1

I have created an Excel workbook using the excel4node library.

var workbook = new excel.Workbook();
var worksheet = workbook.addWorksheet('Sheet 1');
worksheet.cell(1,1).string('Component');
worksheet.cell(1,2).string('Part Name');
worksheet.cell(1,3).string('Value');

I have filled a bunch more cells but I'll keep it short and sweet here as it's not relevant to the question!

I've saved the workbook to my local environment with:

workbook.write(productName + ".xlsx", res);

The name variable is taken from a database. How would I be able to get the user to download this spreadsheet?

If anybody has an idea as to why any help is much appreciated!

Alex Morrison
  • 186
  • 5
  • 18
  • I'd try copying the file with `scp` or a similar tool to your desktop and opening it there. This will tell you whether it's your web server breaking the file or if the file was already corrupted. – mikemaccana Mar 01 '21 at 12:21
  • @mikemaccana I've made an adjustment to my question as I solved my initial issue with the code I've shown above, but this in turn has led to another issue. Any thoughts? – Alex Morrison Mar 01 '21 at 13:16
  • Does this answer your question? [Excel4Node: How to download an excel file without saving?](https://stackoverflow.com/questions/54526641/excel4node-how-to-download-an-excel-file-without-saving) – mikemaccana Mar 01 '21 at 14:57
  • @mikemaccana that's actually the link I've posted below. It solved the problem in getting it download in Firefox, but it still doesn't download in Chrome or Edge – Alex Morrison Mar 01 '21 at 15:10
  • Ah Stack Overflow wrote that, not I. I marked it this question a dupe since you said it answers your question. If you have another question, please don't edit tis one, but instead ask a different question! – mikemaccana Mar 01 '21 at 15:13

1 Answers1

1

I was not familiar with excel4node, but just looked it up. Interesting!

To better answer your question I think it may help to understand what you are trying to achieve. Are you testing the library and just creating a file locally, or trying to serve a workbook from a bucket (S3) or server?

If all is done locally, you say:

I've saved the workbook to my local environment with:

workbook.write(productName + ".xlsx");

Can you open this file with Excel the old fashioned way - clicking on it? If so, excel4node is doing its job and you can investigate the S3 serving process.

OBN
  • 371
  • 2
  • 12
  • 2
    I have managed to find a way to do this. And I must give the credit to Shubh Patel for his answer to this question: https://stackoverflow.com/questions/54526641/excel4node-how-to-download-an-excel-file-without-saving – Alex Morrison Mar 01 '21 at 11:21