簡體   English   中英

導出到Excel-Windows Server 2008 IIS7上的問題

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

我正在嘗試導出到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 這是我的代碼

    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仍然可以處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM