string style =
"<style>" +
".title{font-weight:bold;font-size:30px;color:red;text-align:center;}" +
".BH_ListHD{font-family:宋体;font-size:12pt;font-weight:bold;height:30px;}" +
".BH_ListTD{font-family:宋体;font-size:12pt;height:30px;}" +
"</style>" +
"<table><tr><td colspan='13' class='title'>" + excel + "</td></tr></table>";
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.msnumberformat:@";
this.EnableViewState = false;
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(excel + ".xls", System.Text.Encoding.UTF8));
Response.Write("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=gb2312\"/>" + style + HtmlCode);
//Response.Write(style + HtmlCode);
Response.End();
解决方法:
在Write添加<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=gb2312\"/>一起输出

本文介绍了一种在Web应用中导出Excel文件的方法,通过设置HTTP响应头和编码,确保浏览器正确解析并下载Excel文件,同时提供了调整字体样式和表格布局的代码示例。

1342

被折叠的 条评论
为什么被折叠?



