2015-04-02 20:32:22 +00:00
|
|
|
function write_zip_type(wb, opts) {
|
2014-05-16 00:33:34 +00:00
|
|
|
var o = opts||{};
|
2015-03-03 19:27:28 +00:00
|
|
|
style_builder = new StyleBuilder(opts);
|
2015-03-01 05:39:47 +00:00
|
|
|
|
|
|
|
var z = write_zip(wb, o);
|
2014-05-16 00:33:34 +00:00
|
|
|
switch(o.type) {
|
|
|
|
case "base64": return z.generate({type:"base64"});
|
|
|
|
case "binary": return z.generate({type:"string"});
|
|
|
|
case "buffer": return z.generate({type:"nodebuffer"});
|
|
|
|
case "file": return _fs.writeFileSync(o.file, z.generate({type:"nodebuffer"}));
|
|
|
|
default: throw new Error("Unrecognized type " + o.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 20:32:22 +00:00
|
|
|
function writeSync(wb, opts) {
|
|
|
|
var o = opts||{};
|
|
|
|
switch(o.bookType) {
|
|
|
|
case 'xml': return write_xlml(wb, o);
|
|
|
|
default: return write_zip_type(wb, o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
function writeFileSync(wb, filename, opts) {
|
|
|
|
var o = opts||{}; o.type = 'file';
|
2015-02-28 06:42:41 +00:00
|
|
|
|
2014-05-16 00:33:34 +00:00
|
|
|
o.file = filename;
|
|
|
|
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()) {
|
|
|
|
case '.xls': o.bookType = 'xls'; break;
|
|
|
|
case '.xml': o.bookType = 'xml'; break;
|
|
|
|
}}
|
2014-05-16 00:33:34 +00:00
|
|
|
return writeSync(wb, o);
|
|
|
|
}
|
|
|
|
|