简体   繁体   English

导出到Excel-Windows Server 2008 IIS7上的问题

[英]Export to excel - Issue on Windows Server 2008 IIS7

I am trying to export to repeter/Gridview in excel, this is working fine in my local machine and windows server 2003, however when I deployed on Windows server 2008 its not working properly . 我正在尝试导出到Excel中的repeter / Gridview, this is working fine in my local machine and windows server 2003, however when I deployed on Windows server 2008 its not working properly here is my code 这是我的代码

    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();

Server Details : Windows Server 2008 and IIS7 服务器详细信息: Windows Server 2008和IIS7

In mozilla all the page contents are exported to excel with an error but in IE & Chrome, empty excel file is exported without data. 在mozilla中,所有页面内容都会错误导出到excel,但在IE&Chrome中,空的excel文件将导出而没有数据。

You are writing a string to the response. 您正在将字符串写入响应。 I would expect this file type to be binary and therefore you should be using Response.BinaryWrite(). 我希望此文件类型是二进制文件,因此您应该使用Response.BinaryWrite()。 What is actually coming from rpt.RenderControl(htw)? rpt.RenderControl(htw)实际上是什么? I suspect, that you should change your content type to text/csv, which excel will still handle. 我怀疑您应该将内容类型更改为text / csv,而excel仍然可以处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM