Compare commits

...

3 Commits

Author SHA1 Message Date
ThomasChan
aaefb5344e fix xlsx merge cells logic 2019-09-25 15:13:40 +08:00
ThomasChan
760c55d533 improve parse_dom_table merge cell logic performance 2019-09-19 20:26:56 +08:00
ThomasChan
eafc07926b improve parse_dom_table merge cell logic performance 2019-09-19 20:23:39 +08:00
4 changed files with 104 additions and 52 deletions

@ -19160,29 +19160,42 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000;
var range/*:Range*/ = {s:{r:0,c:0},e:{r:0,c:0}};
var merges/*:Array<Range>*/ = [], midx = 0;
var merges/*:Array<Range>*/ = [], midx = 0, m, cInRange/*:Array<Range>*/ = [], cache/*:Object<Cache>*/ = {};
var rowinfo/*:Array<RowInfo>*/ = [];
var _R = 0, R = 0, _C, C, RS, CS;
var _R = 0, R = 0, _C, C, RS, CS, row, elts, elt, h, v, o, _t;
for(; _R < rows.length && R < sheetRows; ++_R) {
var row/*:HTMLTableRowElement*/ = rows[_R];
row/*:HTMLTableRowElement*/ = rows[_R];
if (is_dom_element_hidden(row)) {
if (opts.display) continue;
rowinfo[R] = {hidden: true};
}
var elts/*:HTMLCollection<HTMLTableCellElement>*/ = (row.children/*:any*/);
elts/*:HTMLCollection<HTMLTableCellElement>*/ = (row.children/*:any*/);
for(_C = C = 0; _C < elts.length; ++_C) {
var elt/*:HTMLTableCellElement*/ = elts[_C];
elt/*:HTMLTableCellElement*/ = elts[_C];
if (opts.display && is_dom_element_hidden(elt)) continue;
var v/*:string*/ = htmldecode(elt.innerHTML);
for(midx = 0; midx < merges.length; ++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; }
h/*:string*/ = elt.innerHTML;
v/*:string*/ = cache[h] || (cache[h] = htmldecode(elt.innerHTML));
cInRange.length = 0;
midx/*:number*/ = merges.length;
while (midx--) {
m/*:Range*/ = merges[midx];
if(m.s.r <= R && R <= m.e.r) {
cInRange.push(m.e.c);
}
}
if (cInRange.indexOf(C) !== -1) {
for (let i = 0; i < cInRange.length; i++) {
C += 1;
if (cInRange.indexOf(C) === -1) {
break;
}
}
}
/* TODO: figure out how to extract nonstandard mso- style */
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}});
var o/*:Cell*/ = {t:'s', v:v};
var _t/*:string*/ = elt.getAttribute("t") || "";
CS = +elt.colSpan || 1;
if((RS = +elt.rowSpan)>1 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});
o/*:Cell*/ = {t:'s', v:v};
_t/*:string*/ = elt.getAttribute("t") || "";
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}

39
xlsx.js generated

@ -19044,29 +19044,42 @@ function parse_dom_table(table, _opts) {
var rows = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000;
var range = {s:{r:0,c:0},e:{r:0,c:0}};
var merges = [], midx = 0;
var merges = [], midx = 0, m, cInRange = [], cache = {};
var rowinfo = [];
var _R = 0, R = 0, _C, C, RS, CS;
var _R = 0, R = 0, _C, C, RS, CS, row, elts, elt, h, v, o, _t;
for(; _R < rows.length && R < sheetRows; ++_R) {
var row = rows[_R];
row = rows[_R];
if (is_dom_element_hidden(row)) {
if (opts.display) continue;
rowinfo[R] = {hidden: true};
}
var elts = (row.children);
elts = (row.children);
for(_C = C = 0; _C < elts.length; ++_C) {
var elt = elts[_C];
elt = elts[_C];
if (opts.display && is_dom_element_hidden(elt)) continue;
var v = htmldecode(elt.innerHTML);
for(midx = 0; midx < merges.length; ++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; }
h = elt.innerHTML;
v = h || (cache[h] = htmldecode(elt.innerHTML));
cInRange.length = 0;
midx = merges.length;
while (midx--) {
m = merges[midx];
if(m.s.r <= R && R <= m.e.r) {
cInRange.push(m.e.c);
}
}
if (cInRange.indexOf(C) !== -1) {
for (let i = 0; i < cInRange.length; i++) {
C += 1;
if (cInRange.indexOf(C) === -1) {
break;
}
}
}
/* TODO: figure out how to extract nonstandard mso- style */
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}});
var o = {t:'s', v:v};
var _t = elt.getAttribute("t") || "";
CS = +elt.colSpan || 1;
if((RS = +elt.rowSpan)>1 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});
o = {t:'s', v:v};
_t = elt.getAttribute("t") || "";
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}

@ -7379,29 +7379,42 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var rows/*:HTMLCollection<HTMLTableRowElement>*/ = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000;
var range/*:Range*/ = {s:{r:0,c:0},e:{r:0,c:0}};
var merges/*:Array<Range>*/ = [], midx = 0;
var merges/*:Array<Range>*/ = [], midx = 0, m, cInRange/*:Array<Range>*/ = [], cache/*:Object<Cache>*/ = {};
var rowinfo/*:Array<RowInfo>*/ = [];
var _R = 0, R = 0, _C, C, RS, CS;
var _R = 0, R = 0, _C, C, RS, CS, row, elts, elt, h, v, o, _t;
for(; _R < rows.length && R < sheetRows; ++_R) {
var row/*:HTMLTableRowElement*/ = rows[_R];
row/*:HTMLTableRowElement*/ = rows[_R];
if (is_dom_element_hidden(row)) {
if (opts.display) continue;
rowinfo[R] = {hidden: true};
}
var elts/*:HTMLCollection<HTMLTableCellElement>*/ = (row.children/*:any*/);
elts/*:HTMLCollection<HTMLTableCellElement>*/ = (row.children/*:any*/);
for(_C = C = 0; _C < elts.length; ++_C) {
var elt/*:HTMLTableCellElement*/ = elts[_C];
elt/*:HTMLTableCellElement*/ = elts[_C];
if (opts.display && is_dom_element_hidden(elt)) continue;
var v/*:string*/ = htmldecode(elt.innerHTML);
for(midx = 0; midx < merges.length; ++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; }
h/*:string*/ = elt.innerHTML;
v/*:string*/ = cache[h] || (cache[h] = htmldecode(elt.innerHTML));
cInRange.length = 0;
midx/*:number*/ = merges.length;
while (midx--) {
m/*:Range*/ = merges[midx];
if(m.s.r <= R && R <= m.e.r) {
cInRange.push(m.e.c);
}
}
if (cInRange.indexOf(C) !== -1) {
for (let i = 0; i < cInRange.length; i++) {
C += 1;
if (cInRange.indexOf(C) === -1) {
break;
}
}
}
/* TODO: figure out how to extract nonstandard mso- style */
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}});
var o/*:Cell*/ = {t:'s', v:v};
var _t/*:string*/ = elt.getAttribute("t") || "";
CS = +elt.colSpan || 1;
if((RS = +elt.rowSpan)>1 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});
o/*:Cell*/ = {t:'s', v:v};
_t/*:string*/ = elt.getAttribute("t") || "";
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}

@ -7288,29 +7288,42 @@ function parse_dom_table(table, _opts) {
var rows = table.getElementsByTagName('tr');
var sheetRows = opts.sheetRows || 10000000;
var range = {s:{r:0,c:0},e:{r:0,c:0}};
var merges = [], midx = 0;
var merges = [], midx = 0, m, cInRange = [], cache = {};
var rowinfo = [];
var _R = 0, R = 0, _C, C, RS, CS;
var _R = 0, R = 0, _C, C, RS, CS, row, elts, elt, h, v, o, _t;
for(; _R < rows.length && R < sheetRows; ++_R) {
var row = rows[_R];
row = rows[_R];
if (is_dom_element_hidden(row)) {
if (opts.display) continue;
rowinfo[R] = {hidden: true};
}
var elts = (row.children);
elts = (row.children);
for(_C = C = 0; _C < elts.length; ++_C) {
var elt = elts[_C];
elt = elts[_C];
if (opts.display && is_dom_element_hidden(elt)) continue;
var v = htmldecode(elt.innerHTML);
for(midx = 0; midx < merges.length; ++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; }
h = elt.innerHTML;
v = h || (cache[h] = htmldecode(elt.innerHTML));
cInRange.length = 0;
midx = merges.length;
while (midx--) {
m = merges[midx];
if(m.s.r <= R && R <= m.e.r) {
cInRange.push(m.e.c);
}
}
if (cInRange.indexOf(C) !== -1) {
for (let i = 0; i < cInRange.length; i++) {
C += 1;
if (cInRange.indexOf(C) === -1) {
break;
}
}
}
/* TODO: figure out how to extract nonstandard mso- style */
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}});
var o = {t:'s', v:v};
var _t = elt.getAttribute("t") || "";
CS = +elt.colSpan || 1;
if((RS = +elt.rowSpan)>1 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});
o = {t:'s', v:v};
_t = elt.getAttribute("t") || "";
if(v != null) {
if(v.length == 0) o.t = _t || 'z';
else if(opts.raw || v.trim().length == 0 || _t == "s"){}