开发者

Export to excel - Issue on Windows Server 2008 IIS7

开发者 https://www.devze.com 2023-01-06 09:49 出处:网络
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. here is m

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. 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

In mozilla all the page contents are exported to e开发者_StackOverflow中文版xcel with an error but in IE & Chrome, empty excel file is exported without data.


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(). What is actually coming from rpt.RenderControl(htw)? I suspect, that you should change your content type to text/csv, which excel will still handle.

0

精彩评论

暂无评论...
验证码 换一张
取 消