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();
                },

 

posted @ 2022-04-14 18:41  嘻嘻哈哈大只佬  阅读(341)  评论(0编辑  收藏  举报