【发布时间】:2019-07-11 20:22:02
【问题描述】:
ExcelJS 导出在 Angular 6 生产环境中不工作,但在开发环境中工作正常。
我正在使用“exceljs”:“^1.13.0”和“file-saver”:“^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');
});
}
//课程结束 }
我的例外是电子表格在我的生产环境中的 Excel 服务中完成该方法后在浏览器中下载,这在开发环境中也是如此。
【问题讨论】:
标签: angular6 production-environment filesaver.js exceljs