且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将HTML表导出到Excel-不在Office 2010中打开

更新时间:2022-11-14 10:50:11

我们的客户抱怨太多了。我们将其追溯到Excel OFffice Security修补程序KB3115262 - https://support.microsoft.com/en-us/kb / 3115262 哪些出现在2016年7月12日



为了解决这个问题,我们让客户在Excel中进行更改,以允许来自互联网的文件。



要修复:
1)打开Excel转到文件选项



2)单击信任中心 - >信任中心设置



3)转到受保护的视图。有3个选项显示全部点击



我们取消选中第一个选项 - 启用来自Internet的文件的保护视图



解决了这个问题。也许不是***的解决方案。我不知道为什么这个特定的KB打破了这个,但我想也许这个文件格式是不可预期的,这个设置是相互矛盾的。



在电脑上我没有安装此KB,所有这些都被检查,它仍然正常工作(不是空白但提示文件格式不同),我认为在保护视图中显示。



我们注意到,如果我们以notepad或notepad ++重新保存文件,而不进行任何更改,那么文件的行为是非常好的,所以excel必须读取文件的某些属性,而不是内容阻止它。

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>

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.