同事离职 ,把手头的程序给我了,第二天客户说:“为什么我们导出的excel不会自己汇总啊??”

。。。。您稍等一下,我看一下哈(我怎么知道你们导出的excel为什么不会汇总啊!!)

打开程序

html导出到excel数据格式不正确解决方法

没什么问题,然后导出打开

html导出到excel数据格式不正确解决方法

这是神马?合着你导出来的全部是文本格式的了。文本格式存储的数字怎么汇总你告诉我。

看代码吧

 1 void exportexcel()
 2     {
 3         DataTable dt = getDataTable();
 4         if (dt != null)
 5         {
 6             Response.Clear();
 7             Response.Buffer = true;
 8             Response.Charset = "GB2312";
 9             Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(exceltitle.Value, System.Text.Encoding.UTF8) + ".xls");
10             Response.ContentEncoding = System.Text.Encoding.UTF8; 
11 
12             Response.ContentType = "application/ms-excel";
13             this.EnableViewState = false;
14             System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
15             System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
16 
17             gvExport = new System.Web.UI.WebControls.GridView();
18             gvExport.DataSource = dt.DefaultView;
19             gvExport.AllowPaging = false;
20             gvExport.DataBind();
21             gvExport.Attributes.Add("style", "vnd.ms-excel.numberformat:@");
22             // 返回客户端 
23             gvExport.RenderControl(oHtmlTextWriter);
24             Response.Write(oStringWriter.ToString());
25             Response.End();
26 
27  
28         }
29         close();
30     }
View Code

相关文章:

  • 2022-01-07
  • 2021-08-09
  • 2022-01-05
  • 2022-12-23
  • 2021-12-28
  • 2021-04-25
猜你喜欢
  • 2022-12-23
  • 2021-06-04
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
相关资源
相似解决方案