gpt4 book ai didi

c# - ASP.NET Web 应用程序导出的 excel 文件上的警告弹出窗口

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:48 25 4
gpt4 key购买 nike

我注意到每次打开由我的网络应用程序导出的 excel 文件时,都会弹出此警告消息

filename.xls, is in a different format than specified by the file extension. Verify that the file is not corrupted.....

这里是使用的代码:

            HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Single_Raw.xls"));
HttpContext.Current.Response.ContentType = "application/ms-excel";

using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
Table tb = new Table();
TableRow tr = new TableRow();


tr.Cells.Add((rawRow((lblPOR1.Text.Substring(0, 4)), (lblPOR1.Text.Substring(5, 3)), (lblPOR1.Text.Substring(9, 3)), lblPNL.Text.ToString())));

TableCell cell3 = new TableCell();
cell3.Text = " ";

TableRow tr2 = new TableRow();
tr2.Cells.Add((rawRow((lblPOR2.Text.Substring(0, 4)), (lblPOR2.Text.Substring(5, 3)), (lblPOR2.Text.Substring(9, 3)), lblPNL.Text.ToString())));




tb.Rows.Add(tr);
tb.Rows.Add(tr2);

tb.RenderControl(htw);

HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}

最佳答案

我认为它需要不同的内容类型:

HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

关于c# - ASP.NET Web 应用程序导出的 excel 文件上的警告弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6053042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com