Author: MSTechie | Posted on: 1/11/2010 3:49:36 AM | Views : 448

Hi All,
I am working on ASP.Net 2.0
I have the below piece of code using which I am able to successfully export data into an Excel 2003 file (.xls file). Currently my requirement is such that I would need to export data into Excel 2007 file. 
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=Test.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As new System.IO.StringWriter()
Dim htmlWrite As new HtmlTextWriter(stringWrite)
myDataGrid.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Now if I change the filename=Test.xlsx, it gives me an error saying
"Excel cannot open the file 'Test.xlsx' because the file format or
file extension is not valid. Verify that the file has not been
corrupted ...

Go to the complete details ...