我正在尝试导出到 excel 中的 repeter/Gridview,这在我的本地计算机和 Windows Server 2003 中工作正常,但是当我在 Windows Server 2008 上部署时它无法正常工作
。这是我的代码
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
string attachment = "attachment; filename=myReport.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
rpt.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
服务器详细信息:Windows Server 2008 和 IIS7
在 mozilla 中,所有页面内容都导出到 excel 时出错,但在 IE 和 Chrome 中,导出的是空 excel 文件,没有数据。
最佳答案
您正在向响应写入一个字符串。我希望这种文件类型是二进制的,因此您应该使用 Response.BinaryWrite()。 rpt.RenderControl(htw) 的实际内容是什么?我怀疑您应该将您的内容类型更改为 text/csv,Excel 仍会处理该类型。
关于c# - 导出到 excel - Windows Server 2008 IIS7 上的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3172274/