excel文件未在本地机器的办公室16中打开

时间:2016-08-19 12:01:04

标签: c# excel ms-office

我在c#

中有以下代码的导出文件
string fileName = "Census_Medical_Report_" + DateTime.Now.ToString("yyyyMMddhhmmss");
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName + ".xls"));
            HttpContext.Current.Response.Charset = "";
            HttpContext.Current.Response.ContentType = "application/ms-excel ";

            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            //Build export table header structure
            StringBuilder sb = new StringBuilder();
            sb.Append("<table>");
  sb.Append("<tr><td colspan='14' align='right'>Retrieved on: " + DateTime.Now.ToString() + "</td></tr>");
            sb.Append("<tr><td colspan='14' style='font-size:14pt;color:black;font-weight:bold' align='center'>Medical, Dental, and Vision Census Report</td></tr>");
            sb.Append("<tr><td colspan='14'>&nbsp;</td></td>");
            sb.Append("<tr style='background-color:#393939;color:#ffffff'>");
            sb.Append("<td style='width:100px'>FName</td>");
            sb.Append("<td style='width:100px'>LName</td>");
            sb.Append("<td style='width:75px'>DOB</td>");
            sb.Append("<td style='width:75px'>Gender</td>");
            sb.Append("<td style='width:110px'>City</td>");
            sb.Append("<td style='width:110px'>State</td>");
            sb.Append("<td style='width:75px'>Zip Code</td>");
            sb.Append("<td style='width:100px'>DOH</td>");
            sb.Append("<td style='width:150px'>Occupation</td>");           
            sb.Append("<td style='width:175px'>Medical Coverage Type</td>");
            sb.Append("<td style='width:300px'>Medical Product</td>");
            sb.Append("<td style='width:100px'>Medical Status</td>");
            sb.Append("<td style='width:175px'>Dental Coverage Type</td>");
            sb.Append("<td style='width:300px'>Dental Product</td>");
            sb.Append("<td style='width:100px'>Dental Status</td>");
            sb.Append("<td style='width:175px'>Vision Coverage Type</td>");
            sb.Append("<td style='width:300px'>Vision Product</td>");
            sb.Append("<td style='width:100px'>Vision Status</td>");
            for (int i = 1; i <= getMaxrecdependent; i++)
            {
                sb.Append("<td style='width:100px'>Relation" + i + "</td>");
                sb.Append("<td style='width:100px'>FirstName" +i + "</td>");
                sb.Append("<td style='width:100px'>MiddleName" + i + "</td>");
                sb.Append("<td style='width:100px'>LastName" + i + "</td>");
                sb.Append("<td style='width:100px'>DOB" + i + "</td>");
                sb.Append("<td style='width:100px'>Gender" + i + "</td>");
                sb.Append("<td style='width:100px'>Notes" + i + "</td>");
            }
            sb.Append("</tr>");
    sb.Append("</table>");

            StringReader sr = new StringReader(sb.ToString());
            HttpContext.Current.Response.Output.Write(sb.ToString());
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();

当excel文件下载时,它在属性窗口中显示安全警告消息,我也在excel的信任中心设置,但它在excel 2016中没有打开。 请建议需要做什么。谢谢

0 个答案:

没有答案