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>