ASP.NET导出Excel文档太大

发布网友 发布时间:2024-09-17 06:20

我来回答

1个回答

热心网友 时间:2024-09-29 12:25

我一般都是使用以下的代码
暂时没有发现问题

protected void Button1_Click(object sender, EventArgs e)

{

DataSet da = new DataSet();

string strSql = "select * from uesrs";

da = sqlHelper.ExecuteDataSet(strSql);

string style = @"<style> .text { mso-number-format:\\@; } </script> ";

Response.Clear();

Response.Buffer = true;

Response.Charset = "GB2312"; //请勿删除此行,否则会出现乱码

Response.AppendHeader("Content-Disposition", "attachment; filename =NewFileName.xls");

Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//设置输出流为简体中文

Response.ContentType = "application/ms-excel";

//设置输出文件类型为excel文件

this.EnableViewState = false;

System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);

System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);

System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

this.GridView1.RenderControl(oHtmlTextWriter);

Response.Write(style);

Response.Write(oStringWriter.ToString());

Response.End();

}

public override void VerifyRenderingInServerForm(Control control)

{

//base.VerifyRenderingInServerForm(control);

} /// <summary>

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com