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

Exporting to xlsx gives "warning" when opening xlsx file in Excel #294

Closed mikkelschultz closed 4 years ago

mikkelschultz commented 4 years ago

Hi When I use the "default" export buttons, the xlsx files are fine and can be opened in Excel But if I create my own buttons, and use the script below, I get this message when opening the xlsx file in Excel: image

If I click "Yes", the file is fine - but it is a bad experience for the users... Is this a known problem? And can something be done to fix it?

` var tableId = 'export-buttons-table'; var ExportButtons = document.getElementById(tableId);

var instance = new TableExport(ExportButtons, {
    formats: ['xlsx', 'csv'],
        trimWhitespace: true,
    exportButtons: false
});
// **** jQuery **************************
//    $(ExportButtons).tableExport({
//        formats: ['xlsx'],
//        exportButtons: false
//    });
// **************************************

var XLSX = instance.CONSTANTS.FORMAT.XLSX;
var CSV = instance.CONSTANTS.FORMAT.CSV;

//                                          // "id"  // format
var exportDataXLSX = instance.getExportData()[tableId][XLSX];
var exportDataCSV = instance.getExportData()[tableId][CSV];

// get filesize
var bytesXLSX = instance.getFileSize(exportDataXLSX.data, exportDataXLSX.fileExtension);
var bytesCSV = instance.getFileSize(exportDataCSV.data, exportDataCSV.fileExtension);

console.log('filesize (XLSX):', bytesXLSX + 'B');
console.log('filesize (CSV):', bytesCSV + 'B');

var XLSXbutton = document.getElementById('customXLSXButton');
XLSXbutton.addEventListener('click', function (e) {
    //                   // data             // mime                 // name                 // extension
    instance.export2file(exportDataXLSX.data, exportDataXLSX.mimeType, exportDataXLSX.filename, exportDataXLSX.fileExtension);
});

var CSVbutton = document.getElementById('customCSVButton');
CSVbutton.addEventListener('click', function (e) {
    //                   // data             // mime                 // name                 // extension
    instance.export2file(exportDataCSV.data, exportDataCSV.mimeType, exportDataCSV.filename, exportDataCSV.fileExtension);
});

`

hhurz commented 4 years ago

I think you are at the wrong project site... Thats an issue of an other TableExport 😉