2017-04-09 04:03:19 +00:00
|
|
|
if(has_buf && typeof require != 'undefined') (function() {
|
|
|
|
var Readable = require('stream').Readable;
|
|
|
|
|
|
|
|
var write_csv_stream = function(sheet/*:Worksheet*/, opts/*:?Sheet2CSVOpts*/) {
|
|
|
|
var stream = Readable();
|
2017-04-16 04:32:13 +00:00
|
|
|
var out = "";
|
2017-04-09 04:03:19 +00:00
|
|
|
var o = opts == null ? {} : opts;
|
|
|
|
if(sheet == null || sheet["!ref"] == null) { stream.push(null); return stream; }
|
|
|
|
var r = safe_decode_range(sheet["!ref"]);
|
|
|
|
var FS = o.FS !== undefined ? o.FS : ",", fs = FS.charCodeAt(0);
|
|
|
|
var RS = o.RS !== undefined ? o.RS : "\n", rs = RS.charCodeAt(0);
|
|
|
|
var endregex = new RegExp((FS=="|" ? "\\|" : FS)+"+$");
|
2017-04-16 04:32:13 +00:00
|
|
|
var row = "", cols = [];
|
|
|
|
o.dense = Array.isArray(sheet);
|
|
|
|
for(var C = r.s.c; C <= r.e.c; ++C) cols[C] = encode_col(C);
|
|
|
|
var R = r.s.r;
|
2017-04-09 04:03:19 +00:00
|
|
|
stream._read = function() {
|
|
|
|
if(R > r.e.r) return stream.push(null);
|
2017-04-16 04:32:13 +00:00
|
|
|
while(R <= r.e.r) {
|
|
|
|
row = make_csv_row(sheet, r, R, cols, fs, rs, FS, o);
|
|
|
|
if(row == null) { ++R; continue; }
|
|
|
|
if(o.strip) row = row.replace(endregex,"");
|
|
|
|
stream.push(row + RS);
|
|
|
|
++R;
|
|
|
|
break;
|
2017-04-09 04:03:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return stream;
|
|
|
|
};
|
|
|
|
|
2017-04-16 07:31:21 +00:00
|
|
|
var HTML_BEGIN = "<html><body><table>";
|
|
|
|
var HTML_END = "</table></body></html>";
|
|
|
|
|
|
|
|
var write_html_stream = function(sheet/*:Worksheet*/, opts) {
|
|
|
|
var stream = Readable();
|
|
|
|
|
|
|
|
var o/*:Array<string>*/ = [];
|
|
|
|
var r = decode_range(sheet['!ref']), cell/*:Cell*/;
|
|
|
|
o.dense = Array.isArray(sheet);
|
|
|
|
stream.push(HTML_BEGIN);
|
|
|
|
|
|
|
|
var R = r.s.r;
|
|
|
|
var end = false;
|
|
|
|
stream._read = function() {
|
|
|
|
if(R > r.e.r) {
|
|
|
|
if(!end) { end = true; stream.push(HTML_END); }
|
|
|
|
return stream.push(null);
|
|
|
|
}
|
|
|
|
while(R <= r.e.r) {
|
|
|
|
stream.push(HTML_._row(sheet, r, R, o));
|
|
|
|
++R;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return stream;
|
|
|
|
};
|
2017-04-09 04:03:19 +00:00
|
|
|
|
|
|
|
XLSX.stream = {
|
2017-04-16 07:31:21 +00:00
|
|
|
to_html: write_html_stream,
|
2017-04-09 04:03:19 +00:00
|
|
|
to_csv: write_csv_stream
|
|
|
|
};
|
|
|
|
})();
|