{
if (GridView1.Rows.Count == 0)
{
Response.Write("<script>alert('没有查找到数据,无法导出!')</script>");
}
else
{
string strStyle = @"<style> .text { mso-number-format:\@; }</style>";
Export(GridView1, strStyle, "application/ms-excel", "myExcel.xlsx");
}
}
private void Export(GridView gvUser, string Style, string FileType, string FileName)
{
Response.ClearContent();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
//page.Response.ContentType = "application/ms-excel";
Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//turn off paging
gvUser.AllowPaging = false;
BindGrid(gvUser); gvUser.RenderControl(hw);
Response.Write(Style);
Response.Write(sw.ToString());
//page.Response.Flush();
Response.End(); //turn the paging on again
gvUser.AllowPaging = true;
BindGrid(gvUser);
}
private void BindGrid(GridView gvUser)
{
gvUser.DataSource = dtResult;
gvUser.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
这是我的导出代码,最多只能导出65536行数据,现在新版的EXCEL不是可以导出1048576行的吗,请问怎么修改可以让我把超出65536行的数据也导出来
if (GridView1.Rows.Count == 0)
{
Response.Write("<script>alert('没有查找到数据,无法导出!')</script>");
}
else
{
string strStyle = @"<style> .text { mso-number-format:\@; }</style>";
Export(GridView1, strStyle, "application/ms-excel", "myExcel.xlsx");
}
}
private void Export(GridView gvUser, string Style, string FileType, string FileName)
{
Response.ClearContent();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
//page.Response.ContentType = "application/ms-excel";
Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//turn off paging
gvUser.AllowPaging = false;
BindGrid(gvUser); gvUser.RenderControl(hw);
Response.Write(Style);
Response.Write(sw.ToString());
//page.Response.Flush();
Response.End(); //turn the paging on again
gvUser.AllowPaging = true;
BindGrid(gvUser);
}
private void BindGrid(GridView gvUser)
{
gvUser.DataSource = dtResult;
gvUser.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
这是我的导出代码,最多只能导出65536行数据,现在新版的EXCEL不是可以导出1048576行的吗,请问怎么修改可以让我把超出65536行的数据也导出来
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货