version bump 0.16.5: sheet_add_dom (fixes )

This commit is contained in:
SheetJS 2020-07-30 23:38:44 -04:00
parent 41cc307e2d
commit 227f970ca1
26 changed files with 944 additions and 564 deletions

@ -2116,6 +2116,56 @@ var wb = XLSX.utils.table_to_book(tbl);
Note: `XLSX.read` can handle HTML represented as strings. Note: `XLSX.read` can handle HTML represented as strings.
`XLSX.utils.sheet_add_dom` takes a table DOM element and updates an existing
worksheet object. It follows the same process as `table_to_sheet` and accepts
an options argument:
| Option Name | Default | Description |
| :---------- | :------: | :-------------------------------------------------- |
|`raw` | | If true, every cell will hold raw strings |
|`dateNF` | FMT 14 | Use specified date format in string output |
|`cellDates` | false | Store dates as type `d` (default is `n`) |
|`sheetRows` | 0 | If >0, read the first `sheetRows` rows of the table |
|`display` | false | If true, hidden rows and cells will not be parsed |
`origin` is expected to be one of:
| `origin` | Description |
| :--------------- | :-------------------------------------------------------- |
| (cell object) | Use specified cell (cell object) |
| (string) | Use specified cell (A1-style cell) |
| (number >= 0) | Start from the first column at specified row (0-indexed) |
| -1 | Append to bottom of worksheet starting on first column |
| (default) | Start from cell A1 |
<details>
<summary><b>Examples</b> (click to show)</summary>
A small helper function can create gap rows between tables:
```js
function create_gap_rows(ws, nrows) {
var ref = XLSX.utils.decode_range(ws["!ref"]); // get original range
ref.e.r += nrows; // add to ending row
ws["!ref"] = XLSX.utils.encode_range(ref); // reassign row
}
/* first table */
var ws = XLSX.utils.table_to_sheet(document.getElementById('table1'));
create_gap_rows(ws, 1); // one row gap after first table
/* second table */
XLSX.utils.sheet_add_dom(ws, document.getElementById('table2'), {origin: -1});
create_gap_rows(ws, 3); // three rows gap after second table
/* third table */
XLSX.utils.sheet_add_dom(ws, document.getElementById('table3'), {origin: -1});
```
</details>
### Formulae Output ### Formulae Output
`XLSX.utils.sheet_to_formulae` generates an array of commands that represent `XLSX.utils.sheet_to_formulae` generates an array of commands that represent

@ -1 +1 @@
XLSX.version = '0.16.4'; XLSX.version = '0.16.5';

@ -26,7 +26,11 @@ function encode_cell(cell/*:CellAddress*/)/*:string*/ {
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
return s + (cell.r + 1); return s + (cell.r + 1);
} }
function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } function decode_range(range/*:string*/)/*:Range*/ {
var idx = range.indexOf(":");
if(idx == -1) return { s: decode_cell(range), e: decode_cell(range) };
return { s: decode_cell(range.slice(0, idx)), e: decode_cell(range.slice(idx + 1)) };
}
/*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */ /*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */
function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ { function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ {
if(typeof ce === 'undefined' || typeof ce === 'number') { if(typeof ce === 'undefined' || typeof ce === 'number') {
@ -105,6 +109,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
var _origin/*:CellAddress*/ = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin; var _origin/*:CellAddress*/ = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
_R = _origin.r; _C = _origin.c; _R = _origin.r; _C = _origin.c;
} }
if(!ws["!ref"]) ws["!ref"] = "A1:A1";
} }
var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}/*:any*/); var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}/*:any*/);
if(ws['!ref']) { if(ws['!ref']) {

@ -690,7 +690,7 @@ var PtgBinOp = {
}; };
// List of invalid characters needs to be tested further // List of invalid characters needs to be tested further
var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/);
function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ { function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ {
if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name");
if (quoteCharacters.test(sname)) return "'" + sname + "'"; if (quoteCharacters.test(sname)) return "'" + sname + "'";

@ -119,16 +119,32 @@ var HTML_ = (function() {
}; };
})(); })();
function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ { function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var opts = _opts || {}; var opts = _opts || {};
if(DENSE != null) opts.dense = DENSE; if(DENSE != null) opts.dense = DENSE;
var ws/*:Worksheet*/ = opts.dense ? ([]/*:any*/) : ({}/*:any*/); var or_R = 0, or_C = 0;
if(opts.origin != null) {
if(typeof opts.origin == 'number') or_R = opts.origin;
else {
var _origin/*:CellAddress*/ = typeof opts.origin == "string" ? decode_cell(opts.origin) : opts.origin;
or_R = _origin.r; or_C = _origin.c;
}
}
var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr'); var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000; var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range/*:Range*/ = {s:{r:0,c:0},e:{r:0,c:0}}; var range/*:Range*/ = {s:{r:0,c:0},e:{r:or_R,c:or_C}};
if(ws["!ref"]) {
var _range/*:Range*/ = decode_range(ws["!ref"]);
range.s.r = Math.min(range.s.r, _range.s.r);
range.s.c = Math.min(range.s.c, _range.s.c);
range.e.r = Math.max(range.e.r, _range.e.r);
range.e.c = Math.max(range.e.c, _range.e.c);
if(or_R == -1) range.e.r = or_R = _range.e.r + 1;
}
var merges/*:Array<Range>*/ = [], midx = 0; var merges/*:Array<Range>*/ = [], midx = 0;
var rowinfo/*:Array<RowInfo>*/ = []; var rowinfo/*:Array<RowInfo>*/ = ws["!rows"] || (ws["!rows"] = []);
var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0; var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0;
if(!ws["!cols"]) ws['!cols'] = [];
for(; _R < rows.length && R < sheetRows; ++_R) { for(; _R < rows.length && R < sheetRows; ++_R) {
var row/*:HTMLTableRowElement*/ = rows[_R]; var row/*:HTMLTableRowElement*/ = rows[_R];
if (is_dom_element_hidden(row)) { if (is_dom_element_hidden(row)) {
@ -143,11 +159,11 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var z/*:?string*/ = elt.getAttribute('z'); var z/*:?string*/ = elt.getAttribute('z');
for(midx = 0; midx < merges.length; ++midx) { for(midx = 0; midx < merges.length; ++midx) {
var m/*:Range*/ = merges[midx]; var m/*:Range*/ = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } if(m.s.c == C + or_C && m.s.r < R + or_R && R + or_R <= m.e.r) { C = m.e.c+1 - or_C; midx = -1; }
} }
/* TODO: figure out how to extract nonstandard mso- style */ /* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1; CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); if( ((RS = (+elt.getAttribute("rowspan") || 1)))>1 || CS>1) merges.push({s:{r:R + or_R,c:C + or_C},e:{r:R + or_R + (RS||1) - 1, c:C + or_C + (CS||1) - 1}});
var o/*:Cell*/ = {t:'s', v:v}; var o/*:Cell*/ = {t:'s', v:v};
var _t/*:string*/ = elt.getAttribute("t") || ""; var _t/*:string*/ = elt.getAttribute("t") || "";
if(v != null) { if(v != null) {
@ -163,21 +179,26 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
} }
} }
if(o.z === undefined && z != null) o.z = z; if(o.z === undefined && z != null) o.z = z;
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} if(opts.dense) { if(!ws[R + or_R]) ws[R + or_R] = []; ws[R + or_R][C + or_C] = o; }
else ws[encode_cell({c:C, r:R})] = o; else ws[encode_cell({c:C + or_C, r:R + or_R})] = o;
if(range.e.c < C) range.e.c = C; if(range.e.c < C + or_C) range.e.c = C + or_C;
C += CS; C += CS;
} }
++R; ++R;
} }
if(merges.length) ws['!merges'] = merges; if(merges.length) ws['!merges'] = (ws["!merges"] || []).concat(merges);
if(rowinfo.length) ws['!rows'] = rowinfo; range.e.r = Math.max(range.e.r, R - 1 + or_R);
range.e.r = R - 1;
ws['!ref'] = encode_range(range); ws['!ref'] = encode_range(range);
if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1,range)); // We can count the real number of rows to parse but we don't to improve the performance if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1 + or_R,range)); // We can count the real number of rows to parse but we don't to improve the performance
return ws; return ws;
} }
function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var opts = _opts || {};
var ws/*:Worksheet*/ = opts.dense ? ([]/*:any*/) : ({}/*:any*/);
return sheet_add_dom(ws, table, _opts);
}
function table_to_book(table/*:HTMLElement*/, opts/*:?any*/)/*:Workbook*/ { function table_to_book(table/*:HTMLElement*/, opts/*:?any*/)/*:Workbook*/ {
return sheet_to_workbook(parse_dom_table(table, opts), opts); return sheet_to_workbook(parse_dom_table(table, opts), opts);
} }

@ -179,6 +179,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
} }
function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet*/ { function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet*/ {
if(!js.length) return _ws;
var o = opts || {}; var o = opts || {};
var offset = +!o.skipHeader; var offset = +!o.skipHeader;
var ws/*:Worksheet*/ = _ws || ({}/*:any*/); var ws/*:Worksheet*/ = _ws || ({}/*:any*/);
@ -197,6 +198,8 @@ function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet
range.e.c = Math.max(range.e.c, _range.e.c); range.e.c = Math.max(range.e.c, _range.e.c);
range.e.r = Math.max(range.e.r, _range.e.r); range.e.r = Math.max(range.e.r, _range.e.r);
if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; } if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; }
} else {
if(_R == -1) { _R = 0; range.e.r = js.length - 1 + offset; }
} }
var hdr/*:Array<string>*/ = o.header || [], C = 0; var hdr/*:Array<string>*/ = o.header || [], C = 0;
@ -254,6 +257,7 @@ var utils/*:any*/ = {
make_formulae: sheet_to_formulae, make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa, sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json, sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
aoa_to_sheet: aoa_to_sheet, aoa_to_sheet: aoa_to_sheet,
json_to_sheet: json_to_sheet, json_to_sheet: json_to_sheet,
table_to_sheet: parse_dom_table, table_to_sheet: parse_dom_table,

26
dist/xlsx.core.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.core.min.map generated vendored

File diff suppressed because one or more lines are too long

231
dist/xlsx.extendscript.js generated vendored

@ -9161,7 +9161,7 @@ module.exports = ZStream;
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {}; var XLSX = {};
function make_xlsx_lib(XLSX){ function make_xlsx_lib(XLSX){
XLSX.version = '0.16.4'; XLSX.version = '0.16.5';
var current_codepage = 1200, current_ansi = 1252; var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */ /*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') { if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -12837,7 +12837,11 @@ function encode_cell(cell) {
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
return s + (cell.r + 1); return s + (cell.r + 1);
} }
function decode_range(range) { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } function decode_range(range) {
var idx = range.indexOf(":");
if(idx == -1) return { s: decode_cell(range), e: decode_cell(range) };
return { s: decode_cell(range.slice(0, idx)), e: decode_cell(range.slice(idx + 1)) };
}
function encode_range(cs,ce) { function encode_range(cs,ce) {
if(typeof ce === 'undefined' || typeof ce === 'number') { if(typeof ce === 'undefined' || typeof ce === 'number') {
return encode_range(cs.s, cs.e); return encode_range(cs.s, cs.e);
@ -12911,6 +12915,7 @@ function sheet_add_aoa(_ws, data, opts) {
var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin; var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
_R = _origin.r; _C = _origin.c; _R = _origin.r; _C = _origin.c;
} }
if(!ws["!ref"]) ws["!ref"] = "A1:A1";
} }
var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}); var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}});
if(ws['!ref']) { if(ws['!ref']) {
@ -12962,7 +12967,7 @@ function sheet_add_aoa(_ws, data, opts) {
function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); } function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); }
function write_UInt32LE(x, o) { function write_UInt32LE(x, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(4, x); o.write_shift(4, x);
return o; return o;
} }
@ -12973,9 +12978,9 @@ function parse_XLWideString(data) {
return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLWideString(data, o) { function write_XLWideString(data, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(4+2*data.length); } var _null = false; if (o == null) { _null = true; o = new_buf(4 + 2 * data.length); }
o.write_shift(4, data.length); o.write_shift(4, data.length);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -12990,7 +12995,7 @@ function parse_StrRun(data) {
return { ich: data.read_shift(2), ifnt: data.read_shift(2) }; return { ich: data.read_shift(2), ifnt: data.read_shift(2) };
} }
function write_StrRun(run, o) { function write_StrRun(run, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(2, run.ich || 0); o.write_shift(2, run.ich || 0);
o.write_shift(2, run.ifnt || 0); o.write_shift(2, run.ifnt || 0);
return o; return o;
@ -13003,13 +13008,13 @@ function parse_RichStr(data, length) {
var str = parse_XLWideString(data); var str = parse_XLWideString(data);
var rgsStrRun = []; var rgsStrRun = [];
var z = ({ t: str, h: str }); var z = ({ t: str, h: str });
if((flags & 1) !== 0) { /* fRichStr */ if ((flags & 1) !== 0) { /* fRichStr */
/* TODO: formatted string */ /* TODO: formatted string */
var dwSizeStrRun = data.read_shift(4); var dwSizeStrRun = data.read_shift(4);
for(var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data)); for (var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data));
z.r = rgsStrRun; z.r = rgsStrRun;
} }
else z.r = [{ich:0, ifnt:0}]; else z.r = [{ ich: 0, ifnt: 0 }];
//if((flags & 2) !== 0) { /* fExtStr */ //if((flags & 2) !== 0) { /* fExtStr */
// /* TODO: phonetic string */ // /* TODO: phonetic string */
//} //}
@ -13018,8 +13023,8 @@ function parse_RichStr(data, length) {
} }
function write_RichStr(str, o) { function write_RichStr(str, o) {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(15+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(15 + 4 * str.t.length); }
o.write_shift(1,0); o.write_shift(1, 0);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -13027,11 +13032,11 @@ function write_RichStr(str, o) {
var parse_BrtCommentText = parse_RichStr; var parse_BrtCommentText = parse_RichStr;
function write_BrtCommentText(str, o) { function write_BrtCommentText(str, o) {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(23+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(23 + 4 * str.t.length); }
o.write_shift(1,1); o.write_shift(1, 1);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
o.write_shift(4,1); o.write_shift(4, 1);
write_StrRun({ich:0,ifnt:0}, o); write_StrRun({ ich: 0, ifnt: 0 }, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -13039,12 +13044,12 @@ function write_BrtCommentText(str, o) {
function parse_XLSBCell(data) { function parse_XLSBCell(data) {
var col = data.read_shift(4); var col = data.read_shift(4);
var iStyleRef = data.read_shift(2); var iStyleRef = data.read_shift(2);
iStyleRef += data.read_shift(1) <<16; iStyleRef += data.read_shift(1) << 16;
data.l++; //var fPhShow = data.read_shift(1); data.l++; //var fPhShow = data.read_shift(1);
return { c:col, iStyleRef: iStyleRef }; return { c: col, iStyleRef: iStyleRef };
} }
function write_XLSBCell(cell, o) { function write_XLSBCell(cell, o) {
if(o == null) o = new_buf(8); if (o == null) o = new_buf(8);
o.write_shift(-4, cell.c); o.write_shift(-4, cell.c);
o.write_shift(3, cell.iStyleRef || cell.s); o.write_shift(3, cell.iStyleRef || cell.s);
o.write_shift(1, 0); /* fPhShow */ o.write_shift(1, 0); /* fPhShow */
@ -13062,9 +13067,9 @@ function parse_XLNullableWideString(data) {
return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLNullableWideString(data, o) { function write_XLNullableWideString(data, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(127); } var _null = false; if (o == null) { _null = true; o = new_buf(127); }
o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF); o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -13079,26 +13084,26 @@ var write_RelID = write_XLNullableWideString;
/* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */ /* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */
function parse_RkNumber(data) { function parse_RkNumber(data) {
var b = data.slice(data.l, data.l+4); var b = data.slice(data.l, data.l + 4);
var fX100 = (b[0] & 1), fInt = (b[0] & 2); var fX100 = (b[0] & 1), fInt = (b[0] & 2);
data.l+=4; data.l += 4;
b[0] &= 0xFC; // b[0] &= ~3; b[0] &= 0xFC; // b[0] &= ~3;
var RK = fInt === 0 ? __double([0,0,0,0,b[0],b[1],b[2],b[3]],0) : __readInt32LE(b,0)>>2; var RK = fInt === 0 ? __double([0, 0, 0, 0, b[0], b[1], b[2], b[3]], 0) : __readInt32LE(b, 0) >> 2;
return fX100 ? (RK/100) : RK; return fX100 ? (RK / 100) : RK;
} }
function write_RkNumber(data, o) { function write_RkNumber(data, o) {
if(o == null) o = new_buf(4); if (o == null) o = new_buf(4);
var fX100 = 0, fInt = 0, d100 = data * 100; var fX100 = 0, fInt = 0, d100 = data * 100;
if((data == (data | 0)) && (data >= -(1<<29)) && (data < (1 << 29))) { fInt = 1; } if ((data == (data | 0)) && (data >= -(1 << 29)) && (data < (1 << 29))) { fInt = 1; }
else if((d100 == (d100 | 0)) && (d100 >= -(1<<29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; } else if ((d100 == (d100 | 0)) && (d100 >= -(1 << 29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; }
if(fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2)); if (fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2));
else throw new Error("unsupported RkNumber " + data); // TODO else throw new Error("unsupported RkNumber " + data); // TODO
} }
/* [MS-XLSB] 2.5.117 RfX */ /* [MS-XLSB] 2.5.117 RfX */
function parse_RfX(data ) { function parse_RfX(data ) {
var cell = ({s: {}, e: {}}); var cell = ({ s: {}, e: {} });
cell.s.r = data.read_shift(4); cell.s.r = data.read_shift(4);
cell.e.r = data.read_shift(4); cell.e.r = data.read_shift(4);
cell.s.c = data.read_shift(4); cell.s.c = data.read_shift(4);
@ -13106,7 +13111,7 @@ function parse_RfX(data ) {
return cell; return cell;
} }
function write_RfX(r, o) { function write_RfX(r, o) {
if(!o) o = new_buf(16); if (!o) o = new_buf(16);
o.write_shift(4, r.s.r); o.write_shift(4, r.s.r);
o.write_shift(4, r.e.r); o.write_shift(4, r.e.r);
o.write_shift(4, r.s.c); o.write_shift(4, r.s.c);
@ -13143,20 +13148,6 @@ var write_UncheckedRfX = write_RfX;
function parse_Xnum(data) { return data.read_shift(8, 'f'); } function parse_Xnum(data) { return data.read_shift(8, 'f'); }
function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); } function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); }
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA",
0xFF: "#WTF?"
};
var RBErr = evert_num(BErr);
/* [MS-XLSB] 2.4.324 BrtColor */ /* [MS-XLSB] 2.4.324 BrtColor */
function parse_BrtColor(data) { function parse_BrtColor(data) {
var out = {}; var out = {};
@ -13172,13 +13163,13 @@ function parse_BrtColor(data) {
var bB = data.read_shift(1); var bB = data.read_shift(1);
data.l++; //var bAlpha = data.read_shift(1); data.l++; //var bAlpha = data.read_shift(1);
switch(xColorType) { switch (xColorType) {
case 0: out.auto = 1; break; case 0: out.auto = 1; break;
case 1: case 1:
out.index = index; out.index = index;
var icv = XLSIcv[index]; var icv = XLSIcv[index];
/* automatic pseudo index 81 */ /* automatic pseudo index 81 */
if(icv) out.rgb = rgb2Hex(icv); if (icv) out.rgb = rgb2Hex(icv);
break; break;
case 2: case 2:
/* if(!fValidRGB) throw new Error("invalid"); */ /* if(!fValidRGB) throw new Error("invalid"); */
@ -13186,17 +13177,17 @@ function parse_BrtColor(data) {
break; break;
case 3: out.theme = index; break; case 3: out.theme = index; break;
} }
if(nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768; if (nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768;
return out; return out;
} }
function write_BrtColor(color, o) { function write_BrtColor(color, o) {
if(!o) o = new_buf(8); if (!o) o = new_buf(8);
if(!color||color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; } if (!color || color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; }
if(color.index != null) { if (color.index != null) {
o.write_shift(1, 0x02); o.write_shift(1, 0x02);
o.write_shift(1, color.index); o.write_shift(1, color.index);
} else if(color.theme != null) { } else if (color.theme != null) {
o.write_shift(1, 0x06); o.write_shift(1, 0x06);
o.write_shift(1, color.theme); o.write_shift(1, color.theme);
} else { } else {
@ -13204,19 +13195,19 @@ function write_BrtColor(color, o) {
o.write_shift(1, 0); o.write_shift(1, 0);
} }
var nTS = color.tint || 0; var nTS = color.tint || 0;
if(nTS > 0) nTS *= 32767; if (nTS > 0) nTS *= 32767;
else if(nTS < 0) nTS *= 32768; else if (nTS < 0) nTS *= 32768;
o.write_shift(2, nTS); o.write_shift(2, nTS);
if(!color.rgb || color.theme != null) { if (!color.rgb || color.theme != null) {
o.write_shift(2, 0); o.write_shift(2, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
} else { } else {
var rgb = (color.rgb || 'FFFFFF'); var rgb = (color.rgb || 'FFFFFF');
if(typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6); if (typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6);
o.write_shift(1, parseInt(rgb.slice(0,2),16)); o.write_shift(1, parseInt(rgb.slice(0, 2), 16));
o.write_shift(1, parseInt(rgb.slice(2,4),16)); o.write_shift(1, parseInt(rgb.slice(2, 4), 16));
o.write_shift(1, parseInt(rgb.slice(4,6),16)); o.write_shift(1, parseInt(rgb.slice(4, 6), 16));
o.write_shift(1, 0xFF); o.write_shift(1, 0xFF);
} }
return o; return o;
@ -13239,14 +13230,14 @@ function parse_FontFlags(data) {
return out; return out;
} }
function write_FontFlags(font, o) { function write_FontFlags(font, o) {
if(!o) o = new_buf(2); if (!o) o = new_buf(2);
var grbit = var grbit =
(font.italic ? 0x02 : 0) | (font.italic ? 0x02 : 0) |
(font.strike ? 0x08 : 0) | (font.strike ? 0x08 : 0) |
(font.outline ? 0x10 : 0) | (font.outline ? 0x10 : 0) |
(font.shadow ? 0x20 : 0) | (font.shadow ? 0x20 : 0) |
(font.condense ? 0x40 : 0) | (font.condense ? 0x40 : 0) |
(font.extend ? 0x80 : 0); (font.extend ? 0x80 : 0);
o.write_shift(1, grbit); o.write_shift(1, grbit);
o.write_shift(1, 0); o.write_shift(1, 0);
return o; return o;
@ -13255,13 +13246,13 @@ function write_FontFlags(font, o) {
/* [MS-OLEDS] 2.3.1 and 2.3.2 */ /* [MS-OLEDS] 2.3.1 and 2.3.2 */
function parse_ClipboardFormatOrString(o, w) { function parse_ClipboardFormatOrString(o, w) {
// $FlowIgnore // $FlowIgnore
var ClipFmt = {2:"BITMAP",3:"METAFILEPICT",8:"DIB",14:"ENHMETAFILE"}; var ClipFmt = { 2: "BITMAP", 3: "METAFILEPICT", 8: "DIB", 14: "ENHMETAFILE" };
var m = o.read_shift(4); var m = o.read_shift(4);
switch(m) { switch (m) {
case 0x00000000: return ""; case 0x00000000: return "";
case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)]||""; case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)] || "";
} }
if(m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16)); if (m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16));
o.l -= 4; o.l -= 4;
return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr"); return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr");
} }
@ -13271,43 +13262,43 @@ function parse_ClipboardFormatOrUnicodeString(o) { return parse_ClipboardFormatO
/* [MS-OLEPS] 2.2 PropertyType */ /* [MS-OLEPS] 2.2 PropertyType */
//var VT_EMPTY = 0x0000; //var VT_EMPTY = 0x0000;
//var VT_NULL = 0x0001; //var VT_NULL = 0x0001;
var VT_I2 = 0x0002; var VT_I2 = 0x0002;
var VT_I4 = 0x0003; var VT_I4 = 0x0003;
//var VT_R4 = 0x0004; //var VT_R4 = 0x0004;
//var VT_R8 = 0x0005; //var VT_R8 = 0x0005;
//var VT_CY = 0x0006; //var VT_CY = 0x0006;
//var VT_DATE = 0x0007; //var VT_DATE = 0x0007;
//var VT_BSTR = 0x0008; //var VT_BSTR = 0x0008;
//var VT_ERROR = 0x000A; //var VT_ERROR = 0x000A;
var VT_BOOL = 0x000B; var VT_BOOL = 0x000B;
var VT_VARIANT = 0x000C; var VT_VARIANT = 0x000C;
//var VT_DECIMAL = 0x000E; //var VT_DECIMAL = 0x000E;
//var VT_I1 = 0x0010; //var VT_I1 = 0x0010;
//var VT_UI1 = 0x0011; //var VT_UI1 = 0x0011;
//var VT_UI2 = 0x0012; //var VT_UI2 = 0x0012;
var VT_UI4 = 0x0013; var VT_UI4 = 0x0013;
//var VT_I8 = 0x0014; //var VT_I8 = 0x0014;
//var VT_UI8 = 0x0015; //var VT_UI8 = 0x0015;
//var VT_INT = 0x0016; //var VT_INT = 0x0016;
//var VT_UINT = 0x0017; //var VT_UINT = 0x0017;
var VT_LPSTR = 0x001E; var VT_LPSTR = 0x001E;
//var VT_LPWSTR = 0x001F; //var VT_LPWSTR = 0x001F;
var VT_FILETIME = 0x0040; var VT_FILETIME = 0x0040;
var VT_BLOB = 0x0041; var VT_BLOB = 0x0041;
//var VT_STREAM = 0x0042; //var VT_STREAM = 0x0042;
//var VT_STORAGE = 0x0043; //var VT_STORAGE = 0x0043;
//var VT_STREAMED_Object = 0x0044; //var VT_STREAMED_Object = 0x0044;
//var VT_STORED_Object = 0x0045; //var VT_STORED_Object = 0x0045;
//var VT_BLOB_Object = 0x0046; //var VT_BLOB_Object = 0x0046;
var VT_CF = 0x0047; var VT_CF = 0x0047;
//var VT_CLSID = 0x0048; //var VT_CLSID = 0x0048;
//var VT_VERSIONED_STREAM = 0x0049; //var VT_VERSIONED_STREAM = 0x0049;
var VT_VECTOR = 0x1000; var VT_VECTOR = 0x1000;
//var VT_ARRAY = 0x2000; //var VT_ARRAY = 0x2000;
var VT_STRING = 0x0050; // 2.3.3.1.11 VtString var VT_STRING = 0x0050; // 2.3.3.1.11 VtString
var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString
var VT_CUSTOM = [VT_STRING, VT_USTR]; var VT_CUSTOM = [VT_STRING, VT_USTR];
/* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */ /* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */
var DocSummaryPIDDSI = { var DocSummaryPIDDSI = {
@ -13370,9 +13361,9 @@ var SpecialProperties = {
0x72627262: {} 0x72627262: {}
}; };
(function() { (function () {
for(var y in SpecialProperties) if(Object.prototype.hasOwnProperty.call(SpecialProperties, y)) for (var y in SpecialProperties) if (Object.prototype.hasOwnProperty.call(SpecialProperties, y))
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y]; DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})(); })();
var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n"); var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n");
@ -13455,7 +13446,7 @@ var XLSFillPattern = [
'gray0625' 'gray0625'
]; ];
function rgbify(arr) { return arr.map(function(x) { return [(x>>16)&255,(x>>8)&255,x&255]; }); } function rgbify(arr) { return arr.map(function (x) { return [(x >> 16) & 255, (x >> 8) & 255, x & 255]; }); }
/* [MS-XLS] 2.5.161 */ /* [MS-XLS] 2.5.161 */
/* [MS-XLSB] 2.5.75 Icv */ /* [MS-XLSB] 2.5.75 Icv */
@ -13552,7 +13543,20 @@ var _XLSIcv = rgbify([
0x000000 /* 0x51 icvInfoText ?? */ 0x000000 /* 0x51 icvInfoText ?? */
]); ]);
var XLSIcv = dup(_XLSIcv); var XLSIcv = dup(_XLSIcv);
/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA",
0xFF: "#WTF?"
};
var RBErr = evert_num(BErr);/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* 12.3 Part Summary <SpreadsheetML> */ /* 12.3 Part Summary <SpreadsheetML> */
/* 14.2 Part Summary <DrawingML> */ /* 14.2 Part Summary <DrawingML> */
/* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */ /* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */
@ -20437,7 +20441,7 @@ var PtgBinOp = {
}; };
// List of invalid characters needs to be tested further // List of invalid characters needs to be tested further
var quoteCharacters = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) var quoteCharacters = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/);
function formula_quote_sheet_name(sname, opts) { function formula_quote_sheet_name(sname, opts) {
if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name");
if (quoteCharacters.test(sname)) return "'" + sname + "'"; if (quoteCharacters.test(sname)) return "'" + sname + "'";
@ -24194,7 +24198,7 @@ function parse_wb_xml(data, opts) {
default: wb.WBProps[w[0]] = y[w[0]]; default: wb.WBProps[w[0]] = y[w[0]];
} }
}); });
if(y.codeName) wb.WBProps.CodeName = y.codeName; if(y.codeName) wb.WBProps.CodeName = utf8read(y.codeName);
break; break;
case '</workbookPr>': break; case '</workbookPr>': break;
@ -28712,16 +28716,32 @@ var HTML_ = (function() {
}; };
})(); })();
function parse_dom_table(table, _opts) { function sheet_add_dom(ws, table, _opts) {
var opts = _opts || {}; var opts = _opts || {};
if(DENSE != null) opts.dense = DENSE; if(DENSE != null) opts.dense = DENSE;
var ws = opts.dense ? ([]) : ({}); var or_R = 0, or_C = 0;
if(opts.origin != null) {
if(typeof opts.origin == 'number') or_R = opts.origin;
else {
var _origin = typeof opts.origin == "string" ? decode_cell(opts.origin) : opts.origin;
or_R = _origin.r; or_C = _origin.c;
}
}
var rows = table.getElementsByTagName('tr'); var rows = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000; var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range = {s:{r:0,c:0},e:{r:0,c:0}}; var range = {s:{r:0,c:0},e:{r:or_R,c:or_C}};
if(ws["!ref"]) {
var _range = decode_range(ws["!ref"]);
range.s.r = Math.min(range.s.r, _range.s.r);
range.s.c = Math.min(range.s.c, _range.s.c);
range.e.r = Math.max(range.e.r, _range.e.r);
range.e.c = Math.max(range.e.c, _range.e.c);
if(or_R == -1) range.e.r = or_R = _range.e.r + 1;
}
var merges = [], midx = 0; var merges = [], midx = 0;
var rowinfo = []; var rowinfo = ws["!rows"] || (ws["!rows"] = []);
var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0; var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0;
if(!ws["!cols"]) ws['!cols'] = [];
for(; _R < rows.length && R < sheetRows; ++_R) { for(; _R < rows.length && R < sheetRows; ++_R) {
var row = rows[_R]; var row = rows[_R];
if (is_dom_element_hidden(row)) { if (is_dom_element_hidden(row)) {
@ -28736,11 +28756,11 @@ function parse_dom_table(table, _opts) {
var z = elt.getAttribute('z'); var z = elt.getAttribute('z');
for(midx = 0; midx < merges.length; ++midx) { for(midx = 0; midx < merges.length; ++midx) {
var m = merges[midx]; var m = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } if(m.s.c == C + or_C && m.s.r < R + or_R && R + or_R <= m.e.r) { C = m.e.c+1 - or_C; midx = -1; }
} }
/* TODO: figure out how to extract nonstandard mso- style */ /* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1; CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); if( ((RS = (+elt.getAttribute("rowspan") || 1)))>1 || CS>1) merges.push({s:{r:R + or_R,c:C + or_C},e:{r:R + or_R + (RS||1) - 1, c:C + or_C + (CS||1) - 1}});
var o = {t:'s', v:v}; var o = {t:'s', v:v};
var _t = elt.getAttribute("t") || ""; var _t = elt.getAttribute("t") || "";
if(v != null) { if(v != null) {
@ -28756,21 +28776,26 @@ function parse_dom_table(table, _opts) {
} }
} }
if(o.z === undefined && z != null) o.z = z; if(o.z === undefined && z != null) o.z = z;
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} if(opts.dense) { if(!ws[R + or_R]) ws[R + or_R] = []; ws[R + or_R][C + or_C] = o; }
else ws[encode_cell({c:C, r:R})] = o; else ws[encode_cell({c:C + or_C, r:R + or_R})] = o;
if(range.e.c < C) range.e.c = C; if(range.e.c < C + or_C) range.e.c = C + or_C;
C += CS; C += CS;
} }
++R; ++R;
} }
if(merges.length) ws['!merges'] = merges; if(merges.length) ws['!merges'] = (ws["!merges"] || []).concat(merges);
if(rowinfo.length) ws['!rows'] = rowinfo; range.e.r = Math.max(range.e.r, R - 1 + or_R);
range.e.r = R - 1;
ws['!ref'] = encode_range(range); ws['!ref'] = encode_range(range);
if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1,range)); // We can count the real number of rows to parse but we don't to improve the performance if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1 + or_R,range)); // We can count the real number of rows to parse but we don't to improve the performance
return ws; return ws;
} }
function parse_dom_table(table, _opts) {
var opts = _opts || {};
var ws = opts.dense ? ([]) : ({});
return sheet_add_dom(ws, table, _opts);
}
function table_to_book(table, opts) { function table_to_book(table, opts) {
return sheet_to_workbook(parse_dom_table(table, opts), opts); return sheet_to_workbook(parse_dom_table(table, opts), opts);
} }
@ -30459,6 +30484,7 @@ function sheet_to_formulae(sheet) {
} }
function sheet_add_json(_ws, js, opts) { function sheet_add_json(_ws, js, opts) {
if(!js.length) return _ws;
var o = opts || {}; var o = opts || {};
var offset = +!o.skipHeader; var offset = +!o.skipHeader;
var ws = _ws || ({}); var ws = _ws || ({});
@ -30477,6 +30503,8 @@ function sheet_add_json(_ws, js, opts) {
range.e.c = Math.max(range.e.c, _range.e.c); range.e.c = Math.max(range.e.c, _range.e.c);
range.e.r = Math.max(range.e.r, _range.e.r); range.e.r = Math.max(range.e.r, _range.e.r);
if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; } if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; }
} else {
if(_R == -1) { _R = 0; range.e.r = js.length - 1 + offset; }
} }
var hdr = o.header || [], C = 0; var hdr = o.header || [], C = 0;
@ -30534,6 +30562,7 @@ var utils = {
make_formulae: sheet_to_formulae, make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa, sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json, sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
aoa_to_sheet: aoa_to_sheet, aoa_to_sheet: aoa_to_sheet,
json_to_sheet: json_to_sheet, json_to_sheet: json_to_sheet,
table_to_sheet: parse_dom_table, table_to_sheet: parse_dom_table,

28
dist/xlsx.full.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.full.min.map generated vendored

File diff suppressed because one or more lines are too long

231
dist/xlsx.js generated vendored

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {}; var XLSX = {};
function make_xlsx_lib(XLSX){ function make_xlsx_lib(XLSX){
XLSX.version = '0.16.4'; XLSX.version = '0.16.5';
var current_codepage = 1200, current_ansi = 1252; var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */ /*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') { if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -3680,7 +3680,11 @@ function encode_cell(cell) {
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
return s + (cell.r + 1); return s + (cell.r + 1);
} }
function decode_range(range) { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } function decode_range(range) {
var idx = range.indexOf(":");
if(idx == -1) return { s: decode_cell(range), e: decode_cell(range) };
return { s: decode_cell(range.slice(0, idx)), e: decode_cell(range.slice(idx + 1)) };
}
function encode_range(cs,ce) { function encode_range(cs,ce) {
if(typeof ce === 'undefined' || typeof ce === 'number') { if(typeof ce === 'undefined' || typeof ce === 'number') {
return encode_range(cs.s, cs.e); return encode_range(cs.s, cs.e);
@ -3754,6 +3758,7 @@ function sheet_add_aoa(_ws, data, opts) {
var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin; var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
_R = _origin.r; _C = _origin.c; _R = _origin.r; _C = _origin.c;
} }
if(!ws["!ref"]) ws["!ref"] = "A1:A1";
} }
var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}); var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}});
if(ws['!ref']) { if(ws['!ref']) {
@ -3805,7 +3810,7 @@ function sheet_add_aoa(_ws, data, opts) {
function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); } function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); }
function write_UInt32LE(x, o) { function write_UInt32LE(x, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(4, x); o.write_shift(4, x);
return o; return o;
} }
@ -3816,9 +3821,9 @@ function parse_XLWideString(data) {
return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLWideString(data, o) { function write_XLWideString(data, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(4+2*data.length); } var _null = false; if (o == null) { _null = true; o = new_buf(4 + 2 * data.length); }
o.write_shift(4, data.length); o.write_shift(4, data.length);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3833,7 +3838,7 @@ function parse_StrRun(data) {
return { ich: data.read_shift(2), ifnt: data.read_shift(2) }; return { ich: data.read_shift(2), ifnt: data.read_shift(2) };
} }
function write_StrRun(run, o) { function write_StrRun(run, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(2, run.ich || 0); o.write_shift(2, run.ich || 0);
o.write_shift(2, run.ifnt || 0); o.write_shift(2, run.ifnt || 0);
return o; return o;
@ -3846,13 +3851,13 @@ function parse_RichStr(data, length) {
var str = parse_XLWideString(data); var str = parse_XLWideString(data);
var rgsStrRun = []; var rgsStrRun = [];
var z = ({ t: str, h: str }); var z = ({ t: str, h: str });
if((flags & 1) !== 0) { /* fRichStr */ if ((flags & 1) !== 0) { /* fRichStr */
/* TODO: formatted string */ /* TODO: formatted string */
var dwSizeStrRun = data.read_shift(4); var dwSizeStrRun = data.read_shift(4);
for(var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data)); for (var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data));
z.r = rgsStrRun; z.r = rgsStrRun;
} }
else z.r = [{ich:0, ifnt:0}]; else z.r = [{ ich: 0, ifnt: 0 }];
//if((flags & 2) !== 0) { /* fExtStr */ //if((flags & 2) !== 0) { /* fExtStr */
// /* TODO: phonetic string */ // /* TODO: phonetic string */
//} //}
@ -3861,8 +3866,8 @@ function parse_RichStr(data, length) {
} }
function write_RichStr(str, o) { function write_RichStr(str, o) {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(15+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(15 + 4 * str.t.length); }
o.write_shift(1,0); o.write_shift(1, 0);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3870,11 +3875,11 @@ function write_RichStr(str, o) {
var parse_BrtCommentText = parse_RichStr; var parse_BrtCommentText = parse_RichStr;
function write_BrtCommentText(str, o) { function write_BrtCommentText(str, o) {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(23+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(23 + 4 * str.t.length); }
o.write_shift(1,1); o.write_shift(1, 1);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
o.write_shift(4,1); o.write_shift(4, 1);
write_StrRun({ich:0,ifnt:0}, o); write_StrRun({ ich: 0, ifnt: 0 }, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3882,12 +3887,12 @@ function write_BrtCommentText(str, o) {
function parse_XLSBCell(data) { function parse_XLSBCell(data) {
var col = data.read_shift(4); var col = data.read_shift(4);
var iStyleRef = data.read_shift(2); var iStyleRef = data.read_shift(2);
iStyleRef += data.read_shift(1) <<16; iStyleRef += data.read_shift(1) << 16;
data.l++; //var fPhShow = data.read_shift(1); data.l++; //var fPhShow = data.read_shift(1);
return { c:col, iStyleRef: iStyleRef }; return { c: col, iStyleRef: iStyleRef };
} }
function write_XLSBCell(cell, o) { function write_XLSBCell(cell, o) {
if(o == null) o = new_buf(8); if (o == null) o = new_buf(8);
o.write_shift(-4, cell.c); o.write_shift(-4, cell.c);
o.write_shift(3, cell.iStyleRef || cell.s); o.write_shift(3, cell.iStyleRef || cell.s);
o.write_shift(1, 0); /* fPhShow */ o.write_shift(1, 0); /* fPhShow */
@ -3905,9 +3910,9 @@ function parse_XLNullableWideString(data) {
return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLNullableWideString(data, o) { function write_XLNullableWideString(data, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(127); } var _null = false; if (o == null) { _null = true; o = new_buf(127); }
o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF); o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3922,26 +3927,26 @@ var write_RelID = write_XLNullableWideString;
/* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */ /* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */
function parse_RkNumber(data) { function parse_RkNumber(data) {
var b = data.slice(data.l, data.l+4); var b = data.slice(data.l, data.l + 4);
var fX100 = (b[0] & 1), fInt = (b[0] & 2); var fX100 = (b[0] & 1), fInt = (b[0] & 2);
data.l+=4; data.l += 4;
b[0] &= 0xFC; // b[0] &= ~3; b[0] &= 0xFC; // b[0] &= ~3;
var RK = fInt === 0 ? __double([0,0,0,0,b[0],b[1],b[2],b[3]],0) : __readInt32LE(b,0)>>2; var RK = fInt === 0 ? __double([0, 0, 0, 0, b[0], b[1], b[2], b[3]], 0) : __readInt32LE(b, 0) >> 2;
return fX100 ? (RK/100) : RK; return fX100 ? (RK / 100) : RK;
} }
function write_RkNumber(data, o) { function write_RkNumber(data, o) {
if(o == null) o = new_buf(4); if (o == null) o = new_buf(4);
var fX100 = 0, fInt = 0, d100 = data * 100; var fX100 = 0, fInt = 0, d100 = data * 100;
if((data == (data | 0)) && (data >= -(1<<29)) && (data < (1 << 29))) { fInt = 1; } if ((data == (data | 0)) && (data >= -(1 << 29)) && (data < (1 << 29))) { fInt = 1; }
else if((d100 == (d100 | 0)) && (d100 >= -(1<<29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; } else if ((d100 == (d100 | 0)) && (d100 >= -(1 << 29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; }
if(fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2)); if (fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2));
else throw new Error("unsupported RkNumber " + data); // TODO else throw new Error("unsupported RkNumber " + data); // TODO
} }
/* [MS-XLSB] 2.5.117 RfX */ /* [MS-XLSB] 2.5.117 RfX */
function parse_RfX(data ) { function parse_RfX(data ) {
var cell = ({s: {}, e: {}}); var cell = ({ s: {}, e: {} });
cell.s.r = data.read_shift(4); cell.s.r = data.read_shift(4);
cell.e.r = data.read_shift(4); cell.e.r = data.read_shift(4);
cell.s.c = data.read_shift(4); cell.s.c = data.read_shift(4);
@ -3949,7 +3954,7 @@ function parse_RfX(data ) {
return cell; return cell;
} }
function write_RfX(r, o) { function write_RfX(r, o) {
if(!o) o = new_buf(16); if (!o) o = new_buf(16);
o.write_shift(4, r.s.r); o.write_shift(4, r.s.r);
o.write_shift(4, r.e.r); o.write_shift(4, r.e.r);
o.write_shift(4, r.s.c); o.write_shift(4, r.s.c);
@ -3986,20 +3991,6 @@ var write_UncheckedRfX = write_RfX;
function parse_Xnum(data) { return data.read_shift(8, 'f'); } function parse_Xnum(data) { return data.read_shift(8, 'f'); }
function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); } function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); }
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA",
0xFF: "#WTF?"
};
var RBErr = evert_num(BErr);
/* [MS-XLSB] 2.4.324 BrtColor */ /* [MS-XLSB] 2.4.324 BrtColor */
function parse_BrtColor(data) { function parse_BrtColor(data) {
var out = {}; var out = {};
@ -4015,13 +4006,13 @@ function parse_BrtColor(data) {
var bB = data.read_shift(1); var bB = data.read_shift(1);
data.l++; //var bAlpha = data.read_shift(1); data.l++; //var bAlpha = data.read_shift(1);
switch(xColorType) { switch (xColorType) {
case 0: out.auto = 1; break; case 0: out.auto = 1; break;
case 1: case 1:
out.index = index; out.index = index;
var icv = XLSIcv[index]; var icv = XLSIcv[index];
/* automatic pseudo index 81 */ /* automatic pseudo index 81 */
if(icv) out.rgb = rgb2Hex(icv); if (icv) out.rgb = rgb2Hex(icv);
break; break;
case 2: case 2:
/* if(!fValidRGB) throw new Error("invalid"); */ /* if(!fValidRGB) throw new Error("invalid"); */
@ -4029,17 +4020,17 @@ function parse_BrtColor(data) {
break; break;
case 3: out.theme = index; break; case 3: out.theme = index; break;
} }
if(nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768; if (nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768;
return out; return out;
} }
function write_BrtColor(color, o) { function write_BrtColor(color, o) {
if(!o) o = new_buf(8); if (!o) o = new_buf(8);
if(!color||color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; } if (!color || color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; }
if(color.index != null) { if (color.index != null) {
o.write_shift(1, 0x02); o.write_shift(1, 0x02);
o.write_shift(1, color.index); o.write_shift(1, color.index);
} else if(color.theme != null) { } else if (color.theme != null) {
o.write_shift(1, 0x06); o.write_shift(1, 0x06);
o.write_shift(1, color.theme); o.write_shift(1, color.theme);
} else { } else {
@ -4047,19 +4038,19 @@ function write_BrtColor(color, o) {
o.write_shift(1, 0); o.write_shift(1, 0);
} }
var nTS = color.tint || 0; var nTS = color.tint || 0;
if(nTS > 0) nTS *= 32767; if (nTS > 0) nTS *= 32767;
else if(nTS < 0) nTS *= 32768; else if (nTS < 0) nTS *= 32768;
o.write_shift(2, nTS); o.write_shift(2, nTS);
if(!color.rgb || color.theme != null) { if (!color.rgb || color.theme != null) {
o.write_shift(2, 0); o.write_shift(2, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
} else { } else {
var rgb = (color.rgb || 'FFFFFF'); var rgb = (color.rgb || 'FFFFFF');
if(typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6); if (typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6);
o.write_shift(1, parseInt(rgb.slice(0,2),16)); o.write_shift(1, parseInt(rgb.slice(0, 2), 16));
o.write_shift(1, parseInt(rgb.slice(2,4),16)); o.write_shift(1, parseInt(rgb.slice(2, 4), 16));
o.write_shift(1, parseInt(rgb.slice(4,6),16)); o.write_shift(1, parseInt(rgb.slice(4, 6), 16));
o.write_shift(1, 0xFF); o.write_shift(1, 0xFF);
} }
return o; return o;
@ -4082,14 +4073,14 @@ function parse_FontFlags(data) {
return out; return out;
} }
function write_FontFlags(font, o) { function write_FontFlags(font, o) {
if(!o) o = new_buf(2); if (!o) o = new_buf(2);
var grbit = var grbit =
(font.italic ? 0x02 : 0) | (font.italic ? 0x02 : 0) |
(font.strike ? 0x08 : 0) | (font.strike ? 0x08 : 0) |
(font.outline ? 0x10 : 0) | (font.outline ? 0x10 : 0) |
(font.shadow ? 0x20 : 0) | (font.shadow ? 0x20 : 0) |
(font.condense ? 0x40 : 0) | (font.condense ? 0x40 : 0) |
(font.extend ? 0x80 : 0); (font.extend ? 0x80 : 0);
o.write_shift(1, grbit); o.write_shift(1, grbit);
o.write_shift(1, 0); o.write_shift(1, 0);
return o; return o;
@ -4098,13 +4089,13 @@ function write_FontFlags(font, o) {
/* [MS-OLEDS] 2.3.1 and 2.3.2 */ /* [MS-OLEDS] 2.3.1 and 2.3.2 */
function parse_ClipboardFormatOrString(o, w) { function parse_ClipboardFormatOrString(o, w) {
// $FlowIgnore // $FlowIgnore
var ClipFmt = {2:"BITMAP",3:"METAFILEPICT",8:"DIB",14:"ENHMETAFILE"}; var ClipFmt = { 2: "BITMAP", 3: "METAFILEPICT", 8: "DIB", 14: "ENHMETAFILE" };
var m = o.read_shift(4); var m = o.read_shift(4);
switch(m) { switch (m) {
case 0x00000000: return ""; case 0x00000000: return "";
case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)]||""; case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)] || "";
} }
if(m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16)); if (m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16));
o.l -= 4; o.l -= 4;
return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr"); return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr");
} }
@ -4114,43 +4105,43 @@ function parse_ClipboardFormatOrUnicodeString(o) { return parse_ClipboardFormatO
/* [MS-OLEPS] 2.2 PropertyType */ /* [MS-OLEPS] 2.2 PropertyType */
//var VT_EMPTY = 0x0000; //var VT_EMPTY = 0x0000;
//var VT_NULL = 0x0001; //var VT_NULL = 0x0001;
var VT_I2 = 0x0002; var VT_I2 = 0x0002;
var VT_I4 = 0x0003; var VT_I4 = 0x0003;
//var VT_R4 = 0x0004; //var VT_R4 = 0x0004;
//var VT_R8 = 0x0005; //var VT_R8 = 0x0005;
//var VT_CY = 0x0006; //var VT_CY = 0x0006;
//var VT_DATE = 0x0007; //var VT_DATE = 0x0007;
//var VT_BSTR = 0x0008; //var VT_BSTR = 0x0008;
//var VT_ERROR = 0x000A; //var VT_ERROR = 0x000A;
var VT_BOOL = 0x000B; var VT_BOOL = 0x000B;
var VT_VARIANT = 0x000C; var VT_VARIANT = 0x000C;
//var VT_DECIMAL = 0x000E; //var VT_DECIMAL = 0x000E;
//var VT_I1 = 0x0010; //var VT_I1 = 0x0010;
//var VT_UI1 = 0x0011; //var VT_UI1 = 0x0011;
//var VT_UI2 = 0x0012; //var VT_UI2 = 0x0012;
var VT_UI4 = 0x0013; var VT_UI4 = 0x0013;
//var VT_I8 = 0x0014; //var VT_I8 = 0x0014;
//var VT_UI8 = 0x0015; //var VT_UI8 = 0x0015;
//var VT_INT = 0x0016; //var VT_INT = 0x0016;
//var VT_UINT = 0x0017; //var VT_UINT = 0x0017;
var VT_LPSTR = 0x001E; var VT_LPSTR = 0x001E;
//var VT_LPWSTR = 0x001F; //var VT_LPWSTR = 0x001F;
var VT_FILETIME = 0x0040; var VT_FILETIME = 0x0040;
var VT_BLOB = 0x0041; var VT_BLOB = 0x0041;
//var VT_STREAM = 0x0042; //var VT_STREAM = 0x0042;
//var VT_STORAGE = 0x0043; //var VT_STORAGE = 0x0043;
//var VT_STREAMED_Object = 0x0044; //var VT_STREAMED_Object = 0x0044;
//var VT_STORED_Object = 0x0045; //var VT_STORED_Object = 0x0045;
//var VT_BLOB_Object = 0x0046; //var VT_BLOB_Object = 0x0046;
var VT_CF = 0x0047; var VT_CF = 0x0047;
//var VT_CLSID = 0x0048; //var VT_CLSID = 0x0048;
//var VT_VERSIONED_STREAM = 0x0049; //var VT_VERSIONED_STREAM = 0x0049;
var VT_VECTOR = 0x1000; var VT_VECTOR = 0x1000;
//var VT_ARRAY = 0x2000; //var VT_ARRAY = 0x2000;
var VT_STRING = 0x0050; // 2.3.3.1.11 VtString var VT_STRING = 0x0050; // 2.3.3.1.11 VtString
var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString
var VT_CUSTOM = [VT_STRING, VT_USTR]; var VT_CUSTOM = [VT_STRING, VT_USTR];
/* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */ /* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */
var DocSummaryPIDDSI = { var DocSummaryPIDDSI = {
@ -4213,9 +4204,9 @@ var SpecialProperties = {
0x72627262: {} 0x72627262: {}
}; };
(function() { (function () {
for(var y in SpecialProperties) if(Object.prototype.hasOwnProperty.call(SpecialProperties, y)) for (var y in SpecialProperties) if (Object.prototype.hasOwnProperty.call(SpecialProperties, y))
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y]; DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})(); })();
var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n"); var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n");
@ -4298,7 +4289,7 @@ var XLSFillPattern = [
'gray0625' 'gray0625'
]; ];
function rgbify(arr) { return arr.map(function(x) { return [(x>>16)&255,(x>>8)&255,x&255]; }); } function rgbify(arr) { return arr.map(function (x) { return [(x >> 16) & 255, (x >> 8) & 255, x & 255]; }); }
/* [MS-XLS] 2.5.161 */ /* [MS-XLS] 2.5.161 */
/* [MS-XLSB] 2.5.75 Icv */ /* [MS-XLSB] 2.5.75 Icv */
@ -4395,7 +4386,20 @@ var _XLSIcv = rgbify([
0x000000 /* 0x51 icvInfoText ?? */ 0x000000 /* 0x51 icvInfoText ?? */
]); ]);
var XLSIcv = dup(_XLSIcv); var XLSIcv = dup(_XLSIcv);
/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA",
0xFF: "#WTF?"
};
var RBErr = evert_num(BErr);/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* 12.3 Part Summary <SpreadsheetML> */ /* 12.3 Part Summary <SpreadsheetML> */
/* 14.2 Part Summary <DrawingML> */ /* 14.2 Part Summary <DrawingML> */
/* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */ /* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */
@ -11280,7 +11284,7 @@ var PtgBinOp = {
}; };
// List of invalid characters needs to be tested further // List of invalid characters needs to be tested further
var quoteCharacters = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) var quoteCharacters = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/);
function formula_quote_sheet_name(sname, opts) { function formula_quote_sheet_name(sname, opts) {
if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name");
if (quoteCharacters.test(sname)) return "'" + sname + "'"; if (quoteCharacters.test(sname)) return "'" + sname + "'";
@ -15037,7 +15041,7 @@ function parse_wb_xml(data, opts) {
default: wb.WBProps[w[0]] = y[w[0]]; default: wb.WBProps[w[0]] = y[w[0]];
} }
}); });
if(y.codeName) wb.WBProps.CodeName = y.codeName; if(y.codeName) wb.WBProps.CodeName = utf8read(y.codeName);
break; break;
case '</workbookPr>': break; case '</workbookPr>': break;
@ -19555,16 +19559,32 @@ var HTML_ = (function() {
}; };
})(); })();
function parse_dom_table(table, _opts) { function sheet_add_dom(ws, table, _opts) {
var opts = _opts || {}; var opts = _opts || {};
if(DENSE != null) opts.dense = DENSE; if(DENSE != null) opts.dense = DENSE;
var ws = opts.dense ? ([]) : ({}); var or_R = 0, or_C = 0;
if(opts.origin != null) {
if(typeof opts.origin == 'number') or_R = opts.origin;
else {
var _origin = typeof opts.origin == "string" ? decode_cell(opts.origin) : opts.origin;
or_R = _origin.r; or_C = _origin.c;
}
}
var rows = table.getElementsByTagName('tr'); var rows = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000; var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range = {s:{r:0,c:0},e:{r:0,c:0}}; var range = {s:{r:0,c:0},e:{r:or_R,c:or_C}};
if(ws["!ref"]) {
var _range = decode_range(ws["!ref"]);
range.s.r = Math.min(range.s.r, _range.s.r);
range.s.c = Math.min(range.s.c, _range.s.c);
range.e.r = Math.max(range.e.r, _range.e.r);
range.e.c = Math.max(range.e.c, _range.e.c);
if(or_R == -1) range.e.r = or_R = _range.e.r + 1;
}
var merges = [], midx = 0; var merges = [], midx = 0;
var rowinfo = []; var rowinfo = ws["!rows"] || (ws["!rows"] = []);
var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0; var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0;
if(!ws["!cols"]) ws['!cols'] = [];
for(; _R < rows.length && R < sheetRows; ++_R) { for(; _R < rows.length && R < sheetRows; ++_R) {
var row = rows[_R]; var row = rows[_R];
if (is_dom_element_hidden(row)) { if (is_dom_element_hidden(row)) {
@ -19579,11 +19599,11 @@ function parse_dom_table(table, _opts) {
var z = elt.getAttribute('z'); var z = elt.getAttribute('z');
for(midx = 0; midx < merges.length; ++midx) { for(midx = 0; midx < merges.length; ++midx) {
var m = merges[midx]; var m = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } if(m.s.c == C + or_C && m.s.r < R + or_R && R + or_R <= m.e.r) { C = m.e.c+1 - or_C; midx = -1; }
} }
/* TODO: figure out how to extract nonstandard mso- style */ /* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1; CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); if( ((RS = (+elt.getAttribute("rowspan") || 1)))>1 || CS>1) merges.push({s:{r:R + or_R,c:C + or_C},e:{r:R + or_R + (RS||1) - 1, c:C + or_C + (CS||1) - 1}});
var o = {t:'s', v:v}; var o = {t:'s', v:v};
var _t = elt.getAttribute("t") || ""; var _t = elt.getAttribute("t") || "";
if(v != null) { if(v != null) {
@ -19599,21 +19619,26 @@ function parse_dom_table(table, _opts) {
} }
} }
if(o.z === undefined && z != null) o.z = z; if(o.z === undefined && z != null) o.z = z;
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} if(opts.dense) { if(!ws[R + or_R]) ws[R + or_R] = []; ws[R + or_R][C + or_C] = o; }
else ws[encode_cell({c:C, r:R})] = o; else ws[encode_cell({c:C + or_C, r:R + or_R})] = o;
if(range.e.c < C) range.e.c = C; if(range.e.c < C + or_C) range.e.c = C + or_C;
C += CS; C += CS;
} }
++R; ++R;
} }
if(merges.length) ws['!merges'] = merges; if(merges.length) ws['!merges'] = (ws["!merges"] || []).concat(merges);
if(rowinfo.length) ws['!rows'] = rowinfo; range.e.r = Math.max(range.e.r, R - 1 + or_R);
range.e.r = R - 1;
ws['!ref'] = encode_range(range); ws['!ref'] = encode_range(range);
if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1,range)); // We can count the real number of rows to parse but we don't to improve the performance if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1 + or_R,range)); // We can count the real number of rows to parse but we don't to improve the performance
return ws; return ws;
} }
function parse_dom_table(table, _opts) {
var opts = _opts || {};
var ws = opts.dense ? ([]) : ({});
return sheet_add_dom(ws, table, _opts);
}
function table_to_book(table, opts) { function table_to_book(table, opts) {
return sheet_to_workbook(parse_dom_table(table, opts), opts); return sheet_to_workbook(parse_dom_table(table, opts), opts);
} }
@ -21302,6 +21327,7 @@ function sheet_to_formulae(sheet) {
} }
function sheet_add_json(_ws, js, opts) { function sheet_add_json(_ws, js, opts) {
if(!js.length) return _ws;
var o = opts || {}; var o = opts || {};
var offset = +!o.skipHeader; var offset = +!o.skipHeader;
var ws = _ws || ({}); var ws = _ws || ({});
@ -21320,6 +21346,8 @@ function sheet_add_json(_ws, js, opts) {
range.e.c = Math.max(range.e.c, _range.e.c); range.e.c = Math.max(range.e.c, _range.e.c);
range.e.r = Math.max(range.e.r, _range.e.r); range.e.r = Math.max(range.e.r, _range.e.r);
if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; } if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; }
} else {
if(_R == -1) { _R = 0; range.e.r = js.length - 1 + offset; }
} }
var hdr = o.header || [], C = 0; var hdr = o.header || [], C = 0;
@ -21377,6 +21405,7 @@ var utils = {
make_formulae: sheet_to_formulae, make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa, sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json, sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
aoa_to_sheet: aoa_to_sheet, aoa_to_sheet: aoa_to_sheet,
json_to_sheet: json_to_sheet, json_to_sheet: json_to_sheet,
table_to_sheet: parse_dom_table, table_to_sheet: parse_dom_table,

28
dist/xlsx.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.min.map generated vendored

File diff suppressed because one or more lines are too long

14
dist/xlsx.mini.min.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/xlsx.mini.min.map generated vendored

File diff suppressed because one or more lines are too long

@ -242,6 +242,56 @@ var wb = XLSX.utils.table_to_book(tbl);
Note: `XLSX.read` can handle HTML represented as strings. Note: `XLSX.read` can handle HTML represented as strings.
`XLSX.utils.sheet_add_dom` takes a table DOM element and updates an existing
worksheet object. It follows the same process as `table_to_sheet` and accepts
an options argument:
| Option Name | Default | Description |
| :---------- | :------: | :-------------------------------------------------- |
|`raw` | | If true, every cell will hold raw strings |
|`dateNF` | FMT 14 | Use specified date format in string output |
|`cellDates` | false | Store dates as type `d` (default is `n`) |
|`sheetRows` | 0 | If >0, read the first `sheetRows` rows of the table |
|`display` | false | If true, hidden rows and cells will not be parsed |
`origin` is expected to be one of:
| `origin` | Description |
| :--------------- | :-------------------------------------------------------- |
| (cell object) | Use specified cell (cell object) |
| (string) | Use specified cell (A1-style cell) |
| (number >= 0) | Start from the first column at specified row (0-indexed) |
| -1 | Append to bottom of worksheet starting on first column |
| (default) | Start from cell A1 |
<details>
<summary><b>Examples</b> (click to show)</summary>
A small helper function can create gap rows between tables:
```js
function create_gap_rows(ws, nrows) {
var ref = XLSX.utils.decode_range(ws["!ref"]); // get original range
ref.e.r += nrows; // add to ending row
ws["!ref"] = XLSX.utils.encode_range(ref); // reassign row
}
/* first table */
var ws = XLSX.utils.table_to_sheet(document.getElementById('table1'));
create_gap_rows(ws, 1); // one row gap after first table
/* second table */
XLSX.utils.sheet_add_dom(ws, document.getElementById('table2'), {origin: -1});
create_gap_rows(ws, 3); // three rows gap after second table
/* third table */
XLSX.utils.sheet_add_dom(ws, document.getElementById('table3'), {origin: -1});
```
</details>
### Formulae Output ### Formulae Output
`XLSX.utils.sheet_to_formulae` generates an array of commands that represent `XLSX.utils.sheet_to_formulae` generates an array of commands that represent

@ -1951,6 +1951,53 @@ var wb = XLSX.utils.table_to_book(tbl);
Note: `XLSX.read` can handle HTML represented as strings. Note: `XLSX.read` can handle HTML represented as strings.
`XLSX.utils.sheet_add_dom` takes a table DOM element and updates an existing
worksheet object. It follows the same process as `table_to_sheet` and accepts
an options argument:
| Option Name | Default | Description |
| :---------- | :------: | :-------------------------------------------------- |
|`raw` | | If true, every cell will hold raw strings |
|`dateNF` | FMT 14 | Use specified date format in string output |
|`cellDates` | false | Store dates as type `d` (default is `n`) |
|`sheetRows` | 0 | If >0, read the first `sheetRows` rows of the table |
|`display` | false | If true, hidden rows and cells will not be parsed |
`origin` is expected to be one of:
| `origin` | Description |
| :--------------- | :-------------------------------------------------------- |
| (cell object) | Use specified cell (cell object) |
| (string) | Use specified cell (A1-style cell) |
| (number >= 0) | Start from the first column at specified row (0-indexed) |
| -1 | Append to bottom of worksheet starting on first column |
| (default) | Start from cell A1 |
A small helper function can create gap rows between tables:
```js
function create_gap_rows(ws, nrows) {
var ref = XLSX.utils.decode_range(ws["!ref"]); // get original range
ref.e.r += nrows; // add to ending row
ws["!ref"] = XLSX.utils.encode_range(ref); // reassign row
}
/* first table */
var ws = XLSX.utils.table_to_sheet(document.getElementById('table1'));
create_gap_rows(ws, 1); // one row gap after first table
/* second table */
XLSX.utils.sheet_add_dom(ws, document.getElementById('table2'), {origin: -1});
create_gap_rows(ws, 3); // three rows gap after second table
/* third table */
XLSX.utils.sheet_add_dom(ws, document.getElementById('table3'), {origin: -1});
```
### Formulae Output ### Formulae Output
`XLSX.utils.sheet_to_formulae` generates an array of commands that represent `XLSX.utils.sheet_to_formulae` generates an array of commands that represent

@ -1,6 +1,6 @@
{ {
"name": "xlsx", "name": "xlsx",
"version": "0.16.4", "version": "0.16.5",
"author": "sheetjs", "author": "sheetjs",
"description": "SheetJS Spreadsheet data parser and writer", "description": "SheetJS Spreadsheet data parser and writer",
"keywords": [ "keywords": [

24
test.js

@ -2182,7 +2182,7 @@ describe('HTML', function() {
var html = "<table><tr style='display: none;'><td>1</td><td>2</td><td>3</td></tr><tr><td class='hidden'>Foo</td><td>Bar</td><td style='display: none;'>Baz</td></tr></table><style>.hidden {display: none}</style>"; var html = "<table><tr style='display: none;'><td>1</td><td>2</td><td>3</td></tr><tr><td class='hidden'>Foo</td><td>Bar</td><td style='display: none;'>Baz</td></tr></table><style>.hidden {display: none}</style>";
var ws = X.utils.table_to_sheet(get_dom_element(html), {display: true}); var ws = X.utils.table_to_sheet(get_dom_element(html), {display: true});
assert.equal(ws['!ref'], "A1"); assert.equal(ws['!ref'], "A1");
assert.equal(ws.hasOwnProperty('!rows'), false); assert(ws.hasOwnProperty('!rows') == false || !ws["!rows"][0] || !ws["!rows"][0].hidden);
assert.equal(get_cell(ws, "A1").v, "Bar"); assert.equal(get_cell(ws, "A1").v, "Bar");
}); });
describe('type override', function() { describe('type override', function() {
@ -2321,17 +2321,17 @@ describe('corner cases', function() {
}); });
it("should quote unicode sheet names in formulae", function() { it("should quote unicode sheet names in formulae", function() {
var wb = X.read(fs.readFileSync(dir + "cross-sheet_formula_names.xlsb"), {WTF:1, type:TYPE}); var wb = X.read(fs.readFileSync(dir + "cross-sheet_formula_names.xlsb"), {WTF:1, type:TYPE});
assert.equal(wb.Sheets["Sheet1"]["A1"].f, "'a-b'!A1"); assert.equal(wb.Sheets.Sheet1.A1.f, "'a-b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A2"].f, "'a#b'!A1"); assert.equal(wb.Sheets.Sheet1.A2.f, "'a#b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A3"].f, "'a^b'!A1"); assert.equal(wb.Sheets.Sheet1.A3.f, "'a^b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A4"].f, "'a%b'!A1"); assert.equal(wb.Sheets.Sheet1.A4.f, "'a%b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A5"].f, "'a\u066ab'!A1"); assert.equal(wb.Sheets.Sheet1.A5.f, "'a\u066ab'!A1");
assert.equal(wb.Sheets["Sheet1"]["A6"].f, "'☃️'!A1"); assert.equal(wb.Sheets.Sheet1.A6.f, "'☃️'!A1");
assert.equal(wb.Sheets["Sheet1"]["A7"].f, "'\ud83c\udf63'!A1"); assert.equal(wb.Sheets.Sheet1.A7.f, "'\ud83c\udf63'!A1");
assert.equal(wb.Sheets["Sheet1"]["A8"].f, "'a!!b'!A1"); assert.equal(wb.Sheets.Sheet1.A8.f, "'a!!b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A9"].f, "'a$b'!A1"); assert.equal(wb.Sheets.Sheet1.A9.f, "'a$b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A10"].f, "'a!b'!A1"); assert.equal(wb.Sheets.Sheet1.A10.f, "'a!b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A11"].f, "'a b'!A1"); assert.equal(wb.Sheets.Sheet1.A11.f, "'a b'!A1");
}); });
}); });

24
tests/core.js generated

@ -2182,7 +2182,7 @@ describe('HTML', function() {
var html = "<table><tr style='display: none;'><td>1</td><td>2</td><td>3</td></tr><tr><td class='hidden'>Foo</td><td>Bar</td><td style='display: none;'>Baz</td></tr></table><style>.hidden {display: none}</style>"; var html = "<table><tr style='display: none;'><td>1</td><td>2</td><td>3</td></tr><tr><td class='hidden'>Foo</td><td>Bar</td><td style='display: none;'>Baz</td></tr></table><style>.hidden {display: none}</style>";
var ws = X.utils.table_to_sheet(get_dom_element(html), {display: true}); var ws = X.utils.table_to_sheet(get_dom_element(html), {display: true});
assert.equal(ws['!ref'], "A1"); assert.equal(ws['!ref'], "A1");
assert.equal(ws.hasOwnProperty('!rows'), false); assert(ws.hasOwnProperty('!rows') == false || !ws["!rows"][0] || !ws["!rows"][0].hidden);
assert.equal(get_cell(ws, "A1").v, "Bar"); assert.equal(get_cell(ws, "A1").v, "Bar");
}); });
describe('type override', function() { describe('type override', function() {
@ -2321,17 +2321,17 @@ describe('corner cases', function() {
}); });
it("should quote unicode sheet names in formulae", function() { it("should quote unicode sheet names in formulae", function() {
var wb = X.read(fs.readFileSync(dir + "cross-sheet_formula_names.xlsb"), {WTF:1, type:TYPE}); var wb = X.read(fs.readFileSync(dir + "cross-sheet_formula_names.xlsb"), {WTF:1, type:TYPE});
assert.equal(wb.Sheets["Sheet1"]["A1"].f, "'a-b'!A1"); assert.equal(wb.Sheets.Sheet1.A1.f, "'a-b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A2"].f, "'a#b'!A1"); assert.equal(wb.Sheets.Sheet1.A2.f, "'a#b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A3"].f, "'a^b'!A1"); assert.equal(wb.Sheets.Sheet1.A3.f, "'a^b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A4"].f, "'a%b'!A1"); assert.equal(wb.Sheets.Sheet1.A4.f, "'a%b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A5"].f, "'a\u066ab'!A1"); assert.equal(wb.Sheets.Sheet1.A5.f, "'a\u066ab'!A1");
assert.equal(wb.Sheets["Sheet1"]["A6"].f, "'☃️'!A1"); assert.equal(wb.Sheets.Sheet1.A6.f, "'☃️'!A1");
assert.equal(wb.Sheets["Sheet1"]["A7"].f, "'\ud83c\udf63'!A1"); assert.equal(wb.Sheets.Sheet1.A7.f, "'\ud83c\udf63'!A1");
assert.equal(wb.Sheets["Sheet1"]["A8"].f, "'a!!b'!A1"); assert.equal(wb.Sheets.Sheet1.A8.f, "'a!!b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A9"].f, "'a$b'!A1"); assert.equal(wb.Sheets.Sheet1.A9.f, "'a$b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A10"].f, "'a!b'!A1"); assert.equal(wb.Sheets.Sheet1.A10.f, "'a!b'!A1");
assert.equal(wb.Sheets["Sheet1"]["A11"].f, "'a b'!A1"); assert.equal(wb.Sheets.Sheet1.A11.f, "'a b'!A1");
}); });
}); });

5
types/index.d.ts vendored

@ -193,7 +193,7 @@ export interface ParsingOptions extends CommonOptions {
/** If specified, only parse the specified sheets or sheet names */ /** If specified, only parse the specified sheets or sheet names */
sheets?: number | string | Array<number | string>; sheets?: number | string | Array<number | string>;
/* If true, plaintext parsing will not parse values */ /** If true, plaintext parsing will not parse values */
raw?: boolean; raw?: boolean;
dense?: boolean; dense?: boolean;
@ -694,7 +694,7 @@ export interface JSON2SheetOpts extends CommonOptions, DateNFOption {
export interface SheetJSONOpts extends JSON2SheetOpts, OriginOption {} export interface SheetJSONOpts extends JSON2SheetOpts, OriginOption {}
export interface Table2SheetOpts extends CommonOptions, DateNFOption { export interface Table2SheetOpts extends CommonOptions, DateNFOption {
/* If true, plaintext parsing will not parse values */ /** If true, plaintext parsing will not parse values */
raw?: boolean; raw?: boolean;
/** /**
@ -722,6 +722,7 @@ export interface XLSX$Utils {
/** BROWSER ONLY! Converts a TABLE DOM element to a worksheet. */ /** BROWSER ONLY! Converts a TABLE DOM element to a worksheet. */
table_to_sheet(data: any, opts?: Table2SheetOpts): WorkSheet; table_to_sheet(data: any, opts?: Table2SheetOpts): WorkSheet;
table_to_book(data: any, opts?: Table2SheetOpts): WorkBook; table_to_book(data: any, opts?: Table2SheetOpts): WorkBook;
sheet_add_dom(ws: WorkSheet, data: any, opts?: Table2SheetOpts): WorkSheet;
/* --- Export Functions --- */ /* --- Export Functions --- */

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {}; var XLSX = {};
function make_xlsx_lib(XLSX){ function make_xlsx_lib(XLSX){
XLSX.version = '0.16.4'; XLSX.version = '0.16.5';
var current_codepage = 1200, current_ansi = 1252; var current_codepage = 1200, current_ansi = 1252;
/*:: declare var cptable:any; */ /*:: declare var cptable:any; */
/*global cptable:true, window */ /*global cptable:true, window */
@ -3768,7 +3768,11 @@ function encode_cell(cell/*:CellAddress*/)/*:string*/ {
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
return s + (cell.r + 1); return s + (cell.r + 1);
} }
function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } function decode_range(range/*:string*/)/*:Range*/ {
var idx = range.indexOf(":");
if(idx == -1) return { s: decode_cell(range), e: decode_cell(range) };
return { s: decode_cell(range.slice(0, idx)), e: decode_cell(range.slice(idx + 1)) };
}
/*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */ /*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */
function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ { function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ {
if(typeof ce === 'undefined' || typeof ce === 'number') { if(typeof ce === 'undefined' || typeof ce === 'number') {
@ -3847,6 +3851,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
var _origin/*:CellAddress*/ = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin; var _origin/*:CellAddress*/ = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
_R = _origin.r; _C = _origin.c; _R = _origin.r; _C = _origin.c;
} }
if(!ws["!ref"]) ws["!ref"] = "A1:A1";
} }
var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}/*:any*/); var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}/*:any*/);
if(ws['!ref']) { if(ws['!ref']) {
@ -3898,7 +3903,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
function aoa_to_sheet(data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ { return sheet_add_aoa(null, data, opts); } function aoa_to_sheet(data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ { return sheet_add_aoa(null, data, opts); }
function write_UInt32LE(x/*:number*/, o) { function write_UInt32LE(x/*:number*/, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(4, x); o.write_shift(4, x);
return o; return o;
} }
@ -3909,9 +3914,9 @@ function parse_XLWideString(data/*::, length*/)/*:string*/ {
return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLWideString(data/*:string*/, o) { function write_XLWideString(data/*:string*/, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(4+2*data.length); } var _null = false; if (o == null) { _null = true; o = new_buf(4 + 2 * data.length); }
o.write_shift(4, data.length); o.write_shift(4, data.length);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3926,7 +3931,7 @@ function parse_StrRun(data) {
return { ich: data.read_shift(2), ifnt: data.read_shift(2) }; return { ich: data.read_shift(2), ifnt: data.read_shift(2) };
} }
function write_StrRun(run, o) { function write_StrRun(run, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(2, run.ich || 0); o.write_shift(2, run.ich || 0);
o.write_shift(2, run.ifnt || 0); o.write_shift(2, run.ifnt || 0);
return o; return o;
@ -3939,13 +3944,13 @@ function parse_RichStr(data, length/*:number*/)/*:XLString*/ {
var str = parse_XLWideString(data); var str = parse_XLWideString(data);
var rgsStrRun = []; var rgsStrRun = [];
var z = ({ t: str, h: str }/*:any*/); var z = ({ t: str, h: str }/*:any*/);
if((flags & 1) !== 0) { /* fRichStr */ if ((flags & 1) !== 0) { /* fRichStr */
/* TODO: formatted string */ /* TODO: formatted string */
var dwSizeStrRun = data.read_shift(4); var dwSizeStrRun = data.read_shift(4);
for(var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data)); for (var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data));
z.r = rgsStrRun; z.r = rgsStrRun;
} }
else z.r = [{ich:0, ifnt:0}]; else z.r = [{ ich: 0, ifnt: 0 }];
//if((flags & 2) !== 0) { /* fExtStr */ //if((flags & 2) !== 0) { /* fExtStr */
// /* TODO: phonetic string */ // /* TODO: phonetic string */
//} //}
@ -3954,8 +3959,8 @@ function parse_RichStr(data, length/*:number*/)/*:XLString*/ {
} }
function write_RichStr(str/*:XLString*/, o/*:?Block*/)/*:Block*/ { function write_RichStr(str/*:XLString*/, o/*:?Block*/)/*:Block*/ {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(15+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(15 + 4 * str.t.length); }
o.write_shift(1,0); o.write_shift(1, 0);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3963,11 +3968,11 @@ function write_RichStr(str/*:XLString*/, o/*:?Block*/)/*:Block*/ {
var parse_BrtCommentText = parse_RichStr; var parse_BrtCommentText = parse_RichStr;
function write_BrtCommentText(str/*:XLString*/, o/*:?Block*/)/*:Block*/ { function write_BrtCommentText(str/*:XLString*/, o/*:?Block*/)/*:Block*/ {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(23+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(23 + 4 * str.t.length); }
o.write_shift(1,1); o.write_shift(1, 1);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
o.write_shift(4,1); o.write_shift(4, 1);
write_StrRun({ich:0,ifnt:0}, o); write_StrRun({ ich: 0, ifnt: 0 }, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3975,12 +3980,12 @@ function write_BrtCommentText(str/*:XLString*/, o/*:?Block*/)/*:Block*/ {
function parse_XLSBCell(data)/*:any*/ { function parse_XLSBCell(data)/*:any*/ {
var col = data.read_shift(4); var col = data.read_shift(4);
var iStyleRef = data.read_shift(2); var iStyleRef = data.read_shift(2);
iStyleRef += data.read_shift(1) <<16; iStyleRef += data.read_shift(1) << 16;
data.l++; //var fPhShow = data.read_shift(1); data.l++; //var fPhShow = data.read_shift(1);
return { c:col, iStyleRef: iStyleRef }; return { c: col, iStyleRef: iStyleRef };
} }
function write_XLSBCell(cell/*:any*/, o/*:?Block*/) { function write_XLSBCell(cell/*:any*/, o/*:?Block*/) {
if(o == null) o = new_buf(8); if (o == null) o = new_buf(8);
o.write_shift(-4, cell.c); o.write_shift(-4, cell.c);
o.write_shift(3, cell.iStyleRef || cell.s); o.write_shift(3, cell.iStyleRef || cell.s);
o.write_shift(1, 0); /* fPhShow */ o.write_shift(1, 0); /* fPhShow */
@ -3998,9 +4003,9 @@ function parse_XLNullableWideString(data/*::, length*/)/*:string*/ {
return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLNullableWideString(data/*:string*/, o) { function write_XLNullableWideString(data/*:string*/, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(127); } var _null = false; if (o == null) { _null = true; o = new_buf(127); }
o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF); o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -4015,26 +4020,26 @@ var write_RelID = write_XLNullableWideString;
/* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */ /* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */
function parse_RkNumber(data)/*:number*/ { function parse_RkNumber(data)/*:number*/ {
var b = data.slice(data.l, data.l+4); var b = data.slice(data.l, data.l + 4);
var fX100 = (b[0] & 1), fInt = (b[0] & 2); var fX100 = (b[0] & 1), fInt = (b[0] & 2);
data.l+=4; data.l += 4;
b[0] &= 0xFC; // b[0] &= ~3; b[0] &= 0xFC; // b[0] &= ~3;
var RK = fInt === 0 ? __double([0,0,0,0,b[0],b[1],b[2],b[3]],0) : __readInt32LE(b,0)>>2; var RK = fInt === 0 ? __double([0, 0, 0, 0, b[0], b[1], b[2], b[3]], 0) : __readInt32LE(b, 0) >> 2;
return fX100 ? (RK/100) : RK; return fX100 ? (RK / 100) : RK;
} }
function write_RkNumber(data/*:number*/, o) { function write_RkNumber(data/*:number*/, o) {
if(o == null) o = new_buf(4); if (o == null) o = new_buf(4);
var fX100 = 0, fInt = 0, d100 = data * 100; var fX100 = 0, fInt = 0, d100 = data * 100;
if((data == (data | 0)) && (data >= -(1<<29)) && (data < (1 << 29))) { fInt = 1; } if ((data == (data | 0)) && (data >= -(1 << 29)) && (data < (1 << 29))) { fInt = 1; }
else if((d100 == (d100 | 0)) && (d100 >= -(1<<29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; } else if ((d100 == (d100 | 0)) && (d100 >= -(1 << 29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; }
if(fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2)); if (fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2));
else throw new Error("unsupported RkNumber " + data); // TODO else throw new Error("unsupported RkNumber " + data); // TODO
} }
/* [MS-XLSB] 2.5.117 RfX */ /* [MS-XLSB] 2.5.117 RfX */
function parse_RfX(data /*::, length*/)/*:Range*/ { function parse_RfX(data /*::, length*/)/*:Range*/ {
var cell/*:Range*/ = ({s: {}, e: {}}/*:any*/); var cell/*:Range*/ = ({ s: {}, e: {} }/*:any*/);
cell.s.r = data.read_shift(4); cell.s.r = data.read_shift(4);
cell.e.r = data.read_shift(4); cell.e.r = data.read_shift(4);
cell.s.c = data.read_shift(4); cell.s.c = data.read_shift(4);
@ -4042,7 +4047,7 @@ function parse_RfX(data /*::, length*/)/*:Range*/ {
return cell; return cell;
} }
function write_RfX(r/*:Range*/, o) { function write_RfX(r/*:Range*/, o) {
if(!o) o = new_buf(16); if (!o) o = new_buf(16);
o.write_shift(4, r.s.r); o.write_shift(4, r.s.r);
o.write_shift(4, r.e.r); o.write_shift(4, r.e.r);
o.write_shift(4, r.s.c); o.write_shift(4, r.s.c);
@ -4079,20 +4084,6 @@ var write_UncheckedRfX = write_RfX;
function parse_Xnum(data/*::, length*/) { return data.read_shift(8, 'f'); } function parse_Xnum(data/*::, length*/) { return data.read_shift(8, 'f'); }
function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); } function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); }
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
/*::[*/0x00/*::]*/: "#NULL!",
/*::[*/0x07/*::]*/: "#DIV/0!",
/*::[*/0x0F/*::]*/: "#VALUE!",
/*::[*/0x17/*::]*/: "#REF!",
/*::[*/0x1D/*::]*/: "#NAME?",
/*::[*/0x24/*::]*/: "#NUM!",
/*::[*/0x2A/*::]*/: "#N/A",
/*::[*/0x2B/*::]*/: "#GETTING_DATA",
/*::[*/0xFF/*::]*/: "#WTF?"
};
var RBErr = evert_num(BErr);
/* [MS-XLSB] 2.4.324 BrtColor */ /* [MS-XLSB] 2.4.324 BrtColor */
function parse_BrtColor(data/*::, length*/) { function parse_BrtColor(data/*::, length*/) {
var out = {}; var out = {};
@ -4108,13 +4099,13 @@ function parse_BrtColor(data/*::, length*/) {
var bB = data.read_shift(1); var bB = data.read_shift(1);
data.l++; //var bAlpha = data.read_shift(1); data.l++; //var bAlpha = data.read_shift(1);
switch(xColorType) { switch (xColorType) {
case 0: out.auto = 1; break; case 0: out.auto = 1; break;
case 1: case 1:
out.index = index; out.index = index;
var icv = XLSIcv[index]; var icv = XLSIcv[index];
/* automatic pseudo index 81 */ /* automatic pseudo index 81 */
if(icv) out.rgb = rgb2Hex(icv); if (icv) out.rgb = rgb2Hex(icv);
break; break;
case 2: case 2:
/* if(!fValidRGB) throw new Error("invalid"); */ /* if(!fValidRGB) throw new Error("invalid"); */
@ -4122,17 +4113,17 @@ function parse_BrtColor(data/*::, length*/) {
break; break;
case 3: out.theme = index; break; case 3: out.theme = index; break;
} }
if(nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768; if (nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768;
return out; return out;
} }
function write_BrtColor(color, o) { function write_BrtColor(color, o) {
if(!o) o = new_buf(8); if (!o) o = new_buf(8);
if(!color||color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; } if (!color || color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; }
if(color.index != null) { if (color.index != null) {
o.write_shift(1, 0x02); o.write_shift(1, 0x02);
o.write_shift(1, color.index); o.write_shift(1, color.index);
} else if(color.theme != null) { } else if (color.theme != null) {
o.write_shift(1, 0x06); o.write_shift(1, 0x06);
o.write_shift(1, color.theme); o.write_shift(1, color.theme);
} else { } else {
@ -4140,19 +4131,19 @@ function write_BrtColor(color, o) {
o.write_shift(1, 0); o.write_shift(1, 0);
} }
var nTS = color.tint || 0; var nTS = color.tint || 0;
if(nTS > 0) nTS *= 32767; if (nTS > 0) nTS *= 32767;
else if(nTS < 0) nTS *= 32768; else if (nTS < 0) nTS *= 32768;
o.write_shift(2, nTS); o.write_shift(2, nTS);
if(!color.rgb || color.theme != null) { if (!color.rgb || color.theme != null) {
o.write_shift(2, 0); o.write_shift(2, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
} else { } else {
var rgb = (color.rgb || 'FFFFFF'); var rgb = (color.rgb || 'FFFFFF');
if(typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6); if (typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6);
o.write_shift(1, parseInt(rgb.slice(0,2),16)); o.write_shift(1, parseInt(rgb.slice(0, 2), 16));
o.write_shift(1, parseInt(rgb.slice(2,4),16)); o.write_shift(1, parseInt(rgb.slice(2, 4), 16));
o.write_shift(1, parseInt(rgb.slice(4,6),16)); o.write_shift(1, parseInt(rgb.slice(4, 6), 16));
o.write_shift(1, 0xFF); o.write_shift(1, 0xFF);
} }
return o; return o;
@ -4175,14 +4166,14 @@ function parse_FontFlags(data/*::, length, opts*/) {
return out; return out;
} }
function write_FontFlags(font, o) { function write_FontFlags(font, o) {
if(!o) o = new_buf(2); if (!o) o = new_buf(2);
var grbit = var grbit =
(font.italic ? 0x02 : 0) | (font.italic ? 0x02 : 0) |
(font.strike ? 0x08 : 0) | (font.strike ? 0x08 : 0) |
(font.outline ? 0x10 : 0) | (font.outline ? 0x10 : 0) |
(font.shadow ? 0x20 : 0) | (font.shadow ? 0x20 : 0) |
(font.condense ? 0x40 : 0) | (font.condense ? 0x40 : 0) |
(font.extend ? 0x80 : 0); (font.extend ? 0x80 : 0);
o.write_shift(1, grbit); o.write_shift(1, grbit);
o.write_shift(1, 0); o.write_shift(1, 0);
return o; return o;
@ -4191,13 +4182,13 @@ function write_FontFlags(font, o) {
/* [MS-OLEDS] 2.3.1 and 2.3.2 */ /* [MS-OLEDS] 2.3.1 and 2.3.2 */
function parse_ClipboardFormatOrString(o, w/*:number*/)/*:string*/ { function parse_ClipboardFormatOrString(o, w/*:number*/)/*:string*/ {
// $FlowIgnore // $FlowIgnore
var ClipFmt = {2:"BITMAP",3:"METAFILEPICT",8:"DIB",14:"ENHMETAFILE"}; var ClipFmt = { 2: "BITMAP", 3: "METAFILEPICT", 8: "DIB", 14: "ENHMETAFILE" };
var m/*:number*/ = o.read_shift(4); var m/*:number*/ = o.read_shift(4);
switch(m) { switch (m) {
case 0x00000000: return ""; case 0x00000000: return "";
case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)]||""; case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)] || "";
} }
if(m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16)); if (m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16));
o.l -= 4; o.l -= 4;
return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr"); return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr");
} }
@ -4207,43 +4198,43 @@ function parse_ClipboardFormatOrUnicodeString(o) { return parse_ClipboardFormatO
/* [MS-OLEPS] 2.2 PropertyType */ /* [MS-OLEPS] 2.2 PropertyType */
//var VT_EMPTY = 0x0000; //var VT_EMPTY = 0x0000;
//var VT_NULL = 0x0001; //var VT_NULL = 0x0001;
var VT_I2 = 0x0002; var VT_I2 = 0x0002;
var VT_I4 = 0x0003; var VT_I4 = 0x0003;
//var VT_R4 = 0x0004; //var VT_R4 = 0x0004;
//var VT_R8 = 0x0005; //var VT_R8 = 0x0005;
//var VT_CY = 0x0006; //var VT_CY = 0x0006;
//var VT_DATE = 0x0007; //var VT_DATE = 0x0007;
//var VT_BSTR = 0x0008; //var VT_BSTR = 0x0008;
//var VT_ERROR = 0x000A; //var VT_ERROR = 0x000A;
var VT_BOOL = 0x000B; var VT_BOOL = 0x000B;
var VT_VARIANT = 0x000C; var VT_VARIANT = 0x000C;
//var VT_DECIMAL = 0x000E; //var VT_DECIMAL = 0x000E;
//var VT_I1 = 0x0010; //var VT_I1 = 0x0010;
//var VT_UI1 = 0x0011; //var VT_UI1 = 0x0011;
//var VT_UI2 = 0x0012; //var VT_UI2 = 0x0012;
var VT_UI4 = 0x0013; var VT_UI4 = 0x0013;
//var VT_I8 = 0x0014; //var VT_I8 = 0x0014;
//var VT_UI8 = 0x0015; //var VT_UI8 = 0x0015;
//var VT_INT = 0x0016; //var VT_INT = 0x0016;
//var VT_UINT = 0x0017; //var VT_UINT = 0x0017;
var VT_LPSTR = 0x001E; var VT_LPSTR = 0x001E;
//var VT_LPWSTR = 0x001F; //var VT_LPWSTR = 0x001F;
var VT_FILETIME = 0x0040; var VT_FILETIME = 0x0040;
var VT_BLOB = 0x0041; var VT_BLOB = 0x0041;
//var VT_STREAM = 0x0042; //var VT_STREAM = 0x0042;
//var VT_STORAGE = 0x0043; //var VT_STORAGE = 0x0043;
//var VT_STREAMED_Object = 0x0044; //var VT_STREAMED_Object = 0x0044;
//var VT_STORED_Object = 0x0045; //var VT_STORED_Object = 0x0045;
//var VT_BLOB_Object = 0x0046; //var VT_BLOB_Object = 0x0046;
var VT_CF = 0x0047; var VT_CF = 0x0047;
//var VT_CLSID = 0x0048; //var VT_CLSID = 0x0048;
//var VT_VERSIONED_STREAM = 0x0049; //var VT_VERSIONED_STREAM = 0x0049;
var VT_VECTOR = 0x1000; var VT_VECTOR = 0x1000;
//var VT_ARRAY = 0x2000; //var VT_ARRAY = 0x2000;
var VT_STRING = 0x0050; // 2.3.3.1.11 VtString var VT_STRING = 0x0050; // 2.3.3.1.11 VtString
var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString
var VT_CUSTOM = [VT_STRING, VT_USTR]; var VT_CUSTOM = [VT_STRING, VT_USTR];
/* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */ /* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */
var DocSummaryPIDDSI = { var DocSummaryPIDDSI = {
@ -4306,9 +4297,9 @@ var SpecialProperties = {
/*::[*/0x72627262/*::]*/: {} /*::[*/0x72627262/*::]*/: {}
}; };
(function() { (function () {
for(var y in SpecialProperties) if(Object.prototype.hasOwnProperty.call(SpecialProperties, y)) for (var y in SpecialProperties) if (Object.prototype.hasOwnProperty.call(SpecialProperties, y))
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y]; DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})(); })();
var DocSummaryRE/*:{[key:string]:string}*/ = evert_key(DocSummaryPIDDSI, "n"); var DocSummaryRE/*:{[key:string]:string}*/ = evert_key(DocSummaryPIDDSI, "n");
@ -4391,7 +4382,7 @@ var XLSFillPattern = [
'gray0625' 'gray0625'
]; ];
function rgbify(arr/*:Array<number>*/)/*:Array<[number, number, number]>*/ { return arr.map(function(x) { return [(x>>16)&255,(x>>8)&255,x&255]; }); } function rgbify(arr/*:Array<number>*/)/*:Array<[number, number, number]>*/ { return arr.map(function (x) { return [(x >> 16) & 255, (x >> 8) & 255, x & 255]; }); }
/* [MS-XLS] 2.5.161 */ /* [MS-XLS] 2.5.161 */
/* [MS-XLSB] 2.5.75 Icv */ /* [MS-XLSB] 2.5.75 Icv */
@ -4488,7 +4479,20 @@ var _XLSIcv = rgbify([
0x000000 /* 0x51 icvInfoText ?? */ 0x000000 /* 0x51 icvInfoText ?? */
]); ]);
var XLSIcv = dup(_XLSIcv); var XLSIcv = dup(_XLSIcv);
/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
/*::[*/0x00/*::]*/: "#NULL!",
/*::[*/0x07/*::]*/: "#DIV/0!",
/*::[*/0x0F/*::]*/: "#VALUE!",
/*::[*/0x17/*::]*/: "#REF!",
/*::[*/0x1D/*::]*/: "#NAME?",
/*::[*/0x24/*::]*/: "#NUM!",
/*::[*/0x2A/*::]*/: "#N/A",
/*::[*/0x2B/*::]*/: "#GETTING_DATA",
/*::[*/0xFF/*::]*/: "#WTF?"
};
var RBErr = evert_num(BErr);/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* 12.3 Part Summary <SpreadsheetML> */ /* 12.3 Part Summary <SpreadsheetML> */
/* 14.2 Part Summary <DrawingML> */ /* 14.2 Part Summary <DrawingML> */
/* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */ /* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */
@ -11382,7 +11386,7 @@ var PtgBinOp = {
}; };
// List of invalid characters needs to be tested further // List of invalid characters needs to be tested further
var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) var quoteCharacters /*:RegExp */ = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/);
function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ { function formula_quote_sheet_name(sname/*:string*/, opts)/*:string*/ {
if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name");
if (quoteCharacters.test(sname)) return "'" + sname + "'"; if (quoteCharacters.test(sname)) return "'" + sname + "'";
@ -19673,16 +19677,32 @@ var HTML_ = (function() {
}; };
})(); })();
function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ { function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var opts = _opts || {}; var opts = _opts || {};
if(DENSE != null) opts.dense = DENSE; if(DENSE != null) opts.dense = DENSE;
var ws/*:Worksheet*/ = opts.dense ? ([]/*:any*/) : ({}/*:any*/); var or_R = 0, or_C = 0;
if(opts.origin != null) {
if(typeof opts.origin == 'number') or_R = opts.origin;
else {
var _origin/*:CellAddress*/ = typeof opts.origin == "string" ? decode_cell(opts.origin) : opts.origin;
or_R = _origin.r; or_C = _origin.c;
}
}
var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr'); var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000; var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range/*:Range*/ = {s:{r:0,c:0},e:{r:0,c:0}}; var range/*:Range*/ = {s:{r:0,c:0},e:{r:or_R,c:or_C}};
if(ws["!ref"]) {
var _range/*:Range*/ = decode_range(ws["!ref"]);
range.s.r = Math.min(range.s.r, _range.s.r);
range.s.c = Math.min(range.s.c, _range.s.c);
range.e.r = Math.max(range.e.r, _range.e.r);
range.e.c = Math.max(range.e.c, _range.e.c);
if(or_R == -1) range.e.r = or_R = _range.e.r + 1;
}
var merges/*:Array<Range>*/ = [], midx = 0; var merges/*:Array<Range>*/ = [], midx = 0;
var rowinfo/*:Array<RowInfo>*/ = []; var rowinfo/*:Array<RowInfo>*/ = ws["!rows"] || (ws["!rows"] = []);
var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0; var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0;
if(!ws["!cols"]) ws['!cols'] = [];
for(; _R < rows.length && R < sheetRows; ++_R) { for(; _R < rows.length && R < sheetRows; ++_R) {
var row/*:HTMLTableRowElement*/ = rows[_R]; var row/*:HTMLTableRowElement*/ = rows[_R];
if (is_dom_element_hidden(row)) { if (is_dom_element_hidden(row)) {
@ -19697,11 +19717,11 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var z/*:?string*/ = elt.getAttribute('z'); var z/*:?string*/ = elt.getAttribute('z');
for(midx = 0; midx < merges.length; ++midx) { for(midx = 0; midx < merges.length; ++midx) {
var m/*:Range*/ = merges[midx]; var m/*:Range*/ = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } if(m.s.c == C + or_C && m.s.r < R + or_R && R + or_R <= m.e.r) { C = m.e.c+1 - or_C; midx = -1; }
} }
/* TODO: figure out how to extract nonstandard mso- style */ /* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1; CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); if( ((RS = (+elt.getAttribute("rowspan") || 1)))>1 || CS>1) merges.push({s:{r:R + or_R,c:C + or_C},e:{r:R + or_R + (RS||1) - 1, c:C + or_C + (CS||1) - 1}});
var o/*:Cell*/ = {t:'s', v:v}; var o/*:Cell*/ = {t:'s', v:v};
var _t/*:string*/ = elt.getAttribute("t") || ""; var _t/*:string*/ = elt.getAttribute("t") || "";
if(v != null) { if(v != null) {
@ -19717,21 +19737,26 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
} }
} }
if(o.z === undefined && z != null) o.z = z; if(o.z === undefined && z != null) o.z = z;
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} if(opts.dense) { if(!ws[R + or_R]) ws[R + or_R] = []; ws[R + or_R][C + or_C] = o; }
else ws[encode_cell({c:C, r:R})] = o; else ws[encode_cell({c:C + or_C, r:R + or_R})] = o;
if(range.e.c < C) range.e.c = C; if(range.e.c < C + or_C) range.e.c = C + or_C;
C += CS; C += CS;
} }
++R; ++R;
} }
if(merges.length) ws['!merges'] = merges; if(merges.length) ws['!merges'] = (ws["!merges"] || []).concat(merges);
if(rowinfo.length) ws['!rows'] = rowinfo; range.e.r = Math.max(range.e.r, R - 1 + or_R);
range.e.r = R - 1;
ws['!ref'] = encode_range(range); ws['!ref'] = encode_range(range);
if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1,range)); // We can count the real number of rows to parse but we don't to improve the performance if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1 + or_R,range)); // We can count the real number of rows to parse but we don't to improve the performance
return ws; return ws;
} }
function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var opts = _opts || {};
var ws/*:Worksheet*/ = opts.dense ? ([]/*:any*/) : ({}/*:any*/);
return sheet_add_dom(ws, table, _opts);
}
function table_to_book(table/*:HTMLElement*/, opts/*:?any*/)/*:Workbook*/ { function table_to_book(table/*:HTMLElement*/, opts/*:?any*/)/*:Workbook*/ {
return sheet_to_workbook(parse_dom_table(table, opts), opts); return sheet_to_workbook(parse_dom_table(table, opts), opts);
} }
@ -21433,6 +21458,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
} }
function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet*/ { function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet*/ {
if(!js.length) return _ws;
var o = opts || {}; var o = opts || {};
var offset = +!o.skipHeader; var offset = +!o.skipHeader;
var ws/*:Worksheet*/ = _ws || ({}/*:any*/); var ws/*:Worksheet*/ = _ws || ({}/*:any*/);
@ -21451,6 +21477,8 @@ function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet
range.e.c = Math.max(range.e.c, _range.e.c); range.e.c = Math.max(range.e.c, _range.e.c);
range.e.r = Math.max(range.e.r, _range.e.r); range.e.r = Math.max(range.e.r, _range.e.r);
if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; } if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; }
} else {
if(_R == -1) { _R = 0; range.e.r = js.length - 1 + offset; }
} }
var hdr/*:Array<string>*/ = o.header || [], C = 0; var hdr/*:Array<string>*/ = o.header || [], C = 0;
@ -21508,6 +21536,7 @@ var utils/*:any*/ = {
make_formulae: sheet_to_formulae, make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa, sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json, sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
aoa_to_sheet: aoa_to_sheet, aoa_to_sheet: aoa_to_sheet,
json_to_sheet: json_to_sheet, json_to_sheet: json_to_sheet,
table_to_sheet: parse_dom_table, table_to_sheet: parse_dom_table,

229
xlsx.js generated

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {}; var XLSX = {};
function make_xlsx_lib(XLSX){ function make_xlsx_lib(XLSX){
XLSX.version = '0.16.4'; XLSX.version = '0.16.5';
var current_codepage = 1200, current_ansi = 1252; var current_codepage = 1200, current_ansi = 1252;
/*global cptable:true, window */ /*global cptable:true, window */
if(typeof module !== "undefined" && typeof require !== 'undefined') { if(typeof module !== "undefined" && typeof require !== 'undefined') {
@ -3680,7 +3680,11 @@ function encode_cell(cell) {
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
return s + (cell.r + 1); return s + (cell.r + 1);
} }
function decode_range(range) { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } function decode_range(range) {
var idx = range.indexOf(":");
if(idx == -1) return { s: decode_cell(range), e: decode_cell(range) };
return { s: decode_cell(range.slice(0, idx)), e: decode_cell(range.slice(idx + 1)) };
}
function encode_range(cs,ce) { function encode_range(cs,ce) {
if(typeof ce === 'undefined' || typeof ce === 'number') { if(typeof ce === 'undefined' || typeof ce === 'number') {
return encode_range(cs.s, cs.e); return encode_range(cs.s, cs.e);
@ -3754,6 +3758,7 @@ function sheet_add_aoa(_ws, data, opts) {
var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin; var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
_R = _origin.r; _C = _origin.c; _R = _origin.r; _C = _origin.c;
} }
if(!ws["!ref"]) ws["!ref"] = "A1:A1";
} }
var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}); var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}});
if(ws['!ref']) { if(ws['!ref']) {
@ -3805,7 +3810,7 @@ function sheet_add_aoa(_ws, data, opts) {
function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); } function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); }
function write_UInt32LE(x, o) { function write_UInt32LE(x, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(4, x); o.write_shift(4, x);
return o; return o;
} }
@ -3816,9 +3821,9 @@ function parse_XLWideString(data) {
return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLWideString(data, o) { function write_XLWideString(data, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(4+2*data.length); } var _null = false; if (o == null) { _null = true; o = new_buf(4 + 2 * data.length); }
o.write_shift(4, data.length); o.write_shift(4, data.length);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3833,7 +3838,7 @@ function parse_StrRun(data) {
return { ich: data.read_shift(2), ifnt: data.read_shift(2) }; return { ich: data.read_shift(2), ifnt: data.read_shift(2) };
} }
function write_StrRun(run, o) { function write_StrRun(run, o) {
if(!o) o = new_buf(4); if (!o) o = new_buf(4);
o.write_shift(2, run.ich || 0); o.write_shift(2, run.ich || 0);
o.write_shift(2, run.ifnt || 0); o.write_shift(2, run.ifnt || 0);
return o; return o;
@ -3846,13 +3851,13 @@ function parse_RichStr(data, length) {
var str = parse_XLWideString(data); var str = parse_XLWideString(data);
var rgsStrRun = []; var rgsStrRun = [];
var z = ({ t: str, h: str }); var z = ({ t: str, h: str });
if((flags & 1) !== 0) { /* fRichStr */ if ((flags & 1) !== 0) { /* fRichStr */
/* TODO: formatted string */ /* TODO: formatted string */
var dwSizeStrRun = data.read_shift(4); var dwSizeStrRun = data.read_shift(4);
for(var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data)); for (var i = 0; i != dwSizeStrRun; ++i) rgsStrRun.push(parse_StrRun(data));
z.r = rgsStrRun; z.r = rgsStrRun;
} }
else z.r = [{ich:0, ifnt:0}]; else z.r = [{ ich: 0, ifnt: 0 }];
//if((flags & 2) !== 0) { /* fExtStr */ //if((flags & 2) !== 0) { /* fExtStr */
// /* TODO: phonetic string */ // /* TODO: phonetic string */
//} //}
@ -3861,8 +3866,8 @@ function parse_RichStr(data, length) {
} }
function write_RichStr(str, o) { function write_RichStr(str, o) {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(15+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(15 + 4 * str.t.length); }
o.write_shift(1,0); o.write_shift(1, 0);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3870,11 +3875,11 @@ function write_RichStr(str, o) {
var parse_BrtCommentText = parse_RichStr; var parse_BrtCommentText = parse_RichStr;
function write_BrtCommentText(str, o) { function write_BrtCommentText(str, o) {
/* TODO: formatted string */ /* TODO: formatted string */
var _null = false; if(o == null) { _null = true; o = new_buf(23+4*str.t.length); } var _null = false; if (o == null) { _null = true; o = new_buf(23 + 4 * str.t.length); }
o.write_shift(1,1); o.write_shift(1, 1);
write_XLWideString(str.t, o); write_XLWideString(str.t, o);
o.write_shift(4,1); o.write_shift(4, 1);
write_StrRun({ich:0,ifnt:0}, o); write_StrRun({ ich: 0, ifnt: 0 }, o);
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3882,12 +3887,12 @@ function write_BrtCommentText(str, o) {
function parse_XLSBCell(data) { function parse_XLSBCell(data) {
var col = data.read_shift(4); var col = data.read_shift(4);
var iStyleRef = data.read_shift(2); var iStyleRef = data.read_shift(2);
iStyleRef += data.read_shift(1) <<16; iStyleRef += data.read_shift(1) << 16;
data.l++; //var fPhShow = data.read_shift(1); data.l++; //var fPhShow = data.read_shift(1);
return { c:col, iStyleRef: iStyleRef }; return { c: col, iStyleRef: iStyleRef };
} }
function write_XLSBCell(cell, o) { function write_XLSBCell(cell, o) {
if(o == null) o = new_buf(8); if (o == null) o = new_buf(8);
o.write_shift(-4, cell.c); o.write_shift(-4, cell.c);
o.write_shift(3, cell.iStyleRef || cell.s); o.write_shift(3, cell.iStyleRef || cell.s);
o.write_shift(1, 0); /* fPhShow */ o.write_shift(1, 0); /* fPhShow */
@ -3905,9 +3910,9 @@ function parse_XLNullableWideString(data) {
return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs'); return cchCharacters === 0 || cchCharacters === 0xFFFFFFFF ? "" : data.read_shift(cchCharacters, 'dbcs');
} }
function write_XLNullableWideString(data, o) { function write_XLNullableWideString(data, o) {
var _null = false; if(o == null) { _null = true; o = new_buf(127); } var _null = false; if (o == null) { _null = true; o = new_buf(127); }
o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF); o.write_shift(4, data.length > 0 ? data.length : 0xFFFFFFFF);
if(data.length > 0) o.write_shift(0, data, 'dbcs'); if (data.length > 0) o.write_shift(0, data, 'dbcs');
return _null ? o.slice(0, o.l) : o; return _null ? o.slice(0, o.l) : o;
} }
@ -3922,26 +3927,26 @@ var write_RelID = write_XLNullableWideString;
/* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */ /* [MS-XLS] 2.5.217 ; [MS-XLSB] 2.5.122 */
function parse_RkNumber(data) { function parse_RkNumber(data) {
var b = data.slice(data.l, data.l+4); var b = data.slice(data.l, data.l + 4);
var fX100 = (b[0] & 1), fInt = (b[0] & 2); var fX100 = (b[0] & 1), fInt = (b[0] & 2);
data.l+=4; data.l += 4;
b[0] &= 0xFC; // b[0] &= ~3; b[0] &= 0xFC; // b[0] &= ~3;
var RK = fInt === 0 ? __double([0,0,0,0,b[0],b[1],b[2],b[3]],0) : __readInt32LE(b,0)>>2; var RK = fInt === 0 ? __double([0, 0, 0, 0, b[0], b[1], b[2], b[3]], 0) : __readInt32LE(b, 0) >> 2;
return fX100 ? (RK/100) : RK; return fX100 ? (RK / 100) : RK;
} }
function write_RkNumber(data, o) { function write_RkNumber(data, o) {
if(o == null) o = new_buf(4); if (o == null) o = new_buf(4);
var fX100 = 0, fInt = 0, d100 = data * 100; var fX100 = 0, fInt = 0, d100 = data * 100;
if((data == (data | 0)) && (data >= -(1<<29)) && (data < (1 << 29))) { fInt = 1; } if ((data == (data | 0)) && (data >= -(1 << 29)) && (data < (1 << 29))) { fInt = 1; }
else if((d100 == (d100 | 0)) && (d100 >= -(1<<29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; } else if ((d100 == (d100 | 0)) && (d100 >= -(1 << 29)) && (d100 < (1 << 29))) { fInt = 1; fX100 = 1; }
if(fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2)); if (fInt) o.write_shift(-4, ((fX100 ? d100 : data) << 2) + (fX100 + 2));
else throw new Error("unsupported RkNumber " + data); // TODO else throw new Error("unsupported RkNumber " + data); // TODO
} }
/* [MS-XLSB] 2.5.117 RfX */ /* [MS-XLSB] 2.5.117 RfX */
function parse_RfX(data ) { function parse_RfX(data ) {
var cell = ({s: {}, e: {}}); var cell = ({ s: {}, e: {} });
cell.s.r = data.read_shift(4); cell.s.r = data.read_shift(4);
cell.e.r = data.read_shift(4); cell.e.r = data.read_shift(4);
cell.s.c = data.read_shift(4); cell.s.c = data.read_shift(4);
@ -3949,7 +3954,7 @@ function parse_RfX(data ) {
return cell; return cell;
} }
function write_RfX(r, o) { function write_RfX(r, o) {
if(!o) o = new_buf(16); if (!o) o = new_buf(16);
o.write_shift(4, r.s.r); o.write_shift(4, r.s.r);
o.write_shift(4, r.e.r); o.write_shift(4, r.e.r);
o.write_shift(4, r.s.c); o.write_shift(4, r.s.c);
@ -3986,20 +3991,6 @@ var write_UncheckedRfX = write_RfX;
function parse_Xnum(data) { return data.read_shift(8, 'f'); } function parse_Xnum(data) { return data.read_shift(8, 'f'); }
function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); } function write_Xnum(data, o) { return (o || new_buf(8)).write_shift(8, data, 'f'); }
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA",
0xFF: "#WTF?"
};
var RBErr = evert_num(BErr);
/* [MS-XLSB] 2.4.324 BrtColor */ /* [MS-XLSB] 2.4.324 BrtColor */
function parse_BrtColor(data) { function parse_BrtColor(data) {
var out = {}; var out = {};
@ -4015,13 +4006,13 @@ function parse_BrtColor(data) {
var bB = data.read_shift(1); var bB = data.read_shift(1);
data.l++; //var bAlpha = data.read_shift(1); data.l++; //var bAlpha = data.read_shift(1);
switch(xColorType) { switch (xColorType) {
case 0: out.auto = 1; break; case 0: out.auto = 1; break;
case 1: case 1:
out.index = index; out.index = index;
var icv = XLSIcv[index]; var icv = XLSIcv[index];
/* automatic pseudo index 81 */ /* automatic pseudo index 81 */
if(icv) out.rgb = rgb2Hex(icv); if (icv) out.rgb = rgb2Hex(icv);
break; break;
case 2: case 2:
/* if(!fValidRGB) throw new Error("invalid"); */ /* if(!fValidRGB) throw new Error("invalid"); */
@ -4029,17 +4020,17 @@ function parse_BrtColor(data) {
break; break;
case 3: out.theme = index; break; case 3: out.theme = index; break;
} }
if(nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768; if (nTS != 0) out.tint = nTS > 0 ? nTS / 32767 : nTS / 32768;
return out; return out;
} }
function write_BrtColor(color, o) { function write_BrtColor(color, o) {
if(!o) o = new_buf(8); if (!o) o = new_buf(8);
if(!color||color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; } if (!color || color.auto) { o.write_shift(4, 0); o.write_shift(4, 0); return o; }
if(color.index != null) { if (color.index != null) {
o.write_shift(1, 0x02); o.write_shift(1, 0x02);
o.write_shift(1, color.index); o.write_shift(1, color.index);
} else if(color.theme != null) { } else if (color.theme != null) {
o.write_shift(1, 0x06); o.write_shift(1, 0x06);
o.write_shift(1, color.theme); o.write_shift(1, color.theme);
} else { } else {
@ -4047,19 +4038,19 @@ function write_BrtColor(color, o) {
o.write_shift(1, 0); o.write_shift(1, 0);
} }
var nTS = color.tint || 0; var nTS = color.tint || 0;
if(nTS > 0) nTS *= 32767; if (nTS > 0) nTS *= 32767;
else if(nTS < 0) nTS *= 32768; else if (nTS < 0) nTS *= 32768;
o.write_shift(2, nTS); o.write_shift(2, nTS);
if(!color.rgb || color.theme != null) { if (!color.rgb || color.theme != null) {
o.write_shift(2, 0); o.write_shift(2, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
o.write_shift(1, 0); o.write_shift(1, 0);
} else { } else {
var rgb = (color.rgb || 'FFFFFF'); var rgb = (color.rgb || 'FFFFFF');
if(typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6); if (typeof rgb == 'number') rgb = ("000000" + rgb.toString(16)).slice(-6);
o.write_shift(1, parseInt(rgb.slice(0,2),16)); o.write_shift(1, parseInt(rgb.slice(0, 2), 16));
o.write_shift(1, parseInt(rgb.slice(2,4),16)); o.write_shift(1, parseInt(rgb.slice(2, 4), 16));
o.write_shift(1, parseInt(rgb.slice(4,6),16)); o.write_shift(1, parseInt(rgb.slice(4, 6), 16));
o.write_shift(1, 0xFF); o.write_shift(1, 0xFF);
} }
return o; return o;
@ -4082,14 +4073,14 @@ function parse_FontFlags(data) {
return out; return out;
} }
function write_FontFlags(font, o) { function write_FontFlags(font, o) {
if(!o) o = new_buf(2); if (!o) o = new_buf(2);
var grbit = var grbit =
(font.italic ? 0x02 : 0) | (font.italic ? 0x02 : 0) |
(font.strike ? 0x08 : 0) | (font.strike ? 0x08 : 0) |
(font.outline ? 0x10 : 0) | (font.outline ? 0x10 : 0) |
(font.shadow ? 0x20 : 0) | (font.shadow ? 0x20 : 0) |
(font.condense ? 0x40 : 0) | (font.condense ? 0x40 : 0) |
(font.extend ? 0x80 : 0); (font.extend ? 0x80 : 0);
o.write_shift(1, grbit); o.write_shift(1, grbit);
o.write_shift(1, 0); o.write_shift(1, 0);
return o; return o;
@ -4098,13 +4089,13 @@ function write_FontFlags(font, o) {
/* [MS-OLEDS] 2.3.1 and 2.3.2 */ /* [MS-OLEDS] 2.3.1 and 2.3.2 */
function parse_ClipboardFormatOrString(o, w) { function parse_ClipboardFormatOrString(o, w) {
// $FlowIgnore // $FlowIgnore
var ClipFmt = {2:"BITMAP",3:"METAFILEPICT",8:"DIB",14:"ENHMETAFILE"}; var ClipFmt = { 2: "BITMAP", 3: "METAFILEPICT", 8: "DIB", 14: "ENHMETAFILE" };
var m = o.read_shift(4); var m = o.read_shift(4);
switch(m) { switch (m) {
case 0x00000000: return ""; case 0x00000000: return "";
case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)]||""; case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)] || "";
} }
if(m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16)); if (m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16));
o.l -= 4; o.l -= 4;
return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr"); return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr");
} }
@ -4114,43 +4105,43 @@ function parse_ClipboardFormatOrUnicodeString(o) { return parse_ClipboardFormatO
/* [MS-OLEPS] 2.2 PropertyType */ /* [MS-OLEPS] 2.2 PropertyType */
//var VT_EMPTY = 0x0000; //var VT_EMPTY = 0x0000;
//var VT_NULL = 0x0001; //var VT_NULL = 0x0001;
var VT_I2 = 0x0002; var VT_I2 = 0x0002;
var VT_I4 = 0x0003; var VT_I4 = 0x0003;
//var VT_R4 = 0x0004; //var VT_R4 = 0x0004;
//var VT_R8 = 0x0005; //var VT_R8 = 0x0005;
//var VT_CY = 0x0006; //var VT_CY = 0x0006;
//var VT_DATE = 0x0007; //var VT_DATE = 0x0007;
//var VT_BSTR = 0x0008; //var VT_BSTR = 0x0008;
//var VT_ERROR = 0x000A; //var VT_ERROR = 0x000A;
var VT_BOOL = 0x000B; var VT_BOOL = 0x000B;
var VT_VARIANT = 0x000C; var VT_VARIANT = 0x000C;
//var VT_DECIMAL = 0x000E; //var VT_DECIMAL = 0x000E;
//var VT_I1 = 0x0010; //var VT_I1 = 0x0010;
//var VT_UI1 = 0x0011; //var VT_UI1 = 0x0011;
//var VT_UI2 = 0x0012; //var VT_UI2 = 0x0012;
var VT_UI4 = 0x0013; var VT_UI4 = 0x0013;
//var VT_I8 = 0x0014; //var VT_I8 = 0x0014;
//var VT_UI8 = 0x0015; //var VT_UI8 = 0x0015;
//var VT_INT = 0x0016; //var VT_INT = 0x0016;
//var VT_UINT = 0x0017; //var VT_UINT = 0x0017;
var VT_LPSTR = 0x001E; var VT_LPSTR = 0x001E;
//var VT_LPWSTR = 0x001F; //var VT_LPWSTR = 0x001F;
var VT_FILETIME = 0x0040; var VT_FILETIME = 0x0040;
var VT_BLOB = 0x0041; var VT_BLOB = 0x0041;
//var VT_STREAM = 0x0042; //var VT_STREAM = 0x0042;
//var VT_STORAGE = 0x0043; //var VT_STORAGE = 0x0043;
//var VT_STREAMED_Object = 0x0044; //var VT_STREAMED_Object = 0x0044;
//var VT_STORED_Object = 0x0045; //var VT_STORED_Object = 0x0045;
//var VT_BLOB_Object = 0x0046; //var VT_BLOB_Object = 0x0046;
var VT_CF = 0x0047; var VT_CF = 0x0047;
//var VT_CLSID = 0x0048; //var VT_CLSID = 0x0048;
//var VT_VERSIONED_STREAM = 0x0049; //var VT_VERSIONED_STREAM = 0x0049;
var VT_VECTOR = 0x1000; var VT_VECTOR = 0x1000;
//var VT_ARRAY = 0x2000; //var VT_ARRAY = 0x2000;
var VT_STRING = 0x0050; // 2.3.3.1.11 VtString var VT_STRING = 0x0050; // 2.3.3.1.11 VtString
var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString
var VT_CUSTOM = [VT_STRING, VT_USTR]; var VT_CUSTOM = [VT_STRING, VT_USTR];
/* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */ /* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */
var DocSummaryPIDDSI = { var DocSummaryPIDDSI = {
@ -4213,9 +4204,9 @@ var SpecialProperties = {
0x72627262: {} 0x72627262: {}
}; };
(function() { (function () {
for(var y in SpecialProperties) if(Object.prototype.hasOwnProperty.call(SpecialProperties, y)) for (var y in SpecialProperties) if (Object.prototype.hasOwnProperty.call(SpecialProperties, y))
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y]; DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})(); })();
var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n"); var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n");
@ -4298,7 +4289,7 @@ var XLSFillPattern = [
'gray0625' 'gray0625'
]; ];
function rgbify(arr) { return arr.map(function(x) { return [(x>>16)&255,(x>>8)&255,x&255]; }); } function rgbify(arr) { return arr.map(function (x) { return [(x >> 16) & 255, (x >> 8) & 255, x & 255]; }); }
/* [MS-XLS] 2.5.161 */ /* [MS-XLS] 2.5.161 */
/* [MS-XLSB] 2.5.75 Icv */ /* [MS-XLSB] 2.5.75 Icv */
@ -4395,7 +4386,20 @@ var _XLSIcv = rgbify([
0x000000 /* 0x51 icvInfoText ?? */ 0x000000 /* 0x51 icvInfoText ?? */
]); ]);
var XLSIcv = dup(_XLSIcv); var XLSIcv = dup(_XLSIcv);
/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA",
0xFF: "#WTF?"
};
var RBErr = evert_num(BErr);/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* 12.3 Part Summary <SpreadsheetML> */ /* 12.3 Part Summary <SpreadsheetML> */
/* 14.2 Part Summary <DrawingML> */ /* 14.2 Part Summary <DrawingML> */
/* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */ /* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */
@ -11280,7 +11284,7 @@ var PtgBinOp = {
}; };
// List of invalid characters needs to be tested further // List of invalid characters needs to be tested further
var quoteCharacters = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/) var quoteCharacters = new RegExp(/[^\w\u4E00-\u9FFF\u3040-\u30FF]/);
function formula_quote_sheet_name(sname, opts) { function formula_quote_sheet_name(sname, opts) {
if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name"); if(!sname && !(opts && opts.biff <= 5 && opts.biff >= 2)) throw new Error("empty sheet name");
if (quoteCharacters.test(sname)) return "'" + sname + "'"; if (quoteCharacters.test(sname)) return "'" + sname + "'";
@ -19555,16 +19559,32 @@ var HTML_ = (function() {
}; };
})(); })();
function parse_dom_table(table, _opts) { function sheet_add_dom(ws, table, _opts) {
var opts = _opts || {}; var opts = _opts || {};
if(DENSE != null) opts.dense = DENSE; if(DENSE != null) opts.dense = DENSE;
var ws = opts.dense ? ([]) : ({}); var or_R = 0, or_C = 0;
if(opts.origin != null) {
if(typeof opts.origin == 'number') or_R = opts.origin;
else {
var _origin = typeof opts.origin == "string" ? decode_cell(opts.origin) : opts.origin;
or_R = _origin.r; or_C = _origin.c;
}
}
var rows = table.getElementsByTagName('tr'); var rows = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000; var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range = {s:{r:0,c:0},e:{r:0,c:0}}; var range = {s:{r:0,c:0},e:{r:or_R,c:or_C}};
if(ws["!ref"]) {
var _range = decode_range(ws["!ref"]);
range.s.r = Math.min(range.s.r, _range.s.r);
range.s.c = Math.min(range.s.c, _range.s.c);
range.e.r = Math.max(range.e.r, _range.e.r);
range.e.c = Math.max(range.e.c, _range.e.c);
if(or_R == -1) range.e.r = or_R = _range.e.r + 1;
}
var merges = [], midx = 0; var merges = [], midx = 0;
var rowinfo = []; var rowinfo = ws["!rows"] || (ws["!rows"] = []);
var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0; var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0;
if(!ws["!cols"]) ws['!cols'] = [];
for(; _R < rows.length && R < sheetRows; ++_R) { for(; _R < rows.length && R < sheetRows; ++_R) {
var row = rows[_R]; var row = rows[_R];
if (is_dom_element_hidden(row)) { if (is_dom_element_hidden(row)) {
@ -19579,11 +19599,11 @@ function parse_dom_table(table, _opts) {
var z = elt.getAttribute('z'); var z = elt.getAttribute('z');
for(midx = 0; midx < merges.length; ++midx) { for(midx = 0; midx < merges.length; ++midx) {
var m = merges[midx]; var m = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } if(m.s.c == C + or_C && m.s.r < R + or_R && R + or_R <= m.e.r) { C = m.e.c+1 - or_C; midx = -1; }
} }
/* TODO: figure out how to extract nonstandard mso- style */ /* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1; CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); if( ((RS = (+elt.getAttribute("rowspan") || 1)))>1 || CS>1) merges.push({s:{r:R + or_R,c:C + or_C},e:{r:R + or_R + (RS||1) - 1, c:C + or_C + (CS||1) - 1}});
var o = {t:'s', v:v}; var o = {t:'s', v:v};
var _t = elt.getAttribute("t") || ""; var _t = elt.getAttribute("t") || "";
if(v != null) { if(v != null) {
@ -19599,21 +19619,26 @@ function parse_dom_table(table, _opts) {
} }
} }
if(o.z === undefined && z != null) o.z = z; if(o.z === undefined && z != null) o.z = z;
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} if(opts.dense) { if(!ws[R + or_R]) ws[R + or_R] = []; ws[R + or_R][C + or_C] = o; }
else ws[encode_cell({c:C, r:R})] = o; else ws[encode_cell({c:C + or_C, r:R + or_R})] = o;
if(range.e.c < C) range.e.c = C; if(range.e.c < C + or_C) range.e.c = C + or_C;
C += CS; C += CS;
} }
++R; ++R;
} }
if(merges.length) ws['!merges'] = merges; if(merges.length) ws['!merges'] = (ws["!merges"] || []).concat(merges);
if(rowinfo.length) ws['!rows'] = rowinfo; range.e.r = Math.max(range.e.r, R - 1 + or_R);
range.e.r = R - 1;
ws['!ref'] = encode_range(range); ws['!ref'] = encode_range(range);
if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1,range)); // We can count the real number of rows to parse but we don't to improve the performance if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1 + or_R,range)); // We can count the real number of rows to parse but we don't to improve the performance
return ws; return ws;
} }
function parse_dom_table(table, _opts) {
var opts = _opts || {};
var ws = opts.dense ? ([]) : ({});
return sheet_add_dom(ws, table, _opts);
}
function table_to_book(table, opts) { function table_to_book(table, opts) {
return sheet_to_workbook(parse_dom_table(table, opts), opts); return sheet_to_workbook(parse_dom_table(table, opts), opts);
} }
@ -21302,6 +21327,7 @@ function sheet_to_formulae(sheet) {
} }
function sheet_add_json(_ws, js, opts) { function sheet_add_json(_ws, js, opts) {
if(!js.length) return _ws;
var o = opts || {}; var o = opts || {};
var offset = +!o.skipHeader; var offset = +!o.skipHeader;
var ws = _ws || ({}); var ws = _ws || ({});
@ -21320,6 +21346,8 @@ function sheet_add_json(_ws, js, opts) {
range.e.c = Math.max(range.e.c, _range.e.c); range.e.c = Math.max(range.e.c, _range.e.c);
range.e.r = Math.max(range.e.r, _range.e.r); range.e.r = Math.max(range.e.r, _range.e.r);
if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; } if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; }
} else {
if(_R == -1) { _R = 0; range.e.r = js.length - 1 + offset; }
} }
var hdr = o.header || [], C = 0; var hdr = o.header || [], C = 0;
@ -21377,6 +21405,7 @@ var utils = {
make_formulae: sheet_to_formulae, make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa, sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json, sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
aoa_to_sheet: aoa_to_sheet, aoa_to_sheet: aoa_to_sheet,
json_to_sheet: json_to_sheet, json_to_sheet: json_to_sheet,
table_to_sheet: parse_dom_table, table_to_sheet: parse_dom_table,

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {}; var XLSX = {};
function make_xlsx_lib(XLSX){ function make_xlsx_lib(XLSX){
XLSX.version = '0.16.4'; XLSX.version = '0.16.5';
var current_codepage = 1200, current_ansi = 1252; var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ]; var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -3692,7 +3692,11 @@ function encode_cell(cell/*:CellAddress*/)/*:string*/ {
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
return s + (cell.r + 1); return s + (cell.r + 1);
} }
function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } function decode_range(range/*:string*/)/*:Range*/ {
var idx = range.indexOf(":");
if(idx == -1) return { s: decode_cell(range), e: decode_cell(range) };
return { s: decode_cell(range.slice(0, idx)), e: decode_cell(range.slice(idx + 1)) };
}
/*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */ /*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */
function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ { function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ {
if(typeof ce === 'undefined' || typeof ce === 'number') { if(typeof ce === 'undefined' || typeof ce === 'number') {
@ -3771,6 +3775,7 @@ function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksh
var _origin/*:CellAddress*/ = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin; var _origin/*:CellAddress*/ = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
_R = _origin.r; _C = _origin.c; _R = _origin.r; _C = _origin.c;
} }
if(!ws["!ref"]) ws["!ref"] = "A1:A1";
} }
var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}/*:any*/); var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}/*:any*/);
if(ws['!ref']) { if(ws['!ref']) {
@ -3824,43 +3829,43 @@ function aoa_to_sheet(data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ { return sheet_
/* [MS-OLEPS] 2.2 PropertyType */ /* [MS-OLEPS] 2.2 PropertyType */
//var VT_EMPTY = 0x0000; //var VT_EMPTY = 0x0000;
//var VT_NULL = 0x0001; //var VT_NULL = 0x0001;
var VT_I2 = 0x0002; var VT_I2 = 0x0002;
var VT_I4 = 0x0003; var VT_I4 = 0x0003;
//var VT_R4 = 0x0004; //var VT_R4 = 0x0004;
//var VT_R8 = 0x0005; //var VT_R8 = 0x0005;
//var VT_CY = 0x0006; //var VT_CY = 0x0006;
//var VT_DATE = 0x0007; //var VT_DATE = 0x0007;
//var VT_BSTR = 0x0008; //var VT_BSTR = 0x0008;
//var VT_ERROR = 0x000A; //var VT_ERROR = 0x000A;
var VT_BOOL = 0x000B; var VT_BOOL = 0x000B;
var VT_VARIANT = 0x000C; var VT_VARIANT = 0x000C;
//var VT_DECIMAL = 0x000E; //var VT_DECIMAL = 0x000E;
//var VT_I1 = 0x0010; //var VT_I1 = 0x0010;
//var VT_UI1 = 0x0011; //var VT_UI1 = 0x0011;
//var VT_UI2 = 0x0012; //var VT_UI2 = 0x0012;
var VT_UI4 = 0x0013; var VT_UI4 = 0x0013;
//var VT_I8 = 0x0014; //var VT_I8 = 0x0014;
//var VT_UI8 = 0x0015; //var VT_UI8 = 0x0015;
//var VT_INT = 0x0016; //var VT_INT = 0x0016;
//var VT_UINT = 0x0017; //var VT_UINT = 0x0017;
var VT_LPSTR = 0x001E; var VT_LPSTR = 0x001E;
//var VT_LPWSTR = 0x001F; //var VT_LPWSTR = 0x001F;
var VT_FILETIME = 0x0040; var VT_FILETIME = 0x0040;
var VT_BLOB = 0x0041; var VT_BLOB = 0x0041;
//var VT_STREAM = 0x0042; //var VT_STREAM = 0x0042;
//var VT_STORAGE = 0x0043; //var VT_STORAGE = 0x0043;
//var VT_STREAMED_Object = 0x0044; //var VT_STREAMED_Object = 0x0044;
//var VT_STORED_Object = 0x0045; //var VT_STORED_Object = 0x0045;
//var VT_BLOB_Object = 0x0046; //var VT_BLOB_Object = 0x0046;
var VT_CF = 0x0047; var VT_CF = 0x0047;
//var VT_CLSID = 0x0048; //var VT_CLSID = 0x0048;
//var VT_VERSIONED_STREAM = 0x0049; //var VT_VERSIONED_STREAM = 0x0049;
var VT_VECTOR = 0x1000; var VT_VECTOR = 0x1000;
//var VT_ARRAY = 0x2000; //var VT_ARRAY = 0x2000;
var VT_STRING = 0x0050; // 2.3.3.1.11 VtString var VT_STRING = 0x0050; // 2.3.3.1.11 VtString
var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString
var VT_CUSTOM = [VT_STRING, VT_USTR]; var VT_CUSTOM = [VT_STRING, VT_USTR];
/* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */ /* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */
var DocSummaryPIDDSI = { var DocSummaryPIDDSI = {
@ -3923,9 +3928,9 @@ var SpecialProperties = {
/*::[*/0x72627262/*::]*/: {} /*::[*/0x72627262/*::]*/: {}
}; };
(function() { (function () {
for(var y in SpecialProperties) if(Object.prototype.hasOwnProperty.call(SpecialProperties, y)) for (var y in SpecialProperties) if (Object.prototype.hasOwnProperty.call(SpecialProperties, y))
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y]; DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})(); })();
var DocSummaryRE/*:{[key:string]:string}*/ = evert_key(DocSummaryPIDDSI, "n"); var DocSummaryRE/*:{[key:string]:string}*/ = evert_key(DocSummaryPIDDSI, "n");
@ -4008,7 +4013,7 @@ var XLSFillPattern = [
'gray0625' 'gray0625'
]; ];
function rgbify(arr/*:Array<number>*/)/*:Array<[number, number, number]>*/ { return arr.map(function(x) { return [(x>>16)&255,(x>>8)&255,x&255]; }); } function rgbify(arr/*:Array<number>*/)/*:Array<[number, number, number]>*/ { return arr.map(function (x) { return [(x >> 16) & 255, (x >> 8) & 255, x & 255]; }); }
/* [MS-XLS] 2.5.161 */ /* [MS-XLS] 2.5.161 */
/* [MS-XLSB] 2.5.75 Icv */ /* [MS-XLSB] 2.5.75 Icv */
@ -4105,7 +4110,20 @@ var _XLSIcv = rgbify([
0x000000 /* 0x51 icvInfoText ?? */ 0x000000 /* 0x51 icvInfoText ?? */
]); ]);
var XLSIcv = dup(_XLSIcv); var XLSIcv = dup(_XLSIcv);
/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
/*::[*/0x00/*::]*/: "#NULL!",
/*::[*/0x07/*::]*/: "#DIV/0!",
/*::[*/0x0F/*::]*/: "#VALUE!",
/*::[*/0x17/*::]*/: "#REF!",
/*::[*/0x1D/*::]*/: "#NAME?",
/*::[*/0x24/*::]*/: "#NUM!",
/*::[*/0x2A/*::]*/: "#N/A",
/*::[*/0x2B/*::]*/: "#GETTING_DATA",
/*::[*/0xFF/*::]*/: "#WTF?"
};
var RBErr = evert_num(BErr);/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* 12.3 Part Summary <SpreadsheetML> */ /* 12.3 Part Summary <SpreadsheetML> */
/* 14.2 Part Summary <DrawingML> */ /* 14.2 Part Summary <DrawingML> */
/* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */ /* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */
@ -8557,16 +8575,32 @@ var HTML_ = (function() {
}; };
})(); })();
function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ { function sheet_add_dom(ws/*:Worksheet*/, table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var opts = _opts || {}; var opts = _opts || {};
if(DENSE != null) opts.dense = DENSE; if(DENSE != null) opts.dense = DENSE;
var ws/*:Worksheet*/ = opts.dense ? ([]/*:any*/) : ({}/*:any*/); var or_R = 0, or_C = 0;
if(opts.origin != null) {
if(typeof opts.origin == 'number') or_R = opts.origin;
else {
var _origin/*:CellAddress*/ = typeof opts.origin == "string" ? decode_cell(opts.origin) : opts.origin;
or_R = _origin.r; or_C = _origin.c;
}
}
var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr'); var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000; var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range/*:Range*/ = {s:{r:0,c:0},e:{r:0,c:0}}; var range/*:Range*/ = {s:{r:0,c:0},e:{r:or_R,c:or_C}};
if(ws["!ref"]) {
var _range/*:Range*/ = decode_range(ws["!ref"]);
range.s.r = Math.min(range.s.r, _range.s.r);
range.s.c = Math.min(range.s.c, _range.s.c);
range.e.r = Math.max(range.e.r, _range.e.r);
range.e.c = Math.max(range.e.c, _range.e.c);
if(or_R == -1) range.e.r = or_R = _range.e.r + 1;
}
var merges/*:Array<Range>*/ = [], midx = 0; var merges/*:Array<Range>*/ = [], midx = 0;
var rowinfo/*:Array<RowInfo>*/ = []; var rowinfo/*:Array<RowInfo>*/ = ws["!rows"] || (ws["!rows"] = []);
var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0; var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0;
if(!ws["!cols"]) ws['!cols'] = [];
for(; _R < rows.length && R < sheetRows; ++_R) { for(; _R < rows.length && R < sheetRows; ++_R) {
var row/*:HTMLTableRowElement*/ = rows[_R]; var row/*:HTMLTableRowElement*/ = rows[_R];
if (is_dom_element_hidden(row)) { if (is_dom_element_hidden(row)) {
@ -8581,11 +8615,11 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var z/*:?string*/ = elt.getAttribute('z'); var z/*:?string*/ = elt.getAttribute('z');
for(midx = 0; midx < merges.length; ++midx) { for(midx = 0; midx < merges.length; ++midx) {
var m/*:Range*/ = merges[midx]; var m/*:Range*/ = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } if(m.s.c == C + or_C && m.s.r < R + or_R && R + or_R <= m.e.r) { C = m.e.c+1 - or_C; midx = -1; }
} }
/* TODO: figure out how to extract nonstandard mso- style */ /* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1; CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); if( ((RS = (+elt.getAttribute("rowspan") || 1)))>1 || CS>1) merges.push({s:{r:R + or_R,c:C + or_C},e:{r:R + or_R + (RS||1) - 1, c:C + or_C + (CS||1) - 1}});
var o/*:Cell*/ = {t:'s', v:v}; var o/*:Cell*/ = {t:'s', v:v};
var _t/*:string*/ = elt.getAttribute("t") || ""; var _t/*:string*/ = elt.getAttribute("t") || "";
if(v != null) { if(v != null) {
@ -8601,21 +8635,26 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
} }
} }
if(o.z === undefined && z != null) o.z = z; if(o.z === undefined && z != null) o.z = z;
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} if(opts.dense) { if(!ws[R + or_R]) ws[R + or_R] = []; ws[R + or_R][C + or_C] = o; }
else ws[encode_cell({c:C, r:R})] = o; else ws[encode_cell({c:C + or_C, r:R + or_R})] = o;
if(range.e.c < C) range.e.c = C; if(range.e.c < C + or_C) range.e.c = C + or_C;
C += CS; C += CS;
} }
++R; ++R;
} }
if(merges.length) ws['!merges'] = merges; if(merges.length) ws['!merges'] = (ws["!merges"] || []).concat(merges);
if(rowinfo.length) ws['!rows'] = rowinfo; range.e.r = Math.max(range.e.r, R - 1 + or_R);
range.e.r = R - 1;
ws['!ref'] = encode_range(range); ws['!ref'] = encode_range(range);
if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1,range)); // We can count the real number of rows to parse but we don't to improve the performance if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1 + or_R,range)); // We can count the real number of rows to parse but we don't to improve the performance
return ws; return ws;
} }
function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var opts = _opts || {};
var ws/*:Worksheet*/ = opts.dense ? ([]/*:any*/) : ({}/*:any*/);
return sheet_add_dom(ws, table, _opts);
}
function table_to_book(table/*:HTMLElement*/, opts/*:?any*/)/*:Workbook*/ { function table_to_book(table/*:HTMLElement*/, opts/*:?any*/)/*:Workbook*/ {
return sheet_to_workbook(parse_dom_table(table, opts), opts); return sheet_to_workbook(parse_dom_table(table, opts), opts);
} }
@ -9522,6 +9561,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
} }
function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet*/ { function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet*/ {
if(!js.length) return _ws;
var o = opts || {}; var o = opts || {};
var offset = +!o.skipHeader; var offset = +!o.skipHeader;
var ws/*:Worksheet*/ = _ws || ({}/*:any*/); var ws/*:Worksheet*/ = _ws || ({}/*:any*/);
@ -9540,6 +9580,8 @@ function sheet_add_json(_ws/*:?Worksheet*/, js/*:Array<any>*/, opts)/*:Worksheet
range.e.c = Math.max(range.e.c, _range.e.c); range.e.c = Math.max(range.e.c, _range.e.c);
range.e.r = Math.max(range.e.r, _range.e.r); range.e.r = Math.max(range.e.r, _range.e.r);
if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; } if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; }
} else {
if(_R == -1) { _R = 0; range.e.r = js.length - 1 + offset; }
} }
var hdr/*:Array<string>*/ = o.header || [], C = 0; var hdr/*:Array<string>*/ = o.header || [], C = 0;
@ -9597,6 +9639,7 @@ var utils/*:any*/ = {
make_formulae: sheet_to_formulae, make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa, sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json, sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
aoa_to_sheet: aoa_to_sheet, aoa_to_sheet: aoa_to_sheet,
json_to_sheet: json_to_sheet, json_to_sheet: json_to_sheet,
table_to_sheet: parse_dom_table, table_to_sheet: parse_dom_table,

@ -4,7 +4,7 @@
/*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */ /*global global, exports, module, require:false, process:false, Buffer:false, ArrayBuffer:false */
var XLSX = {}; var XLSX = {};
function make_xlsx_lib(XLSX){ function make_xlsx_lib(XLSX){
XLSX.version = '0.16.4'; XLSX.version = '0.16.5';
var current_codepage = 1200, current_ansi = 1252; var current_codepage = 1200, current_ansi = 1252;
var VALID_ANSI = [ 874, 932, 936, 949, 950 ]; var VALID_ANSI = [ 874, 932, 936, 949, 950 ];
@ -3607,7 +3607,11 @@ function encode_cell(cell) {
for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s; for(; col; col=((col-1)/26)|0) s = String.fromCharCode(((col-1)%26) + 65) + s;
return s + (cell.r + 1); return s + (cell.r + 1);
} }
function decode_range(range) { var x =range.split(":"); return {s:decode_cell(x[0]),e:decode_cell(x[x.length-1])}; } function decode_range(range) {
var idx = range.indexOf(":");
if(idx == -1) return { s: decode_cell(range), e: decode_cell(range) };
return { s: decode_cell(range.slice(0, idx)), e: decode_cell(range.slice(idx + 1)) };
}
function encode_range(cs,ce) { function encode_range(cs,ce) {
if(typeof ce === 'undefined' || typeof ce === 'number') { if(typeof ce === 'undefined' || typeof ce === 'number') {
return encode_range(cs.s, cs.e); return encode_range(cs.s, cs.e);
@ -3681,6 +3685,7 @@ function sheet_add_aoa(_ws, data, opts) {
var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin; var _origin = typeof o.origin == "string" ? decode_cell(o.origin) : o.origin;
_R = _origin.r; _C = _origin.c; _R = _origin.r; _C = _origin.c;
} }
if(!ws["!ref"]) ws["!ref"] = "A1:A1";
} }
var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}); var range = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}});
if(ws['!ref']) { if(ws['!ref']) {
@ -3734,43 +3739,43 @@ function aoa_to_sheet(data, opts) { return sheet_add_aoa(null, data, opts); }
/* [MS-OLEPS] 2.2 PropertyType */ /* [MS-OLEPS] 2.2 PropertyType */
//var VT_EMPTY = 0x0000; //var VT_EMPTY = 0x0000;
//var VT_NULL = 0x0001; //var VT_NULL = 0x0001;
var VT_I2 = 0x0002; var VT_I2 = 0x0002;
var VT_I4 = 0x0003; var VT_I4 = 0x0003;
//var VT_R4 = 0x0004; //var VT_R4 = 0x0004;
//var VT_R8 = 0x0005; //var VT_R8 = 0x0005;
//var VT_CY = 0x0006; //var VT_CY = 0x0006;
//var VT_DATE = 0x0007; //var VT_DATE = 0x0007;
//var VT_BSTR = 0x0008; //var VT_BSTR = 0x0008;
//var VT_ERROR = 0x000A; //var VT_ERROR = 0x000A;
var VT_BOOL = 0x000B; var VT_BOOL = 0x000B;
var VT_VARIANT = 0x000C; var VT_VARIANT = 0x000C;
//var VT_DECIMAL = 0x000E; //var VT_DECIMAL = 0x000E;
//var VT_I1 = 0x0010; //var VT_I1 = 0x0010;
//var VT_UI1 = 0x0011; //var VT_UI1 = 0x0011;
//var VT_UI2 = 0x0012; //var VT_UI2 = 0x0012;
var VT_UI4 = 0x0013; var VT_UI4 = 0x0013;
//var VT_I8 = 0x0014; //var VT_I8 = 0x0014;
//var VT_UI8 = 0x0015; //var VT_UI8 = 0x0015;
//var VT_INT = 0x0016; //var VT_INT = 0x0016;
//var VT_UINT = 0x0017; //var VT_UINT = 0x0017;
var VT_LPSTR = 0x001E; var VT_LPSTR = 0x001E;
//var VT_LPWSTR = 0x001F; //var VT_LPWSTR = 0x001F;
var VT_FILETIME = 0x0040; var VT_FILETIME = 0x0040;
var VT_BLOB = 0x0041; var VT_BLOB = 0x0041;
//var VT_STREAM = 0x0042; //var VT_STREAM = 0x0042;
//var VT_STORAGE = 0x0043; //var VT_STORAGE = 0x0043;
//var VT_STREAMED_Object = 0x0044; //var VT_STREAMED_Object = 0x0044;
//var VT_STORED_Object = 0x0045; //var VT_STORED_Object = 0x0045;
//var VT_BLOB_Object = 0x0046; //var VT_BLOB_Object = 0x0046;
var VT_CF = 0x0047; var VT_CF = 0x0047;
//var VT_CLSID = 0x0048; //var VT_CLSID = 0x0048;
//var VT_VERSIONED_STREAM = 0x0049; //var VT_VERSIONED_STREAM = 0x0049;
var VT_VECTOR = 0x1000; var VT_VECTOR = 0x1000;
//var VT_ARRAY = 0x2000; //var VT_ARRAY = 0x2000;
var VT_STRING = 0x0050; // 2.3.3.1.11 VtString var VT_STRING = 0x0050; // 2.3.3.1.11 VtString
var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString var VT_USTR = 0x0051; // 2.3.3.1.12 VtUnalignedString
var VT_CUSTOM = [VT_STRING, VT_USTR]; var VT_CUSTOM = [VT_STRING, VT_USTR];
/* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */ /* [MS-OSHARED] 2.3.3.2.2.1 Document Summary Information PIDDSI */
var DocSummaryPIDDSI = { var DocSummaryPIDDSI = {
@ -3833,9 +3838,9 @@ var SpecialProperties = {
0x72627262: {} 0x72627262: {}
}; };
(function() { (function () {
for(var y in SpecialProperties) if(Object.prototype.hasOwnProperty.call(SpecialProperties, y)) for (var y in SpecialProperties) if (Object.prototype.hasOwnProperty.call(SpecialProperties, y))
DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y]; DocSummaryPIDDSI[y] = SummaryPIDSI[y] = SpecialProperties[y];
})(); })();
var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n"); var DocSummaryRE = evert_key(DocSummaryPIDDSI, "n");
@ -3918,7 +3923,7 @@ var XLSFillPattern = [
'gray0625' 'gray0625'
]; ];
function rgbify(arr) { return arr.map(function(x) { return [(x>>16)&255,(x>>8)&255,x&255]; }); } function rgbify(arr) { return arr.map(function (x) { return [(x >> 16) & 255, (x >> 8) & 255, x & 255]; }); }
/* [MS-XLS] 2.5.161 */ /* [MS-XLS] 2.5.161 */
/* [MS-XLSB] 2.5.75 Icv */ /* [MS-XLSB] 2.5.75 Icv */
@ -4015,7 +4020,20 @@ var _XLSIcv = rgbify([
0x000000 /* 0x51 icvInfoText ?? */ 0x000000 /* 0x51 icvInfoText ?? */
]); ]);
var XLSIcv = dup(_XLSIcv); var XLSIcv = dup(_XLSIcv);
/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* [MS-XLSB] 2.5.97.2 */
var BErr = {
0x00: "#NULL!",
0x07: "#DIV/0!",
0x0F: "#VALUE!",
0x17: "#REF!",
0x1D: "#NAME?",
0x24: "#NUM!",
0x2A: "#N/A",
0x2B: "#GETTING_DATA",
0xFF: "#WTF?"
};
var RBErr = evert_num(BErr);/* Parts enumerated in OPC spec, MS-XLSB and MS-XLSX */
/* 12.3 Part Summary <SpreadsheetML> */ /* 12.3 Part Summary <SpreadsheetML> */
/* 14.2 Part Summary <DrawingML> */ /* 14.2 Part Summary <DrawingML> */
/* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */ /* [MS-XLSX] 2.1 Part Enumerations ; [MS-XLSB] 2.1.7 Part Enumeration */
@ -8464,16 +8482,32 @@ var HTML_ = (function() {
}; };
})(); })();
function parse_dom_table(table, _opts) { function sheet_add_dom(ws, table, _opts) {
var opts = _opts || {}; var opts = _opts || {};
if(DENSE != null) opts.dense = DENSE; if(DENSE != null) opts.dense = DENSE;
var ws = opts.dense ? ([]) : ({}); var or_R = 0, or_C = 0;
if(opts.origin != null) {
if(typeof opts.origin == 'number') or_R = opts.origin;
else {
var _origin = typeof opts.origin == "string" ? decode_cell(opts.origin) : opts.origin;
or_R = _origin.r; or_C = _origin.c;
}
}
var rows = table.getElementsByTagName('tr'); var rows = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000; var sheetRows = Math.min(opts.sheetRows||10000000, rows.length);
var range = {s:{r:0,c:0},e:{r:0,c:0}}; var range = {s:{r:0,c:0},e:{r:or_R,c:or_C}};
if(ws["!ref"]) {
var _range = decode_range(ws["!ref"]);
range.s.r = Math.min(range.s.r, _range.s.r);
range.s.c = Math.min(range.s.c, _range.s.c);
range.e.r = Math.max(range.e.r, _range.e.r);
range.e.c = Math.max(range.e.c, _range.e.c);
if(or_R == -1) range.e.r = or_R = _range.e.r + 1;
}
var merges = [], midx = 0; var merges = [], midx = 0;
var rowinfo = []; var rowinfo = ws["!rows"] || (ws["!rows"] = []);
var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0; var _R = 0, R = 0, _C = 0, C = 0, RS = 0, CS = 0;
if(!ws["!cols"]) ws['!cols'] = [];
for(; _R < rows.length && R < sheetRows; ++_R) { for(; _R < rows.length && R < sheetRows; ++_R) {
var row = rows[_R]; var row = rows[_R];
if (is_dom_element_hidden(row)) { if (is_dom_element_hidden(row)) {
@ -8488,11 +8522,11 @@ function parse_dom_table(table, _opts) {
var z = elt.getAttribute('z'); var z = elt.getAttribute('z');
for(midx = 0; midx < merges.length; ++midx) { for(midx = 0; midx < merges.length; ++midx) {
var m = merges[midx]; var m = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; } if(m.s.c == C + or_C && m.s.r < R + or_R && R + or_R <= m.e.r) { C = m.e.c+1 - or_C; midx = -1; }
} }
/* TODO: figure out how to extract nonstandard mso- style */ /* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1; CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); if( ((RS = (+elt.getAttribute("rowspan") || 1)))>1 || CS>1) merges.push({s:{r:R + or_R,c:C + or_C},e:{r:R + or_R + (RS||1) - 1, c:C + or_C + (CS||1) - 1}});
var o = {t:'s', v:v}; var o = {t:'s', v:v};
var _t = elt.getAttribute("t") || ""; var _t = elt.getAttribute("t") || "";
if(v != null) { if(v != null) {
@ -8508,21 +8542,26 @@ function parse_dom_table(table, _opts) {
} }
} }
if(o.z === undefined && z != null) o.z = z; if(o.z === undefined && z != null) o.z = z;
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o;} if(opts.dense) { if(!ws[R + or_R]) ws[R + or_R] = []; ws[R + or_R][C + or_C] = o; }
else ws[encode_cell({c:C, r:R})] = o; else ws[encode_cell({c:C + or_C, r:R + or_R})] = o;
if(range.e.c < C) range.e.c = C; if(range.e.c < C + or_C) range.e.c = C + or_C;
C += CS; C += CS;
} }
++R; ++R;
} }
if(merges.length) ws['!merges'] = merges; if(merges.length) ws['!merges'] = (ws["!merges"] || []).concat(merges);
if(rowinfo.length) ws['!rows'] = rowinfo; range.e.r = Math.max(range.e.r, R - 1 + or_R);
range.e.r = R - 1;
ws['!ref'] = encode_range(range); ws['!ref'] = encode_range(range);
if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1,range)); // We can count the real number of rows to parse but we don't to improve the performance if(R >= sheetRows) ws['!fullref'] = encode_range((range.e.r = rows.length-_R+R-1 + or_R,range)); // We can count the real number of rows to parse but we don't to improve the performance
return ws; return ws;
} }
function parse_dom_table(table, _opts) {
var opts = _opts || {};
var ws = opts.dense ? ([]) : ({});
return sheet_add_dom(ws, table, _opts);
}
function table_to_book(table, opts) { function table_to_book(table, opts) {
return sheet_to_workbook(parse_dom_table(table, opts), opts); return sheet_to_workbook(parse_dom_table(table, opts), opts);
} }
@ -9417,6 +9456,7 @@ function sheet_to_formulae(sheet) {
} }
function sheet_add_json(_ws, js, opts) { function sheet_add_json(_ws, js, opts) {
if(!js.length) return _ws;
var o = opts || {}; var o = opts || {};
var offset = +!o.skipHeader; var offset = +!o.skipHeader;
var ws = _ws || ({}); var ws = _ws || ({});
@ -9435,6 +9475,8 @@ function sheet_add_json(_ws, js, opts) {
range.e.c = Math.max(range.e.c, _range.e.c); range.e.c = Math.max(range.e.c, _range.e.c);
range.e.r = Math.max(range.e.r, _range.e.r); range.e.r = Math.max(range.e.r, _range.e.r);
if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; } if(_R == -1) { _R = _range.e.r + 1; range.e.r = _R + js.length - 1 + offset; }
} else {
if(_R == -1) { _R = 0; range.e.r = js.length - 1 + offset; }
} }
var hdr = o.header || [], C = 0; var hdr = o.header || [], C = 0;
@ -9492,6 +9534,7 @@ var utils = {
make_formulae: sheet_to_formulae, make_formulae: sheet_to_formulae,
sheet_add_aoa: sheet_add_aoa, sheet_add_aoa: sheet_add_aoa,
sheet_add_json: sheet_add_json, sheet_add_json: sheet_add_json,
sheet_add_dom: sheet_add_dom,
aoa_to_sheet: aoa_to_sheet, aoa_to_sheet: aoa_to_sheet,
json_to_sheet: json_to_sheet, json_to_sheet: json_to_sheet,
table_to_sheet: parse_dom_table, table_to_sheet: parse_dom_table,