ExcelJS Export Not Working in Angular 6 Production Environment, but works fine in development environment.
I am using "exceljs": "^1.13.0" with "file-saver": "^2.0.2". So far I have tried updating:
angular.json scripts with "node_modules/exceljs/dist/exceljs.min.js",
tsconfig.json with "paths": {"exceljs": ["node_modules/exceljs/dist/exceljs.min"].
Additionally, I've tried two different import sets:
import * as Excel from 'exceljs/dist/exceljs.min.js';
import * as FileSaver from 'file-saver';
and
import * as Excel from "exceljs/dist/exceljs.min.js";
import * as ExcelProper from "exceljs";
import * as FileSaver from 'file-saver';
I have also tried adding:
declare const ExcelJS: any;
Here is the excel service.
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');
});
}
//end of class }
My exception is for the spreadsheet to download in the browser upon the completion of the method in my Excel Service in production, which is does in the development environment.
import * as ExcelJS from "exceljs/dist/exceljs.min.js";
Keep this code declare const ExcelJS: any;
as it is
Keep "node_modules/exceljs/dist/exceljs.min.js"
in the script path of angular.json file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With