sheetjs/demos/nwjs
2022-04-14 03:27:38 -04:00
..
index.html
index.js
Makefile version bump 0.18.6 2022-04-14 03:27:38 -04:00
package.json version bump 0.18.6 2022-04-14 03:27:38 -04:00
README.md version bump 0.18.6 2022-04-14 03:27:38 -04:00
xlsx.full.min.js

NW.js

This library is compatible with NW.js and should just work out of the box. The demonstration uses NW.js 0.63.0 with the dist script.

Reading data

The standard HTML5 FileReader techniques from the browser apply to NW.js! This demo includes a drag-and-drop box as well as a file input box, mirroring the SheetJS Data Preview Live Demo.

Writing data

File input elements with the attribute nwsaveas show UI for saving a file. The standard trick is to generate a hidden file input DOM element and "click" it. Since NW.js does not present a writeFileSync in the fs package, a manual step is required:

/* from within the input change callback, `this.value` is the file name */
var filename = this.value, bookType = (filename.match(/[^\.]*$/)||["xlsx"])[0];

/* convert the TABLE element back to a workbook */
var wb = XLSX.utils.table_to_book(HTMLOUT);

/* write to buffer */
var wbout = XLSX.write(wb, {type:'buffer', bookType:bookType});

/* use the async fs.writeFile to save the data */
fs.writeFile(filename, wbout, function(err) {
	if(!err) return alert("Saved to " + filename);
	alert("Error: " + (err.message || err));
});

Analytics