C#Excel 2007错误

我有这样一个简单的代码。 此代码只是出口gridwiev excel文件..

Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=cat5.xls"); Response.ContentEncoding = 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(); 

但是我们公司的一些用户使用Excel 2003,一些用户使用Excel 2007。当我运行这个代码时,Excel 2003没有问题。但是在Excel 2007中,像这样的图片存在一些问题。

替代文字替代文字

我怎么解决这个问题? 有没有人有想法?

最好的问候,Soner。

我相信这是由devise(在Excel 2007中):请参阅http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx

可能的解决方法可以是在服务器上生成csv文件(但是会丢失格式)或生成实际的excel文件(使用Excel自动化或第三方工具)。

尝试删除这一行:

Response.ContentEncoding = System.Text.Encoding.GetEncoding(“windows-1254”);

那么单元数据太大将被修复。