【发布时间】: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();
【问题讨论】: