Click here to Skip to main content
14,427,367 members
Rate this:
Please Sign up or sign in to vote.
See more:
I was trying to make some app for excel automation using and c#. When trying to open computer generated xls i got error: "external table is not in the expected format". This can be fixed when open with excel software or fix the file.

Is there anyway to ignore and access the xls file from app without repairing?

What I have tried:

First opening the file using MS Excel and then access from the app.
Updated 13-Jan-20 23:53pm
F-ES Sitecore 14-Jan-20 4:47am
You're probably not creating the xls file properly in the first place. So that's what you want to fix.
cotdarz 14-Jan-20 4:51am
When downloaded, the xls file tends to lose its property as if corrupt xls but ms excel could open easily without losing anything while showing some prompt.
Richard Deeming 15-Jan-20 9:31am
Let me guess: you're generating the Excel file by sending some HTML back to the client with an Excel "content-type" header?

That seems to be a common way to "export to Excel", but it doesn't actually generate an Excel file. It generates an HTML file, which Excel attempts to import.

You need to fix the export code so that it returns a real Excel file instead. Use a tool like EPPlus[^], ClosedXML[^], or The OpenXML SDK[^] to generate the file.
cotdarz 15-Jan-20 21:34pm
Ok, the file is generated by the software made by tcs company. I do not have access to their codes.
Richard Deeming 16-Jan-20 7:34am
Then you'll need to get them to fix their code.

You can check whether this is the problem by opening the file in Notepad. If it looks like HTML, then they've not generated the file properly.
Richard MacCutchan 14-Jan-20 4:52am
Come on, it's always best just to ignore errors. :)
cotdarz 14-Jan-20 5:15am
🤣 yep!

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You'll have to look at how you are generating the XLS file, and at the difference between the "before fix" and "after fix" versions to even begin to work out what your problem is: We have no access to any of that and have no idea of even what version of Excel you are "fixing it" with.

My best guess would be that the XLS file you generate is actually an XLXS file, which is a very different format, and the Excel fix is writing the true XLS format - but without any access to your system or your data a guess is all we can do.
Richard Deeming 15-Jan-20 9:28am
My guess is the file was generated by one of these HTML-with-a-fake-MIME-type-header "export to Excel" scripts that keep popping up. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100