Filesaver.js: Exporting with Multiple Sheets

Created on 22 May 2017  路  5Comments  路  Source: eligrey/FileSaver.js

How to export excel with multiple sheets?

Make a Blob help wanted

Most helpful comment

You can still use FileSaver.
But you have to format template to include multiple sheets in the same file

I don't know how you create/get the template but maybe SheetJS is something for you?

/* bookType can be any supported output type */
var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };

var wbout = XLSX.write(workbook,wopts);

function s2ab(s) {
  var buf = new ArrayBuffer(s.length);
  var view = new Uint8Array(buf);
  for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  return buf;
}

/* the saveAs call downloads a file on the local machine */
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "test.xlsx");

All 5 comments

Just pass the binary (blob/file) to saveAs
this lib won't help you make a excel file, just help you save the files

Hello, jimmywarting
This is my code and it works fine.

template = ...;
blob = new Blob([template], {
  type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "test.xls");

but I want to make multiple sheets in one file in this case test.xls, how should I deal with it?
As you said do I need to try another way beside filesaver.js?

Thank for pay attention!

You can still use FileSaver.
But you have to format template to include multiple sheets in the same file

I don't know how you create/get the template but maybe SheetJS is something for you?

/* bookType can be any supported output type */
var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };

var wbout = XLSX.write(workbook,wopts);

function s2ab(s) {
  var buf = new ArrayBuffer(s.length);
  var view = new Uint8Array(buf);
  for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  return buf;
}

/* the saveAs call downloads a file on the local machine */
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "test.xlsx");

@HeroSony is this still an issue? As I read it, the 'issue' is not about saving a file usgin FileSaver.js but more a question about an implementation of Excel in javascript. IMHO this issue should be closed...

@eligrey Consider to close this question. It was created May 2017, I pinged July 2017 but with no response. It is a question about implementation, not an bug/issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Toterbiber picture Toterbiber  路  5Comments

ezequiel88 picture ezequiel88  路  4Comments

siva3378 picture siva3378  路  7Comments

rhyous picture rhyous  路  6Comments

sangyeol-kim picture sangyeol-kim  路  5Comments