How to export excel with multiple sheets?
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.
Most helpful comment
You can still use FileSaver.
But you have to format
templateto include multiple sheets in the same fileI don't know how you create/get the template but maybe SheetJS is something for you?