I am using the following Javascript code to generate an excel on the fly, which converts HTML table to a spreadsheet.
The excel file does not open in Office 2010, shows blank. The same spreadsheet opens with Openoffice. What can be the issue? Is this something related to encoding
function ExcelReport() { var tab_text = '<html xmlns:x="urn:schemas-microsoft-com:office:excel">'; tab_text = tab_text + '<head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>'; tab_text = tab_text + '<x:Name>Test Sheet</x:Name>'; tab_text = tab_text + '<x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet>'; tab_text = tab_text + '</x:ExcelWorksheets></x:ExcelWorkbook></xml></head><body>'; tab_text = tab_text + "<table>"; var headingTable = $('#h_tbl').clone(); tab_text = tab_text + headingTable.html(); tab_text = tab_text + '</table>'; $('.c_tbl').each(function( index ) { tab_text = tab_text + "<table>"; tab_text = tab_text + "<tr><td></td></tr><tr><td></td></tr>"; tab_text = tab_text + '</table>'; tab_text = tab_text + "<table>"; var exportTable = $(this).clone(); tab_text = tab_text + exportTable.html(); tab_text = tab_text + '</table>'; }); tab_text = tab_text + '</body></html>'; var fileName = name + '.xls'; var blob = new Blob([tab_text], { type: "application/vnd.ms-excel;charset=utf-8" }) window.saveAs(blob, wo_var + ".xls"); }
When I open the excel in notepad the html code looks like the following
<html xmlns:x="urn:schemas-microsoft-com:office:excel"><head><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table> <tbody><tr><td>abc:</td></tr></tbody></table></body></html>
Here are some of the reasons why Excel files might not open after an upgrade: Microsoft Excel hasn't been correctly installed or upgraded on your laptop/computer. The Excel files might have been corrupted. Microsoft Excel is not able to get access to the default printer setup on the laptop/computer.
We had the same issue too many complaints from our customers. We traced it to the Excel OFffice Security patch KB3115262 - https://support.microsoft.com/en-us/kb/3115262 Which came out July 12, 2016
To work around the issue, we had customers make a change in their Excel to allow files from the internet.
To fix: 1) Open Excel Go to File Options
2) Click Trust Center -> Trust Center Settings
3) Go to Protected View. there are 3 options that show that were all clicked
We uncheck the first option that reads -- "Enable Protected View for files originating from the Internet"
That fixed the issue. Perhaps not the best solution. I'm not sure why this particular KB broke this but I think perhaps the fact the file format is not expected and this setting are conflicting with each other.
On a computer I have that doesn't have this KB installed, all those are checked and it still works fine (not blank but prompts file format is different) and I think shows in protected view.
What led us to fact its not the content of the file is we noticed if we resave the file in notepad or notepad++ without making any changes, the file behaves fine so excel must be reading some property of the file rather than the content to block it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With