Export HTML Table to Excel- Doesn t Open in Office 2010

0 votes

Using the following Javascript code, I can instantly create an excel spreadsheet from an HTML table.

Office 2010 cannot open the spreadsheet file; it is blank. When using Openoffice, the identical spreadsheet opens. What might the problem be? Does this have anything to do with 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>

enter image description here

Oct 21, 2022 in Others by Kithuzzz
• 38,000 points
758 views

1 answer to this question.

0 votes

We had the same issue too many complaints from our customers. We traced it to the Excel office Security patch KB3115262 - https://support.microsoft.com/en-us/kb/3115262 Which came out July 12, 2016

We asked clients to modify their Excel files to enable files from the internet in order to get around the problem.

(1) Launch Excel. click on File Options.

2) Select Trust Center Settings under Trust Center.

Three) Select Protected View. Three alternatives are displayed when they were all selected.

The first checkbox, "Enable Protected View for files coming from the Internet," is deactivated.

That resolved the problem. Possibly not the finest choice. I'm not sure why this specific KB ruined it, but I wonder whether it has something to do with the fact that the file format is unexpected and this setting is in a clash with it.

All of those are tested on a computer I own that doesn't have this KB loaded, and it still functions well (it isn't blank, but it does prompt that the file format is different and, I believe, shows in protected view).

The fact that the file operates normally if we resave it in notepad or notepad++ without making any changes is what convinced us that the problem wasn't with the file's content. Therefore, Excel must be reading a file property rather than the file's content to cause the problem.

answered Oct 21, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How to import data from a HTML table on a website to excel?

Hello  To import any HTML file in excel there ...READ MORE

answered Feb 10, 2022 in Others by gaurav
• 23,260 points
7,886 views
0 votes
1 answer

How to open .xlsx files in MS Excel from VS Code?

Hello, to open xlxs files, or files ...READ MORE

answered Feb 17, 2022 in Others by gaurav
• 23,260 points
4,145 views
0 votes
1 answer

How to create a bar graph in Excel 2010 by counts?

Read on usage of pivot charts: Procedure: Pivot Table: Select Data Insert ...READ MORE

answered Oct 21, 2022 in Others by narikkadan
• 63,600 points
767 views
0 votes
1 answer

Display a table (in the html/Excel spreadsheet meaning) in a iOS app in Swift

Here is the answer to your question: ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 63,600 points
634 views
0 votes
1 answer

ExcelJS wrapText in Table columns

I implemented a workaround by detecting what ...READ MORE

answered Sep 30, 2022 in Others by narikkadan
• 63,600 points
3,793 views
0 votes
1 answer

Convert Excel to PDF using JavaScript

You're clobbering objExcel on line 15: var objExcel ...READ MORE

answered Oct 9, 2022 in Others by narikkadan
• 63,600 points
3,847 views
0 votes
1 answer

Convert Excel's "41014" date to actual date in PHP or JavaScript

PHPExcel Date handling code: public static function ExcelToPHP($dateValue ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,600 points
4,405 views
0 votes
1 answer

Excel viewer lib

You will need to save your excel ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 63,600 points
500 views
0 votes
1 answer

Convert table in a jpg image to excel using python

I believe you must execute OCR (optical ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 63,600 points
2,272 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP