代码之家  ›  专栏  ›  技术社区  ›  Muhammad Akhtar

导出到excel-在Windows Server 2008 IIS7上发布

  •  2
  • Muhammad Akhtar  · 技术社区  · 15 年前

    我正在尝试导出到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文件导出时不带数据。

    1 回复  |  直到 15 年前
        1
  •  1
  •   matt-dot-net    15 年前

    您正在向响应写入字符串。我希望这个文件类型是二进制的,因此应该使用Response.BinaryWrite()。从rpt.RenderControl(htw)中到底得到了什么?我怀疑,您应该将内容类型更改为text/csv,excel仍将处理该类型。

    推荐文章