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-05-13 18:21:22 +00:00
|
|
|
var row/*:?string*/ = "", cols = [];
|
2017-04-16 04:32:13 +00:00
|
|
|
o.dense = Array.isArray(sheet);
|
2017-08-05 06:32:57 +00:00
|
|
|
var colInfos = o.skipHidden && sheet["!cols"] || [];
|
|
|
|
var rowInfos = o.skipHidden && sheet["!rows"] || [];
|
|
|
|
for(var C = r.s.c; C <= r.e.c; ++C) if (!((colInfos[C]||{}).hidden)) cols[C] = encode_col(C);
|
2017-04-16 04:32:13 +00:00
|
|
|
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) {
|
|
|
|
++R;
|
2017-08-05 06:32:57 +00:00
|
|
|
if ((rowInfos[R-1]||{}).hidden) continue;
|
|
|
|
row = make_csv_row(sheet, r, R-1, cols, fs, rs, FS, o);
|
2017-05-13 18:21:22 +00:00
|
|
|
if(row != null) {
|
|
|
|
if(o.strip) row = row.replace(endregex,"");
|
|
|
|
stream.push(row + RS);
|
|
|
|
break;
|
|
|
|
}
|
2017-04-09 04:03:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return stream;
|
|
|
|
};
|
|
|
|
|
2017-06-10 01:47:42 +00:00
|
|
|
var write_html_stream = function(ws/*:Worksheet*/, opts/*:?Sheet2HTMLOpts*/) {
|
2017-04-16 07:31:21 +00:00
|
|
|
var stream = Readable();
|
|
|
|
|
2017-06-10 01:47:42 +00:00
|
|
|
var o = opts || {};
|
|
|
|
var header = o.header != null ? o.header : HTML_.BEGIN;
|
|
|
|
var footer = o.footer != null ? o.footer : HTML_.END;
|
|
|
|
stream.push(header);
|
|
|
|
var r = decode_range(ws['!ref']);
|
|
|
|
o.dense = Array.isArray(ws);
|
|
|
|
stream.push(HTML_._preamble(ws, r, o));
|
2017-04-16 07:31:21 +00:00
|
|
|
var R = r.s.r;
|
|
|
|
var end = false;
|
|
|
|
stream._read = function() {
|
|
|
|
if(R > r.e.r) {
|
2017-06-10 01:47:42 +00:00
|
|
|
if(!end) { end = true; stream.push("</table>" + footer); }
|
2017-04-16 07:31:21 +00:00
|
|
|
return stream.push(null);
|
|
|
|
}
|
|
|
|
while(R <= r.e.r) {
|
2017-06-10 01:47:42 +00:00
|
|
|
stream.push(HTML_._row(ws, r, R, o));
|
2017-04-16 07:31:21 +00:00
|
|
|
++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
|
|
|
|
};
|
|
|
|
})();
|
2017-05-11 07:29:59 +00:00
|
|
|
|