【问题标题】:PDF and Excel generation problems when web application posted in Windows local server在 Windows 本地服务器中发布 Web 应用程序时的 PDF 和 Excel 生成问题
【发布时间】:2014-07-25 23:40:33
【问题描述】:

我在 Windows Server 中发布了我的 Web 应用程序。它具有使用 HTTP 上下文生成 PDF 和 Excel 文档等功能。实际问题是生成的 PDF 文档显示错误为“文件已损坏”,并且 Excel 文档正在与生成 Excel 文档的整个网页一起复制。但是在本地系统中运行我的应用程序时,我没有遇到上述问题。下面是生成Excel的代码。请帮我解决这个问题

HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    HttpContext.Current.Response.Headers.Add("X-Content-Type-Options", "nosniff");
    HttpContext.Current.Response.Charset = " ";
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;            filename=Employee_Detail.xls;");
    HttpContext.Current.Response.Write("<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">");
    HttpContext.Current.Response.Write("<tr><td colspan=3 ><b><font size=6> Employee_Details</font></b></td></tr>");
    HttpContext.Current.Response.Write("</table>");
    HttpContext.Current.Response.Write("<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">");

    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td><b><font size=4> Name </font></b></td>");
    HttpContext.Current.Response.Write("<td><b><font size=4>Employee Id</font></b></td>");
    HttpContext.Current.Response.Write("<td><b><font size=4>Department</font></b></td>");
    HttpContext.Current.Response.Write("</tr>");

    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Ram</td>");
    HttpContext.Current.Response.Write("<td>2200202029393020</td>");
    HttpContext.Current.Response.Write("<td>Accounts</td>");
    HttpContext.Current.Response.Write("</tr>");

    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Jordan</td>");
    HttpContext.Current.Response.Write("<td>2200202029393021</td>");
    HttpContext.Current.Response.Write("<td>Sales</td>");
    HttpContext.Current.Response.Write("</tr>");


    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Shyam</td>");
    HttpContext.Current.Response.Write("<td>2200202029393022</td>");
    HttpContext.Current.Response.Write("<td>Production</td>");
    HttpContext.Current.Response.Write("</tr>");


    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Donald</td>");
    HttpContext.Current.Response.Write("<td>2200202029393023</td>");
    HttpContext.Current.Response.Write("<td>HR</td>");
    HttpContext.Current.Response.Write("</tr>");

    HttpContext.Current.Response.Write("</table>");
    HttpContext.Current.Response.End();
    HttpContext.Current.Response.Flush();

【问题讨论】:

    标签: c# asp.net excel pdf iis


    【解决方案1】:

    可能是您的 MIME 类型在 IIS 中设置不正确?

    看看这里:http://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx

    【讨论】:

    • 我假设是 .xls 而不是 xsl? :)
    • 是的。抱歉输入错误。我的意思是它是 .xls,但我没有在 IIS 中新添加 MIME 类型。它们已经存在于其中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-04
    • 2015-02-20
    • 1970-01-01
    • 2019-04-16
    相关资源
    最近更新 更多