Last post May 08, 2019 01:50 AM by Wei Zhang
May 07, 2019 11:53 AM|Gravityloft|LINK
My date in datatable so download the excel my local machie
May 07, 2019 12:24 PM|KathyW|LINK
Your post is not clear. What are you trying to do, and what error are you getting. Showing your code would help people understand what you are trying to do.
May 08, 2019 01:50 AM|Wei Zhang|LINK
According to your description ,I think you want to export datatable to excel sheets,right? I suggest that you could fisrtly download OpenXml SDK and ClosedXml libarary ,then you could use
XLWorkbook to change the data in datatable to memory stream and finally build an Excel file. Here is the demo, I hope it could help you.
<asp:Button Text="Export" OnClick="ExportExcel" runat="server" />
add namespace as below:
protected void ExportExcel(object sender, EventArgs e)
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers"))
using (SqlDataAdapter sda = new SqlDataAdapter())
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
using (XLWorkbook wb = new XLWorkbook())
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
using (MemoryStream MyMemoryStream = new MemoryStream())
Here is the link , I hope it could help you.