I am trying to create an excel file from the response of SSRS reporting server, on front-end I successfully able to download an excel file but when I open it I get the error.
Change the File Extension of Your Excel Sheet: Sometimes, the problem is seen due to the unsupported file extension of your Excel file. To check the support of xlsx extension, go to 'My Computer'. Browse 'Tools Folder Options File Types'. Check if 'xlsx' extension is. Excel cannot open the file claim format.xlsx because the file format or file is not valid. Verify that file has not been corrupted and that the file extension matches the file. I see this most often when a file has been transferred around a lot and gets corrupted due to bad sectors on hard drives, bad thumb drives, etc.
xlsx excel cannot open the file because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
Here is the code:
Any help would be appreciated.
1 Answer
Assuming response
is some kind of HTTP response object that eventually gets sent to the browser, and that you have the actual Excel file contents in fStream
, the problem is you are sending the Base64'd version of the file as the contents (which Excel is not going to understand):
Since I can't see what response
is, all I can say is you need to leave the file contents intact.
If you want to send the raw bytes, you could do:
If your response
can handle a Stream, that would be the ideal way (then you don't have to convert it back and forth between a stream and byte data).
If result.Content
has to be a string, then you have to worry about which encoding to use, and it'll look something like:
It wouldn't surprise me if Excel needs to be encoded as UTF-16 (Microsoft uses it quite heavily internally).
Not the answer you're looking for? Browse other questions tagged c# or ask your own question.
In Excel 2007, I get this error when I try to run a script a friend posted to the web. I have heard of no one else having trouble.
Any ideas what might be going on here?
1 Answer
![File format or file extension not valid File format or file extension not valid](https://i.ytimg.com/vi/OIBYaGeXU_U/hqdefault.jpg)
Check your folder options for the .xlsm extension. That's used by Excel 2007 to indicate a macro-enabled workbook. If you have an earlier version of Office (or none at all), it may not be set. You may need to install the compatibility pack, re-install or repair Office 2007, or change the folder options.