After downloading test.xslx rename it to test.zip (.xslx files are actuall .zip files) You should be able to open it by double clicking. What do you see? There should be a [Content_Types].xml file and some folders (_rels, docProps, xl)
It would be useful to see what happens between the first and second lines of your code. Eg, how do you populate this workbook, do you close it properly, etc.
Is this code on your development machine? Do you realise that Microsoft neither supports nor recommends installing Office on a server and so you are unlikely to be able to publish this web site?
matR
0 Points
2 Posts
Unable to open .xlsx file generated by data export
Jan 10, 2013 02:17 PM|LINK
Hello everyone!
I have problem with my application. This is my code which exports data to file:
Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-Disposition", "attachment;filename=test.xlsx"); Response.Charset = ""; Response.Write(xlWorkBook); Response.End();Columns in xlWorkBook has some assigned values.
But when i try to open this "test.xlsx" file i get an error: "excel can not open the file because the file format or file extension is not valid".
Any ideas what should i change in this code? Any proposals will be highly appreciate.
ignatandrei
All-Star
134983 Points
21638 Posts
Moderator
MVP
Re: Unable to open .xlsx file generated by data export
Jan 10, 2013 03:09 PM|LINK
see the beginning of the excel file or the end - does it contains something unusual?
matR
0 Points
2 Posts
Re: Unable to open .xlsx file generated by data export
Jan 10, 2013 05:07 PM|LINK
No, everything looks fine
Paul Linton
Star
13421 Points
2535 Posts
Re: Unable to open .xlsx file generated by data export
Jan 10, 2013 08:46 PM|LINK
After downloading test.xslx rename it to test.zip (.xslx files are actuall .zip files) You should be able to open it by double clicking. What do you see? There should be a [Content_Types].xml file and some folders (_rels, docProps, xl)
It would be useful to see what happens between the first and second lines of your code. Eg, how do you populate this workbook, do you close it properly, etc.
Is this code on your development machine? Do you realise that Microsoft neither supports nor recommends installing Office on a server and so you are unlikely to be able to publish this web site?
artvindustri...
Member
14 Points
52 Posts
Re: Unable to open .xlsx file generated by data export
Jan 11, 2013 12:17 AM|LINK
try adding "default" at the end of xlWorkBook.
Such as:
Excel.XlFileFormat.xlWorkbookDefault
or
Response.Write(xlWorkBookDefault);
Try opening it after that and see if it takes.
april_123456
Participant
775 Points
246 Posts
Re: Unable to open .xlsx file generated by data export
Jan 11, 2013 02:41 AM|LINK
Hello Mat R,
With regards to your problem, please view the following:
http://stackoverflow.com/questions/9769703/exporting-to-xlsx-using-microsoft-office-interop-excel-saveas-error
Perhaps it will give you some aid.
Best of Luck!
With Kind Regards,