ExcelJS导出不工作于Range6生产环境,但在开发环境中工作良好。
我使用"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');
});
}//课末}
我的例外是,在生产中完成exception中的方法时,电子表格将在浏览器中下载,这在开发环境中是这样做的。
发布于 2019-08-05 05:36:50
import * as ExcelJS from "exceljs/dist/exceljs.min.js";
declare const ExcelJS: any;的原样"node_modules/exceljs/dist/exceljs.min.js"保存在angular.json文件的脚本路径中发布于 2020-07-14 17:17:02
exceljs@1.13.0 的最新版本(任何版本> 1.10.0)在development配置中工作良好,但在production配置中不工作exceljs@1.10.0将解决这个问题。发布于 2021-05-29 10:15:41
https://stackoverflow.com/questions/56996774
复制相似问题