Shu*_*ngh 5 javascript exceljs angular
我在 Angular 6 中使用 ExcelJs Lib(1.12.0),但是这个 Lib 在开发中工作正常,但在生产中却不行,它在 workbook.xlsx.writeBuffer() 点失败。
import * as ExcelJS from "exceljs/dist/exceljs.min.js";
downloadExcelFile() {
const title = 'Titlename';
const header = 'headerdata'
const data = 'actualData';
let workbook = new ExcelJS.Workbook();
let worksheet = workbook.addWorksheet(title);
worksheet.addRow(header);
for(let d of data) {
worksheet.addRow(d);
}
workbook.xlsx.writeBuffer().then((data) => {
let blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const anchor = document.createElement('a');
const url = URL.createObjectURL(blob);
anchor.href = url;
anchor.download = title + '.xlsx';
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
URL.revokeObjectURL(url);
}).catch(err => console.log(err))
}
Run Code Online (Sandbox Code Playgroud)
它无法在生产环境中下载文件。
| 归档时间: |
|
| 查看次数: |
3345 次 |
| 最近记录: |