我正在將一個gridview導出到一個excel文件,並且它打開得很好。唯一的一點是,此警告每一個Excel文件打開時總是彈出:Excel文件是由文件擴展名指定的另一種格式(從gridview導出的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();
}
}
還有像這樣的另一個問題... http://stackoverflow.com/questions/940045/how-to-suppress-the-file-corrupt-warning-at-excel-download – 2GDev 2011-05-25 14:26:25
嗯,它是正確的。該文件格式不同。即使您將Excel工作表保存爲HTML並立即重新打開,也會發生這種情況。我不認爲這是你可以避免的。 :( – Chris 2011-05-25 14:39:19