2017-02-10 19:23:01 +00:00
|
|
|
function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
|
2014-05-16 00:33:34 +00:00
|
|
|
var o = opts||{};
|
|
|
|
var z = write_zip(wb, o);
|
2017-02-03 20:50:45 +00:00
|
|
|
var oopts = {};
|
2017-02-10 19:23:01 +00:00
|
|
|
if(o.compression) oopts.compression = 'DEFLATE';
|
2014-05-16 00:33:34 +00:00
|
|
|
switch(o.type) {
|
2017-02-03 20:50:45 +00:00
|
|
|
case "base64": oopts.type = "base64"; break;
|
|
|
|
case "binary": oopts.type = "string"; break;
|
|
|
|
case "buffer":
|
|
|
|
case "file": oopts.type = "nodebuffer"; break;
|
2014-05-16 00:33:34 +00:00
|
|
|
default: throw new Error("Unrecognized type " + o.type);
|
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
if(o.type === "file") return _fs.writeFileSync(o.file, z.generate(oopts));
|
|
|
|
return z.generate(oopts);
|
2014-05-16 00:33:34 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function writeSync(wb/*:Workbook*/, opts/*:?WriteOpts*/) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var o = opts||{};
|
|
|
|
switch(o.bookType) {
|
|
|
|
case 'xml': return write_xlml(wb, o);
|
2017-02-10 19:23:01 +00:00
|
|
|
case 'biff2': return write_biff(wb, o);
|
2015-04-02 20:32:22 +00:00
|
|
|
default: return write_zip_type(wb, o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
function writeFileSync(wb/*:Workbook*/, filename/*:string*/, opts/*:?WriteFileOpts*/) {
|
2014-05-16 00:33:34 +00:00
|
|
|
var o = opts||{}; o.type = 'file';
|
|
|
|
o.file = filename;
|
2017-02-03 20:50:45 +00:00
|
|
|
if(!o.bookType) switch(o.file.substr(-5).toLowerCase()) {
|
2015-04-02 20:32:22 +00:00
|
|
|
case '.xlsx': o.bookType = 'xlsx'; break;
|
2014-05-16 00:33:34 +00:00
|
|
|
case '.xlsm': o.bookType = 'xlsm'; break;
|
|
|
|
case '.xlsb': o.bookType = 'xlsb'; break;
|
2015-04-02 20:32:22 +00:00
|
|
|
default: switch(o.file.substr(-4).toLowerCase()) {
|
2017-02-10 19:23:01 +00:00
|
|
|
case '.xls': o.bookType = 'biff2'; break;
|
2015-04-02 20:32:22 +00:00
|
|
|
case '.xml': o.bookType = 'xml'; break;
|
2017-02-03 20:50:45 +00:00
|
|
|
case '.ods': o.bookType = 'ods'; break;
|
2015-04-02 20:32:22 +00:00
|
|
|
}}
|
2014-05-16 00:33:34 +00:00
|
|
|
return writeSync(wb, o);
|
|
|
|
}
|
|
|
|
|