1. 程式人生 > 其它 >elementui表格匯出為excel

elementui表格匯出為excel

//匯出填報清單
                exportList() {
                    //將表格合計行rowspan改為1
                    $($("#daochu").find("table")[2]).find("tbody").find('tr').find('td').attr({'rowspan': 1});

                    var tableHeader = $($("#daochu").find("table")[0])
                        .find("thead")
                        .html();
                    
var tableBody = $($("#daochu").find("table")[1]) .find("tbody") .html(); var tableFoot = $($("#daochu").find("table")[2]) .find("tbody") .html(); var html = '<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"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>Sheet1</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>' + "<table><tbody>" + tableHeader
+ tableBody + tableFoot + "</tbody></table>" + "</body></html>"; var blob = new Blob(["\uFEFF" + html], { type: "text/csv;charset=utf-8", });
var a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = "資金落實情況.xls"; document.body.appendChild(a); a.onclick = function () { document.body.removeChild(a); }; a.click(); },