datagrid导出EXECL表,如何解决分页都同时导在同一张EXECL那里啊??
如题,我想用EXECL表导出DataGrid里面的数据,但是因为数据太多需要分页,但是我希望导出EXECL表时能够全部导为一张EXECL表??请大家帮忙一下
[解决办法]
前提是用了gridview或DataGrid自带的分页:
public void ExportToExcel(string Filename, DataGrid gridview, Page page) { gridview.EnableViewState = false; gridview.AllowSorting = false; gridview.AllowPaging = false; gridview.HeaderStyle.ForeColor = System.Drawing.Color.Black; DataTable temp = (DataTable)ViewState["view"];//把你前边绑定数据的DataTable暂存ViewState. gridview.DataSource = temp; gridview.DataBind(); page.Response.Clear(); // 防止中文内容为乱码 page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); //可令中文文件名不为乱码 page.Response.AppendHeader("content-disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(Filename + DateTime.Now.ToShortDateString(), System.Text.Encoding.UTF8) + ".xls\""); System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gridview.RenderControl(htw); page.Response.Write(sw.ToString()); page.Response.End(); }