asp.net 将动态生成的 table 导出到excel

//Response.Clear();
//Response.Buffer = true;
//Response.Charset = "GB2312";
//Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + "" + System.DateTime.Today.ToShortDateString() + ".xls");
//Response.ContentEncoding = System.Text.Encoding.UTF7;
//Response.ContentType = "application/vnd.ms-excel";
//this.EnableViewState = false;

//System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
//System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
//this.divResport.RenderControl(oHtmlTextWriter);
//Response.Output.Write(oStringWriter.ToString());

//Response.Flush();
//Response.End();
我的页面是动态生成的table格式,用2003导出来可以查看,但是2010版本就不能了,都是乱码,请问有什么可以解决的办法吗,没有分不好意思啊

改变下编码试试
Response.ContentEncoding = System.Text.Encoding.UTF8;

UTF-7:A Mail-Safe Transformation Format of Unicode(RFC1642)。这是一种使用 7 位 ASCII 码对 Unicode 码进行转换的编码。它的设计目的仍然是为了在只能传递 7 为编码的邮件网关中传递信息。 UTF-7 对英语字母、数字和常见符号直接显示,而对其他符号用修正的 Base64 编码。符号 + 和 - 号控制编码过程的开始和暂停。所以乱码中如果夹有英文单词,并且相伴有 + 号和 - 号,这就有可能是 UTF-7 编码。
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-11-08
导出excel 可以参考目前最常使用的 npoi导出excel 组件

这个组件不会依赖excel,不会像html那样提示格式问题

导出数据可以很好的支持excel各种版本。

百度一下 找博客园的技术文章看看就会了,很简单.
相似回答