在Windows本地服务器上发布web应用程序时,PDF和Excel生成问题

本文关键字:PDF Excel 成问题 应用程序 web Windows 服务器 | 更新日期: 2023-09-27 18:06:43

我在windows服务器上发布了我的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();

在Windows本地服务器上发布web应用程序时,PDF和Excel生成问题

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

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