做个笔记,后续自己可以看看,将页面的一个Table直接输出为excel文件,亲测有用。
//下载excel function downloadExcel() { var uri = 'data:application/vnd.ms-excel;base64,'; var template = `<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"> <meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"> <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>`+ $('#idData').html() + `</table></body></html>`; window.location.href = uri + window.btoa(unescape(encodeURIComponent(template))); };
标签:excel,JS,window,template,var,页面 From: https://www.cnblogs.com/wonder223/p/17586840.html