Excel文件的格式由文件扩展名指定(Excel从gridview导出)
|
我正在将gridview导出到一个excel文件,它可以很好地打开。唯一的事情是,每次打开excel文件时,此警告总是弹出:
The file you are trying to open < > is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
我正在使用的代码:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader(\"content-disposition\", string.Format(\"attachment; filename={0}\", \"Single_Raw.xls\"));
HttpContext.Current.Response.ContentType = \"application/vnd.ms-excel\";
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// some code
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}
没有找到相关结果
已邀请:
1 个回复
枫湃揩乾纲