0

I am having a Unhandled Rejection when I try to run the function xlsx.writeFile() on my React webapp.

import Excel from 'exceljs';

const workbook = new Excel.Workbook();

const worksheet = workbook.addWorksheet('simpleXlsx');

worksheet.columns = [
  { header: 'Route', key: 'route', width: 10 },
];

worksheet.getColumn(1).values = [1, 2, 3, 4, 5];

async function Test(worksheet: any) {
  await worksheet.xlsx.writeFile('filename');
}

Test(worksheet)

Current versions:

react: 16.7.0
node: 8.17.0
excelJS: 1.15.0
xlsx: 0.15.4

  • You can't write files from a webapp. The browser knows nothing of the filesystem. This would only work on the backend. – Eric Haynes Feb 09 '21 at 20:02
  • That is probably why the older code on this webapp use a library called FileSaver, right? Even tho I can console.log the worksheet... – Mateus FlowinTech Feb 09 '21 at 20:07
  • I'd rather develop this in my backend, but the webAPI runs on .NET Core 2.1 and I can't seem to find any NuGet package that can create a Sheet with Images on this version of .NET – Mateus FlowinTech Feb 09 '21 at 20:12
  • For security reasons, browsers never have access to the filesystem. `FileSaver` looks to be a library which will **open a dialog** asking the user to "Save As". That might be an option for you, but directly writing the file such as above is impossible. – Eric Haynes Feb 09 '21 at 21:01

1 Answers1

0

As @erich2k8 said:

we can't write files from a webapp.

If I managed to do it, with help from some other library, I'll update this post.