0

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.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();

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.

alt text alt text

How can i solve this problem? Is there anybody have an idea?

Best Regards, Soner.

2
  • Does this happen for all gridsizes? I had problems exporting to Excel from some library that got "solved" by appending some empty rows to get the filesize above (I think) 7k. Commented Dec 22, 2010 at 9:04
  • I don't calculate any filesize of gridsize or what? Just writing this code and run it. MY question is what is the different excel 2003 and excel 2007.. Commented Dec 22, 2010 at 9:26

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

1 Comment

I too have encountered this before and I specified a .xlsx extension and all was well. Fortunately I could rely on the fact we were all using Office 2007, but that's a bit more tricky here.
0

try to remove this line:

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

Then Cell data too large will be fixed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.