5

I am using ExcelJs Lib(1.12.0) inside angular 6 but this Lib is wokring fine in dev but not in production its failing at point 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))
}

Its not able to download the file in production env.

Shubham Singh
  • 147
  • 1
  • 2
  • 15
  • That's a... pretty old version for ExcelJS. Is it possible to upgrade to v2.0.1+? If not, then try downgrading to 1.10.0. – double-beep Jan 09 '22 at 12:16
  • Is there any output on your dev console? Have you checked for CSP errors? Something like https://stackoverflow.com/questions/28467789/content-security-policy-object-src-blob could cause things you are whatching. CSP is sometimes different between stages/dev. – stefan.seeland Jan 09 '22 at 14:17

0 Answers0