每當我打開我我的ASP.NET頁面上生成與Excel 2007中xls文件,我得到以下錯誤:如何在ASP.NET中生成Excel 2007文件而不會收到警告消息?
The file you are trying to open, 'filename.xls', 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?
如果我點擊「是」,一切都看起來不錯,但它很煩人我們的客戶每次都必須點擊。如果他們使用2003年,沒有問題,但在2007年,它給出了這個錯誤。這裏是我使用的代碼:
string style = @"<style> .text { mso-number-format: \@ } </style> ";
Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment;filename=OperationsReport_Rejects_{0}.xls", DateTime.Today.ToString("yyyyMMdd")));
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
reportOperationsRejectsGridView.RenderControl(htmlWrite);
Response.Write(style);
Response.Write(stringWrite.ToString());
Response.End();
有誰知道是什麼原因造成它在2003和2007的行爲不同?
2007版本將具有的.xlsx擴展 – 2009-11-20 19:54:07
@DJ:不一定。你可以給它任何你想要的擴展;嘿,做一個另存爲並保存爲一個Excel 2007文件,但給它一個.JPG擴展名,並保存爲JPEG格式。格式方面仍然存在基本差異;我始終以任一種格式獲取文件。正如我所說,查看十六進制查看器或編輯器中的文件。 – 2009-11-20 20:23:38