<table id="table" border="1"><tr style="height:50px;"><th style="width:100px;color:red;">姓名</th><th>性别</th><th>年龄</th></tr></table><a id="down">点击下载excel</a><script>let html = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"></head><body>${ElementById('table').outerHTML}</body></html>`let blob = new Blob([html],{ type: 'application/vnd.ms-excel'});let a = ElementById('down');a.href = ateObjectURL(blob);a.download = '测试excel下载'</script>原文链接:
downloadFile(){const xlsx = require('xlsx');let arrayData = [['name', 'age'],['zhangsan', 20]];let jsonData = [{name: "zhangsan1",age: 30},{name: "zhangsan1",age: 24}];// 将数据转成workSheetlet arrayWorkSheet = xlsx.utils.aoa_to_sheet(arrayData);let jsonWorkSheet = xlsx.utils.json_to_sheet(jsonData);// 构造workBooklet workBook = {SheetNames: ['arrayWorkSheet', 'jsonWorkSheet'],Sheets: {'arrayWorkSheet': arrayWorkSheet,'jsonWorkSheet': jsonWorkSheet,}};// 将workBook写入文件xlsx.writeFile(workBook, "./aa.xlsx");
}
本文发布于:2024-01-29 15:35:33,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170651373716288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |