C# Excel 2007 Error
I have a simple code like this. This code simply exporting gridwiev to excel file..
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=cat5.xls");
Response.Con开发者_JAVA技巧tentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
//Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.Charset = "windows-1254";
//Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.ContentType = "application/vnd.ms-excel";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
But our company some users usign Excel 2003, some user using Excel 2007. When i run this code, there is no problem Excel 2003. But there is some problem in Excel 2007 like this pictures.
How can i solve this problem? Is there anybody have an idea?
Best Regards, Soner.
I believe that this is by design (in Excel 2007): see http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx
Possible work-around can be generating either csv file on server (but you will loose formatting) or generating actual excel file (using excel automation or 3rd party tool).
try to remove this line:
Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
Then Cell data too large will be fixed.
精彩评论