hhurz / tableExport.jquery.plugin

jQuery plugin to export a html table to JSON, XML, CSV, TSV, TXT, SQL, Word, Excel, PNG and PDF
MIT License
984 stars 714 forks source link

<meta> not in <head> in MS-Excel exported file #367

Closed TomKrakott closed 1 year ago

TomKrakott commented 1 year ago

Hi,

When trying to import export files in xls format, I regularly get errors from PhP DOMDocument::loadHTML. It seems that this comes from a bad recognition of the which is not in the desired place. This should be included in the section.

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">
<head>
<!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>Table</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
...

I just reversed line 917/918 in tableExport.js and everything work fine :

917      docFile += '<head>';
918      docFile += '<meta http-equiv="content-type" content="application/vnd.ms-' + MSDocType + '; charset=UTF-8">';

Thanks for your work :)

hhurz commented 1 year ago

Thanks for pointing this out. I have changed the code accordingly and the change will be released in the next version.