version bump 0.9.11: streaming HTML write
This commit is contained in:
parent
1d61054602
commit
f51feb375a
12
README.md
12
README.md
|
@ -410,10 +410,14 @@ saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "test.xlsx");
|
|||
|
||||
### Streaming Write
|
||||
|
||||
`XLSX.stream.to_csv` is the streaming version of `XLSX.utils.sheet_to_csv`. It
|
||||
takes the same arguments but returns a readable stream.
|
||||
The streaming write functions are available in the `XLSX.stream` object. They
|
||||
take the same arguments as the normal write functions but return a readable
|
||||
stream. They are only exposed in node.
|
||||
|
||||
<https://github.com/sheetjs/sheetaki> pipes CSV write stream to nodejs response.
|
||||
- `XLSX.stream.to_csv` is the streaming version of `XLSX.utils.sheet_to_csv`.
|
||||
- `XLSX.stream.to_html` is the streaming version of the HTML output type.
|
||||
|
||||
<https://github.com/sheetjs/sheetaki> pipes write streams to nodejs response.
|
||||
## Interface
|
||||
|
||||
`XLSX` is the exposed variable in the browser and the exported node variable
|
||||
|
@ -439,6 +443,8 @@ Parse options are described in the [Parsing Options](#parsing-options) section.
|
|||
`XLSX.writeFileAsync(filename, wb, o, cb)` attempts to write `wb` to `filename`.
|
||||
If `o` is omitted, the writer will use the third argument as the callback.
|
||||
|
||||
`XLSX.stream` contains a set of streaming write functions.
|
||||
|
||||
Write options are described in the [Writing Options](#writing-options) section.
|
||||
|
||||
### Utilities
|
||||
|
|
|
@ -1 +1 @@
|
|||
XLSX.version = '0.9.10';
|
||||
XLSX.version = '0.9.11';
|
||||
|
|
|
@ -51,40 +51,42 @@ var HTML_ = (function() {
|
|||
function html_to_book(str/*:string*/, opts)/*:Workbook*/ {
|
||||
return sheet_to_workbook(html_to_sheet(str, opts), opts);
|
||||
}
|
||||
function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o)/*:string*/ {
|
||||
var M = (ws['!merges'] ||[]);
|
||||
var oo = [];
|
||||
for(var C = r.s.c; C <= r.e.c; ++C) {
|
||||
var RS = 0, CS = 0;
|
||||
for(var j = 0; j < M.length; ++j) {
|
||||
if(M[j].s.r > R || M[j].s.c > C) continue;
|
||||
if(M[j].e.r < R || M[j].e.c < C) continue;
|
||||
if(M[j].s.r < R || M[j].s.c < C) { RS = -1; break; }
|
||||
RS = M[j].e.r - M[j].s.r + 1; CS = M[j].e.c - M[j].s.c + 1; break;
|
||||
}
|
||||
if(RS < 0) continue;
|
||||
var coord = encode_cell({r:R,c:C});
|
||||
var cell = o.dense ? (ws[R]||[])[C] : ws[coord];
|
||||
if(!cell || cell.v == null) { oo.push("<td></td>"); continue; }
|
||||
/* TODO: html entities */
|
||||
var w = cell.h || escapexml(cell.w || (format_cell(cell), cell.w) || "");
|
||||
var sp = {};
|
||||
if(RS > 1) sp.rowspan = RS;
|
||||
if(CS > 1) sp.colspan = CS;
|
||||
oo.push(writextag('td', w, sp));
|
||||
}
|
||||
return "<tr>" + oo.join("") + "</tr>";
|
||||
}
|
||||
function sheet_to_html(ws/*:Worksheet*/, opts)/*:string*/ {
|
||||
var o/*:Array<string>*/ = [];
|
||||
var r = decode_range(ws['!ref']), cell/*:Cell*/;
|
||||
var dense = Array.isArray(ws);
|
||||
var M = (ws['!merges'] ||[]);
|
||||
for(var R = r.s.r; R <= r.e.r; ++R) {
|
||||
var oo = [];
|
||||
for(var C = r.s.c; C <= r.e.c; ++C) {
|
||||
var RS = 0, CS = 0;
|
||||
for(var j = 0; j < M.length; ++j) {
|
||||
if(M[j].s.r > R || M[j].s.c > C) continue;
|
||||
if(M[j].e.r < R || M[j].e.c < C) continue;
|
||||
if(M[j].s.r < R || M[j].s.c < C) { RS = -1; break; }
|
||||
RS = M[j].e.r - M[j].s.r + 1; CS = M[j].e.c - M[j].s.c + 1; break;
|
||||
}
|
||||
if(RS < 0) continue;
|
||||
var coord = encode_cell({r:R,c:C});
|
||||
cell = dense ? (ws[R]||[])[C] : ws[coord];
|
||||
if(!cell || cell.v == null) { oo.push("<td></td>"); continue; }
|
||||
/* TODO: html entities */
|
||||
var w = cell.h || escapexml(cell.w || (format_cell(cell), cell.w) || "");
|
||||
var sp = {};
|
||||
if(RS > 1) sp.rowspan = RS;
|
||||
if(CS > 1) sp.colspan = CS;
|
||||
oo.push(writextag('td', w, sp));
|
||||
}
|
||||
o.push("<tr>" + oo.join("") + "</tr>");
|
||||
}
|
||||
var r = decode_range(ws['!ref']);
|
||||
o.dense = Array.isArray(ws);
|
||||
for(var R = r.s.r; R <= r.e.r; ++R) o.push(make_html_row(ws, r, R, o));
|
||||
return "<html><body><table>" + o.join("") + "</table></body></html>";
|
||||
}
|
||||
|
||||
return {
|
||||
to_workbook: html_to_book,
|
||||
to_sheet: html_to_sheet,
|
||||
_row: make_html_row,
|
||||
from_sheet: sheet_to_html
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -28,8 +28,35 @@ if(has_buf && typeof require != 'undefined') (function() {
|
|||
return stream;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
XLSX.stream = {
|
||||
to_html: write_html_stream,
|
||||
to_csv: write_csv_stream
|
||||
};
|
||||
})();
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,10 @@
|
|||
### Streaming Write
|
||||
|
||||
`XLSX.stream.to_csv` is the streaming version of `XLSX.utils.sheet_to_csv`. It
|
||||
takes the same arguments but returns a readable stream.
|
||||
The streaming write functions are available in the `XLSX.stream` object. They
|
||||
take the same arguments as the normal write functions but return a readable
|
||||
stream. They are only exposed in node.
|
||||
|
||||
<https://github.com/sheetjs/sheetaki> pipes CSV write stream to nodejs response.
|
||||
- `XLSX.stream.to_csv` is the streaming version of `XLSX.utils.sheet_to_csv`.
|
||||
- `XLSX.stream.to_html` is the streaming version of the HTML output type.
|
||||
|
||||
<https://github.com/sheetjs/sheetaki> pipes write streams to nodejs response.
|
||||
|
|
|
@ -23,6 +23,8 @@ Parse options are described in the [Parsing Options](#parsing-options) section.
|
|||
`XLSX.writeFileAsync(filename, wb, o, cb)` attempts to write `wb` to `filename`.
|
||||
If `o` is omitted, the writer will use the third argument as the callback.
|
||||
|
||||
`XLSX.stream` contains a set of streaming write functions.
|
||||
|
||||
Write options are described in the [Writing Options](#writing-options) section.
|
||||
|
||||
### Utilities
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "xlsx",
|
||||
"version": "0.9.10",
|
||||
"version": "0.9.11",
|
||||
"author": "sheetjs",
|
||||
"description": "Excel (XLSB/XLSX/XLSM/XLS/XML) and ODS (ODS/FODS/UOS) spreadsheet parser and writer",
|
||||
"keywords": [ "excel", "xls", "xlsx", "xlsb", "xlsm", "ods", "office", "spreadsheet" ],
|
||||
|
|
83
xlsx.flow.js
83
xlsx.flow.js
|
@ -5,7 +5,7 @@
|
|||
/*exported XLSX */
|
||||
var XLSX = {};
|
||||
(function make_xlsx(XLSX){
|
||||
XLSX.version = '0.9.10';
|
||||
XLSX.version = '0.9.11';
|
||||
var current_codepage = 1200, current_cptable;
|
||||
/*:: declare var cptable:any; */
|
||||
if(typeof module !== "undefined" && typeof require !== 'undefined') {
|
||||
|
@ -15111,40 +15111,42 @@ var HTML_ = (function() {
|
|||
function html_to_book(str/*:string*/, opts)/*:Workbook*/ {
|
||||
return sheet_to_workbook(html_to_sheet(str, opts), opts);
|
||||
}
|
||||
function make_html_row(ws/*:Worksheet*/, r/*:Range*/, R/*:number*/, o)/*:string*/ {
|
||||
var M = (ws['!merges'] ||[]);
|
||||
var oo = [];
|
||||
for(var C = r.s.c; C <= r.e.c; ++C) {
|
||||
var RS = 0, CS = 0;
|
||||
for(var j = 0; j < M.length; ++j) {
|
||||
if(M[j].s.r > R || M[j].s.c > C) continue;
|
||||
if(M[j].e.r < R || M[j].e.c < C) continue;
|
||||
if(M[j].s.r < R || M[j].s.c < C) { RS = -1; break; }
|
||||
RS = M[j].e.r - M[j].s.r + 1; CS = M[j].e.c - M[j].s.c + 1; break;
|
||||
}
|
||||
if(RS < 0) continue;
|
||||
var coord = encode_cell({r:R,c:C});
|
||||
var cell = o.dense ? (ws[R]||[])[C] : ws[coord];
|
||||
if(!cell || cell.v == null) { oo.push("<td></td>"); continue; }
|
||||
/* TODO: html entities */
|
||||
var w = cell.h || escapexml(cell.w || (format_cell(cell), cell.w) || "");
|
||||
var sp = {};
|
||||
if(RS > 1) sp.rowspan = RS;
|
||||
if(CS > 1) sp.colspan = CS;
|
||||
oo.push(writextag('td', w, sp));
|
||||
}
|
||||
return "<tr>" + oo.join("") + "</tr>";
|
||||
}
|
||||
function sheet_to_html(ws/*:Worksheet*/, opts)/*:string*/ {
|
||||
var o/*:Array<string>*/ = [];
|
||||
var r = decode_range(ws['!ref']), cell/*:Cell*/;
|
||||
var dense = Array.isArray(ws);
|
||||
var M = (ws['!merges'] ||[]);
|
||||
for(var R = r.s.r; R <= r.e.r; ++R) {
|
||||
var oo = [];
|
||||
for(var C = r.s.c; C <= r.e.c; ++C) {
|
||||
var RS = 0, CS = 0;
|
||||
for(var j = 0; j < M.length; ++j) {
|
||||
if(M[j].s.r > R || M[j].s.c > C) continue;
|
||||
if(M[j].e.r < R || M[j].e.c < C) continue;
|
||||
if(M[j].s.r < R || M[j].s.c < C) { RS = -1; break; }
|
||||
RS = M[j].e.r - M[j].s.r + 1; CS = M[j].e.c - M[j].s.c + 1; break;
|
||||
}
|
||||
if(RS < 0) continue;
|
||||
var coord = encode_cell({r:R,c:C});
|
||||
cell = dense ? (ws[R]||[])[C] : ws[coord];
|
||||
if(!cell || cell.v == null) { oo.push("<td></td>"); continue; }
|
||||
/* TODO: html entities */
|
||||
var w = cell.h || escapexml(cell.w || (format_cell(cell), cell.w) || "");
|
||||
var sp = {};
|
||||
if(RS > 1) sp.rowspan = RS;
|
||||
if(CS > 1) sp.colspan = CS;
|
||||
oo.push(writextag('td', w, sp));
|
||||
}
|
||||
o.push("<tr>" + oo.join("") + "</tr>");
|
||||
}
|
||||
var r = decode_range(ws['!ref']);
|
||||
o.dense = Array.isArray(ws);
|
||||
for(var R = r.s.r; R <= r.e.r; ++R) o.push(make_html_row(ws, r, R, o));
|
||||
return "<html><body><table>" + o.join("") + "</table></body></html>";
|
||||
}
|
||||
|
||||
return {
|
||||
to_workbook: html_to_book,
|
||||
to_sheet: html_to_sheet,
|
||||
_row: make_html_row,
|
||||
from_sheet: sheet_to_html
|
||||
};
|
||||
})();
|
||||
|
@ -16614,8 +16616,35 @@ if(has_buf && typeof require != 'undefined') (function() {
|
|||
return stream;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
XLSX.stream = {
|
||||
to_html: write_html_stream,
|
||||
to_csv: write_csv_stream
|
||||
};
|
||||
})();
|
||||
|
|
83
xlsx.js
83
xlsx.js
|
@ -5,7 +5,7 @@
|
|||
/*exported XLSX */
|
||||
var XLSX = {};
|
||||
(function make_xlsx(XLSX){
|
||||
XLSX.version = '0.9.10';
|
||||
XLSX.version = '0.9.11';
|
||||
var current_codepage = 1200, current_cptable;
|
||||
if(typeof module !== "undefined" && typeof require !== 'undefined') {
|
||||
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel.js');
|
||||
|
@ -15050,40 +15050,42 @@ var HTML_ = (function() {
|
|||
function html_to_book(str, opts) {
|
||||
return sheet_to_workbook(html_to_sheet(str, opts), opts);
|
||||
}
|
||||
function make_html_row(ws, r, R, o) {
|
||||
var M = (ws['!merges'] ||[]);
|
||||
var oo = [];
|
||||
for(var C = r.s.c; C <= r.e.c; ++C) {
|
||||
var RS = 0, CS = 0;
|
||||
for(var j = 0; j < M.length; ++j) {
|
||||
if(M[j].s.r > R || M[j].s.c > C) continue;
|
||||
if(M[j].e.r < R || M[j].e.c < C) continue;
|
||||
if(M[j].s.r < R || M[j].s.c < C) { RS = -1; break; }
|
||||
RS = M[j].e.r - M[j].s.r + 1; CS = M[j].e.c - M[j].s.c + 1; break;
|
||||
}
|
||||
if(RS < 0) continue;
|
||||
var coord = encode_cell({r:R,c:C});
|
||||
var cell = o.dense ? (ws[R]||[])[C] : ws[coord];
|
||||
if(!cell || cell.v == null) { oo.push("<td></td>"); continue; }
|
||||
/* TODO: html entities */
|
||||
var w = cell.h || escapexml(cell.w || (format_cell(cell), cell.w) || "");
|
||||
var sp = {};
|
||||
if(RS > 1) sp.rowspan = RS;
|
||||
if(CS > 1) sp.colspan = CS;
|
||||
oo.push(writextag('td', w, sp));
|
||||
}
|
||||
return "<tr>" + oo.join("") + "</tr>";
|
||||
}
|
||||
function sheet_to_html(ws, opts) {
|
||||
var o = [];
|
||||
var r = decode_range(ws['!ref']), cell;
|
||||
var dense = Array.isArray(ws);
|
||||
var M = (ws['!merges'] ||[]);
|
||||
for(var R = r.s.r; R <= r.e.r; ++R) {
|
||||
var oo = [];
|
||||
for(var C = r.s.c; C <= r.e.c; ++C) {
|
||||
var RS = 0, CS = 0;
|
||||
for(var j = 0; j < M.length; ++j) {
|
||||
if(M[j].s.r > R || M[j].s.c > C) continue;
|
||||
if(M[j].e.r < R || M[j].e.c < C) continue;
|
||||
if(M[j].s.r < R || M[j].s.c < C) { RS = -1; break; }
|
||||
RS = M[j].e.r - M[j].s.r + 1; CS = M[j].e.c - M[j].s.c + 1; break;
|
||||
}
|
||||
if(RS < 0) continue;
|
||||
var coord = encode_cell({r:R,c:C});
|
||||
cell = dense ? (ws[R]||[])[C] : ws[coord];
|
||||
if(!cell || cell.v == null) { oo.push("<td></td>"); continue; }
|
||||
/* TODO: html entities */
|
||||
var w = cell.h || escapexml(cell.w || (format_cell(cell), cell.w) || "");
|
||||
var sp = {};
|
||||
if(RS > 1) sp.rowspan = RS;
|
||||
if(CS > 1) sp.colspan = CS;
|
||||
oo.push(writextag('td', w, sp));
|
||||
}
|
||||
o.push("<tr>" + oo.join("") + "</tr>");
|
||||
}
|
||||
var r = decode_range(ws['!ref']);
|
||||
o.dense = Array.isArray(ws);
|
||||
for(var R = r.s.r; R <= r.e.r; ++R) o.push(make_html_row(ws, r, R, o));
|
||||
return "<html><body><table>" + o.join("") + "</table></body></html>";
|
||||
}
|
||||
|
||||
return {
|
||||
to_workbook: html_to_book,
|
||||
to_sheet: html_to_sheet,
|
||||
_row: make_html_row,
|
||||
from_sheet: sheet_to_html
|
||||
};
|
||||
})();
|
||||
|
@ -16544,8 +16546,35 @@ if(has_buf && typeof require != 'undefined') (function() {
|
|||
return stream;
|
||||
};
|
||||
|
||||
var HTML_BEGIN = "<html><body><table>";
|
||||
var HTML_END = "</table></body></html>";
|
||||
|
||||
var write_html_stream = function(sheet, opts) {
|
||||
var stream = Readable();
|
||||
|
||||
var o = [];
|
||||
var r = decode_range(sheet['!ref']), 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;
|
||||
};
|
||||
|
||||
XLSX.stream = {
|
||||
to_html: write_html_stream,
|
||||
to_csv: write_csv_stream
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue