sheetjs/docbits/30_export.md
SheetJS 00f25cfe1e version bump 0.10.7: autocorrections for bad files
- recalculate SSF for malformed files (fixes #506 h/t @asksahil)
- malformed shared string (fixes #445 h/t @Ramzec)
- SSF added to TS def (fixes #711 h/t @duckywang1)
- Norsk property names
- resolved gitbook processing issues
2017-07-05 18:27:54 -04:00

1.4 KiB

Writing Workbooks

For writing, the first step is to generate output data. The helper functions write and writeFile will produce the data in various formats suitable for dissemination. The second step is to actual share the data with the end point. Assuming workbook is a workbook object:

nodejs write a file (click to show)
/* output format determined by filename */
XLSX.writeFile(workbook, 'out.xlsx');
/* at this point, out.xlsx is a file that you can distribute */
Browser download file (click to show)

Note: browser generates binary blob and forces a "download" to client. This example uses FileSaver.js:

/* 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");

Writing Examples