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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
XLSX.stream = {
|
|
|
|
to_csv: write_csv_stream
|
|
|
|
};
|
|
|
|
})();
|