ExcelJS 导出在 Angular 6 生产环境中不起作用,但在开发环境中运行良好。
我正在使用“exceljs”:“^1.13.0”和“文件保护程序”:“^2.0.2”。到目前为止,我已经尝试更新:
angular.json scripts with "node_modules/exceljs/dist/exceljs.min.js",
tsconfig.json with "paths": {"exceljs": ["node_modules/exceljs/dist/exceljs.min"].
此外,我尝试了两种不同的导入集:
import * as Excel from 'exceljs/dist/exceljs.min.js';
import * as FileSaver from 'file-saver';
和
import * as Excel from "exceljs/dist/exceljs.min.js";
import * as ExcelProper from "exceljs";
import * as FileSaver from 'file-saver';
我也尝试添加:
declare const ExcelJS: any;
这里是excel服务。
import { Injectable } from '@angular/core';
import * as Excel from "exceljs/dist/exceljs.min.js";
import * as ExcelProper from "exceljs";
import * as FileSaver from 'file-saver';
const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
const EXCEL_EXTENSION = '.xlsx';
// declare const ExcelJS: any;
@Injectable({
providedIn: 'root'
})
export class ExcelService {
workbook: Excel.Workbook;
worksheet: any;
constructor() { }
generateExcel() {
// Create workbook and worksheet
this.workbook = new Excel.Workbook();
// Add a Worksheet
this.worksheet = this.workbook.addWorksheet('File');
//Add Test to cell A1
this.worksheet.getCell('A1').value = 'TEST';
// Generate Excel File
this.workbook.xlsx.writeBuffer().then((data) => {
console.log('buffer data', data);
const blob = new Blob([data], {type: EXCEL_TYPE});
console.log('blob', blob);
FileSaver.saveAs(blob, 'quote.xlsx');
});
}
//类(class)结束
}
我的异常(exception)是电子表格在我的 Excel 服务中的方法完成后在浏览器中下载,这是在开发环境中完成的。
最佳答案
import * as ExcelJS from "exceljs/dist/exceljs.min.js";
declare const ExcelJS: any;
照原样"node_modules/exceljs/dist/exceljs.min.js"
在 angular.json 文件的脚本路径中 关于angular6 - ExcelJS 在 Angular 6 中无法用于生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56996774/