Export the HTML table to excel is not working in IE

后端 未结 4 1138
迷失自我
迷失自我 2020-11-30 13:18

Exporting HTML table to Excel is working fine in Chrome and Firefox but it is not working in Internet Explorer 10.

var tableToExcel = (function() {
  var uri         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 13:42

    Found a community version of SheetJS that works like a cham!

    No warning like "The file format and extension of 'file.xls' don't match. This file could be corrupted or unsafe."

    Import the library

        
    

    Paste the function that calls the library

    function doit(type, fn, dl) {
            var elt = document.getElementById('data-table');
            var wb = XLSX.utils.table_to_book(elt, { sheet: "Sheet JS" });
            return dl ?
                XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
                XLSX.writeFile(wb, fn || ('test.' + (type || 'xlsx')));
        }
    

    Trigger the function using a button or anything that suit your needs.

    
    

    Sample code can be found in this page

提交回复
热议问题