<! DOCTYPE html> <html> <head> <title></title> </head> <body> <div class="container"> <table id="backViewTable" Class = "table table - hover table - sm table2excel" > < tr > < td > # < / td > < td > ID < / td > < td > name < / td > < td > seat number < / td > < td > action < / td > < / tr > <tr> <th scope="row">1</th> < TD >< TD >< TD >< TD >< INPUT class=" bTN-primary "type="button" Value = "delete" / > < / td > < / tr > < tr > < th scope = "row" > 2 < / th > 2345 < / td > < td > < td > LWF < / td > < td > 1/3 row number 34 < / td > < td > < input Class = "BTN - primary" type = "button" value = "delete" / > < / td > < / tr > < tr > < th scope = "row" > 3 < / th > 3456 < / td > < td > < td > Lee < / td > < td > 1 floor </td> <td><input class="btn-primary" type="button" value=" "/></ TD ></ tr> </table> <button class=" BTN btn-primary" btn-sm" onclick="tablesToExcel(['backViewTable'], ['ProductDay1'], 'TestBook.xls', 'Excel')">Export to Excel</button> </div> <script> var tablesToExcel = (function() { var uri = 'data:application/vnd.ms-excel; base64,' , tmplWorkbookXML = '<? The XML version = "1.0"? > <? mso-application progid="Excel.Sheet"? ><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">' + '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>Axel Richter</Author><Created>{created}</Created></DocumentProperties>' + '<Styles>' + '<Style ss:ID="Currency"><NumberFormat ss:Format="Currency"></NumberFormat></Style>' + '<Style ss:ID="Date"><NumberFormat ss:Format="Medium Date"></NumberFormat></Style>' + '</Styles>' + '{worksheets}</Workbook>' , tmplWorksheetXML = '<Worksheet ss:Name="{nameWS}"><Table>{rows}</Table></Worksheet>' , tmplCellXML = '<Cell{attributeStyleID}{attributeFormula}><Data ss:Type="{nameType}">{data}</Data></Cell>' , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) } , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) } return function(tables, wsnames, wbname, appname) { var ctx = ""; var workbookXML = ""; var worksheetsXML = ""; var rowsXML = ""; for (var i = 0; i < tables.length; i++) { if (! tables[i].nodeType) tables[i] = document.getElementById(tables[i]); For (var j = 0; j < tables[i].rows.length; j++) { rowsXML += '<Row>'; For (var k = 0; var k = 0; k < tables[i].rows[j].cells.length-1; k++) { var dataType = tables[i].rows[j].cells[k].getAttribute("data-type"); var dataStyle = tables[i].rows[j].cells[k].getAttribute("data-style"); var dataValue = tables[i].rows[j].cells[k].getAttribute("data-value"); dataValue = (dataValue)? dataValue:tables[i].rows[j].cells[k].innerHTML; var dataFormula = tables[i].rows[j].cells[k].getAttribute("data-formula"); dataFormula = (dataFormula)? dataFormula:(appname=='Calc' && dataType=='DateTime')? dataValue:null; ctx = { attributeStyleID: (dataStyle=='Currency' || dataStyle=='Date')? ' ss:StyleID="'+dataStyle+'"':'' , nameType: (dataType=='Number' || dataType=='DateTime' || dataType=='Boolean' || dataType=='Error')? dataType:'String' , data: (dataFormula)? '':dataValue , attributeFormula: (dataFormula)? ' ss:Formula="'+dataFormula+'"':'' }; rowsXML += format(tmplCellXML, ctx); } rowsXML += '</Row>' } ctx = {rows: rowsXML, nameWS: wsnames[i] || 'Sheet' + i}; worksheetsXML += format(tmplWorksheetXML, ctx); rowsXML = ""; } ctx = {created: (new Date()).getTime(), worksheets: worksheetsXML}; workbookXML = format(tmplWorkbookXML, ctx); Console. log(workbookXML); var link = document.createElement("A"); link.href = uri + base64(workbookXML); link.download = wbname || 'Workbook.xls'; link.target = '_blank'; document.body.appendChild(link); link.click(); document.body.removeChild(link); }}) (); </script> </body> </html>Copy the code