New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
callback for writeFile? #396
Comments
+1 |
Is there any progress on this issue? @barbalex @lucdetellis were you guys able use callback? please help if you have any information. |
@barbalex @lucdetellis @MrWhite1 you can just wrap
So it should be straightforward to write something similar: (warning: untested) function writeFileAsync(wb, filename, opts, cb) {
// set up bookType and type options
var o = opts||{}; o.type = 'buffer';
if(!o.bookType) switch(filename.substr(-5).toLowerCase()) {
case '.xlsx': o.bookType = 'xlsx'; break;
case '.xlsm': o.bookType = 'xlsm'; break;
case '.xlsb': o.bookType = 'xlsb'; break;
default: switch(filename.substr(-4).toLowerCase()) {
case '.xls': o.bookType = 'biff2'; break;
case '.ods': o.bookType = 'ods'; break;
}}
// generate output data
var out;
try {
out = XLSX.write(wb, o);
} catch(e) {
// call the callback if there's an error
return cb(e, null);
}
// success! now just write the file asynchronously
fs.writeFile(filename, out, cb);
} |
- `aoa_to_sheet` function (fixes SheetJS#314 h/t @fonzy2013 @rvdwijngaard) - `writeFileAsync` function (fixes SheetJS#396 h/t @barbalex) - `sheet_to_json` tests + docs + blankrows (fixes SheetJS#602 h/t @EEaglehouse) - write number format scan now includes every index >= 50 - propagate SSF IE8 fixes (fixes protobi#171 h/t @SheetJSDev) - update shim for extendscript (see SheetJS#603 h/t @firas3d) - more flow type definitions
First of all: thanks for this great tool!
XLSX.writeFile
can take quite some time to finish. And of course an error could occur.In either case the user should be informed about the outcome. Or maybe the created file should then be opened.
I must be missing something extremely obvious, but I can't find a way to pass a callback and receive error and result.
I have tried adding a callback as fourth parameter. But it seems like this is ignored.
(How) can this be done?
The text was updated successfully, but these errors were encountered: