0

I am a little new to javascript. I have got one javascript function which is generating xlsx file from HTML table. It's working fine but as soon as the file gets generated, it's downloading the file instead I am looking to save it on my server. The function is like below

function ExportToExcel(type, fn, dl) {
       var elt = document.getElementById('tour');
       var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
       return dl ?
         XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }):
         XLSX.writeFile(wb, fn || ('MySheetName.' + (type || 'xlsx')));
}

and I am calling it like below:

onclick="ExportToExcel('xlsx')"

How to store the file instead of downloading it?

Gopal Mishra
  • 1,575
  • 1
  • 14
  • 17
Nidhi
  • 95
  • 9
  • 1
    *"save it in my server"* what server? javascript/jquery runs on the client. You need to upload/POST the document to your server (or just generate it there rather than on the client) – freedomn-m Sep 30 '21 at 10:32
  • Why don't you use a similar kind of library on your backend? Just get the data from the front end? Something like `msexcel-builder`? – Gopal Mishra Sep 30 '21 at 10:33

1 Answers1

0

Not understanding why you want to generate XLSX on the Client and save it to the server later on. I suggest you generate it on the server itself.

Take a look at answers to this question if you want to save/generate an XLSX file in Node.JS.

Gopal Mishra
  • 1,575
  • 1
  • 14
  • 17