2014-02-13 06:22:42 +00:00
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* [MS-XLSB] 2.4.718 BrtRowHdr */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtRowHdr(data, length) {
|
|
|
|
var z = [];
|
2014-01-28 16:38:02 +00:00
|
|
|
z.r = data.read_shift(4);
|
|
|
|
data.l += length-4;
|
|
|
|
return z;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
function write_BrtRowHdr(R/*:number*/, range, ws) {
|
|
|
|
var o = new_buf(17+8*16);
|
|
|
|
o.write_shift(4, R);
|
|
|
|
|
|
|
|
/* TODO: flags styles */
|
|
|
|
o.write_shift(4, 0);
|
|
|
|
o.write_shift(2, 0x0140);
|
|
|
|
o.write_shift(2, 0);
|
|
|
|
o.write_shift(1, 0);
|
|
|
|
|
|
|
|
/* [MS-XLSB] 2.5.8 BrtColSpan explains the mechanism */
|
|
|
|
var ncolspan = 0, lcs = o.l;
|
|
|
|
o.l += 4;
|
|
|
|
|
|
|
|
var caddr = {r:R, c:0};
|
|
|
|
for(var i = 0; i < 16; ++i) {
|
|
|
|
if(range.s.c > ((i+1) << 10) || range.e.c < (i << 10)) continue;
|
|
|
|
var first = -1, last = -1;
|
|
|
|
for(var j = (i<<10); j < ((i+1)<<10); ++j) {
|
|
|
|
caddr.c = j;
|
|
|
|
if(ws[encode_cell(caddr)]) { if(first < 0) first = j; last = j; }
|
|
|
|
}
|
|
|
|
if(first < 0) continue;
|
|
|
|
++ncolspan;
|
|
|
|
o.write_shift(4, first);
|
|
|
|
o.write_shift(4, last);
|
|
|
|
}
|
|
|
|
|
|
|
|
var l = o.l;
|
|
|
|
o.l = lcs;
|
|
|
|
o.write_shift(4, ncolspan);
|
|
|
|
o.l = l;
|
|
|
|
|
|
|
|
return o.length > o.l ? o.slice(0, o.l) : o;
|
|
|
|
}
|
|
|
|
function write_row_header(ba, ws, range, R) {
|
|
|
|
var o = write_BrtRowHdr(R, range, ws);
|
|
|
|
if(o.length > 17) write_record(ba, 'BrtRowHdr', o);
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.812 BrtWsDim */
|
|
|
|
var parse_BrtWsDim = parse_UncheckedRfX;
|
2014-05-29 22:30:03 +00:00
|
|
|
var write_BrtWsDim = write_UncheckedRfX;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.815 BrtWsProp */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtWsProp(data, length) {
|
2014-01-28 16:38:02 +00:00
|
|
|
var z = {};
|
|
|
|
/* TODO: pull flags */
|
|
|
|
data.l += 19;
|
2015-04-02 20:32:22 +00:00
|
|
|
z.name = parse_XLSBCodeName(data, length - 19);
|
2014-01-28 16:38:02 +00:00
|
|
|
return z;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-02-13 06:22:42 +00:00
|
|
|
/* [MS-XLSB] 2.4.303 BrtCellBlank */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtCellBlank(data, length) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-03-29 22:53:15 +00:00
|
|
|
return [cell];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
function write_BrtCellBlank(cell, ncell, o) {
|
2014-07-28 13:22:32 +00:00
|
|
|
if(o == null) o = new_buf(8);
|
2017-02-03 20:50:45 +00:00
|
|
|
return write_XLSBCell(ncell, o);
|
2014-07-28 13:22:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 06:22:42 +00:00
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* [MS-XLSB] 2.4.304 BrtCellBool */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtCellBool(data, length) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-01-28 16:38:02 +00:00
|
|
|
var fBool = data.read_shift(1);
|
|
|
|
return [cell, fBool, 'b'];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
function write_BrtCellBool(cell, ncell, o) {
|
|
|
|
if(o == null) o = new_buf(9);
|
|
|
|
write_XLSBCell(ncell, o);
|
|
|
|
o.write_shift(1, cell.v ? 1 : 0);
|
|
|
|
return o;
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.305 BrtCellError */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtCellError(data, length) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2017-02-03 20:50:45 +00:00
|
|
|
var bError = data.read_shift(1);
|
|
|
|
return [cell, bError, 'e'];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.308 BrtCellIsst */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtCellIsst(data, length) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-01-28 16:38:02 +00:00
|
|
|
var isst = data.read_shift(4);
|
|
|
|
return [cell, isst, 's'];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
function write_BrtCellIsst(cell, ncell, o) {
|
|
|
|
if(o == null) o = new_buf(12);
|
|
|
|
write_XLSBCell(ncell, o);
|
|
|
|
o.write_shift(4, ncell.v);
|
|
|
|
return o;
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.310 BrtCellReal */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtCellReal(data, length) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-01-28 16:38:02 +00:00
|
|
|
var value = parse_Xnum(data);
|
|
|
|
return [cell, value, 'n'];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
function write_BrtCellReal(cell, ncell, o) {
|
|
|
|
if(o == null) o = new_buf(16);
|
|
|
|
write_XLSBCell(ncell, o);
|
|
|
|
write_Xnum(cell.v, o);
|
|
|
|
return o;
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.311 BrtCellRk */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtCellRk(data, length) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-01-28 16:38:02 +00:00
|
|
|
var value = parse_RkNumber(data);
|
|
|
|
return [cell, value, 'n'];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
function write_BrtCellRk(cell, ncell, o) {
|
|
|
|
if(o == null) o = new_buf(12);
|
|
|
|
write_XLSBCell(ncell, o);
|
|
|
|
write_RkNumber(cell.v, o);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-02-13 06:22:42 +00:00
|
|
|
/* [MS-XLSB] 2.4.314 BrtCellSt */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtCellSt(data, length) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-01-28 16:38:02 +00:00
|
|
|
var value = parse_XLWideString(data);
|
|
|
|
return [cell, value, 'str'];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
function write_BrtCellSt(cell, ncell, o) {
|
|
|
|
if(o == null) o = new_buf(12 + 4 * cell.v.length);
|
|
|
|
write_XLSBCell(ncell, o);
|
|
|
|
write_XLWideString(cell.v, o);
|
|
|
|
return o.length > o.l ? o.slice(0, o.l) : o;
|
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-02-12 06:09:42 +00:00
|
|
|
/* [MS-XLSB] 2.4.647 BrtFmlaBool */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtFmlaBool(data, length, opts) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-02-12 06:09:42 +00:00
|
|
|
var value = data.read_shift(1);
|
2014-02-13 06:22:42 +00:00
|
|
|
var o = [cell, value, 'b'];
|
|
|
|
if(opts.cellFormula) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var formula = parse_XLSBCellParsedFormula(data, length-9);
|
2014-02-13 06:22:42 +00:00
|
|
|
o[3] = ""; /* TODO */
|
|
|
|
}
|
|
|
|
else data.l += length-9;
|
|
|
|
return o;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-02-12 06:09:42 +00:00
|
|
|
|
2014-01-29 06:00:09 +00:00
|
|
|
/* [MS-XLSB] 2.4.648 BrtFmlaError */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtFmlaError(data, length, opts) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-02-13 06:22:42 +00:00
|
|
|
var value = data.read_shift(1);
|
|
|
|
var o = [cell, value, 'e'];
|
|
|
|
if(opts.cellFormula) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var formula = parse_XLSBCellParsedFormula(data, length-9);
|
2014-02-13 06:22:42 +00:00
|
|
|
o[3] = ""; /* TODO */
|
|
|
|
}
|
|
|
|
else data.l += length-9;
|
|
|
|
return o;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
|
|
|
/* [MS-XLSB] 2.4.649 BrtFmlaNum */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtFmlaNum(data, length, opts) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-01-28 16:38:02 +00:00
|
|
|
var value = parse_Xnum(data);
|
2014-02-13 06:22:42 +00:00
|
|
|
var o = [cell, value, 'n'];
|
|
|
|
if(opts.cellFormula) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var formula = parse_XLSBCellParsedFormula(data, length - 16);
|
2014-02-13 06:22:42 +00:00
|
|
|
o[3] = ""; /* TODO */
|
|
|
|
}
|
|
|
|
else data.l += length-16;
|
|
|
|
return o;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-02-12 06:09:42 +00:00
|
|
|
/* [MS-XLSB] 2.4.650 BrtFmlaString */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtFmlaString(data, length, opts) {
|
2014-02-12 06:09:42 +00:00
|
|
|
var start = data.l;
|
2015-04-02 20:32:22 +00:00
|
|
|
var cell = parse_XLSBCell(data);
|
2014-02-12 06:09:42 +00:00
|
|
|
var value = parse_XLWideString(data);
|
2014-02-13 06:22:42 +00:00
|
|
|
var o = [cell, value, 'str'];
|
|
|
|
if(opts.cellFormula) {
|
2015-04-02 20:32:22 +00:00
|
|
|
var formula = parse_XLSBCellParsedFormula(data, start + length - data.l);
|
2014-02-13 06:22:42 +00:00
|
|
|
}
|
|
|
|
else data.l = start + length;
|
|
|
|
return o;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-02-12 06:09:42 +00:00
|
|
|
|
2014-03-23 21:30:00 +00:00
|
|
|
/* [MS-XLSB] 2.4.676 BrtMergeCell */
|
|
|
|
var parse_BrtMergeCell = parse_UncheckedRfX;
|
|
|
|
|
2014-04-15 09:04:03 +00:00
|
|
|
/* [MS-XLSB] 2.4.656 BrtHLink */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_BrtHLink(data, length, opts) {
|
2014-04-15 09:04:03 +00:00
|
|
|
var end = data.l + length;
|
|
|
|
var rfx = parse_UncheckedRfX(data, 16);
|
|
|
|
var relId = parse_XLNullableWideString(data);
|
|
|
|
var loc = parse_XLWideString(data);
|
|
|
|
var tooltip = parse_XLWideString(data);
|
|
|
|
var display = parse_XLWideString(data);
|
|
|
|
data.l = end;
|
|
|
|
return {rfx:rfx, relId:relId, loc:loc, tooltip:tooltip, display:display};
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-04-15 09:04:03 +00:00
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
/* [MS-XLSB] 2.1.7.61 Worksheet */
|
2014-06-29 18:29:45 +00:00
|
|
|
function parse_ws_bin(data, opts, rels) {
|
2014-01-28 16:38:02 +00:00
|
|
|
if(!data) return data;
|
2014-04-15 09:04:03 +00:00
|
|
|
if(!rels) rels = {'!id':{}};
|
2014-01-28 16:38:02 +00:00
|
|
|
var s = {};
|
|
|
|
|
|
|
|
var ref;
|
2017-02-03 20:50:45 +00:00
|
|
|
var refguess = {s: {r:2000000, c:2000000}, e: {r:0, c:0} };
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-02-19 03:03:28 +00:00
|
|
|
var pass = false, end = false;
|
2014-06-29 18:29:45 +00:00
|
|
|
var row, p, cf, R, C, addr, sstr, rr;
|
2014-03-23 21:30:00 +00:00
|
|
|
var mergecells = [];
|
2017-02-10 19:23:01 +00:00
|
|
|
recordhopper(data, function ws_parse(val, Record) {
|
|
|
|
//console.log(Record);
|
2014-02-19 03:03:28 +00:00
|
|
|
if(end) return;
|
2017-02-10 19:23:01 +00:00
|
|
|
switch(Record.n) {
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtWsDim': ref = val; break;
|
2014-02-19 03:03:28 +00:00
|
|
|
case 'BrtRowHdr':
|
|
|
|
row = val;
|
|
|
|
if(opts.sheetRows && opts.sheetRows <= row.r) end=true;
|
2014-06-29 18:29:45 +00:00
|
|
|
rr = encode_row(row.r);
|
2014-02-19 03:03:28 +00:00
|
|
|
break;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-02-12 06:09:42 +00:00
|
|
|
case 'BrtFmlaBool':
|
|
|
|
case 'BrtFmlaError':
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtFmlaNum':
|
2014-02-12 06:09:42 +00:00
|
|
|
case 'BrtFmlaString':
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtCellBool':
|
|
|
|
case 'BrtCellError':
|
|
|
|
case 'BrtCellIsst':
|
|
|
|
case 'BrtCellReal':
|
|
|
|
case 'BrtCellRk':
|
2014-03-19 17:53:20 +00:00
|
|
|
case 'BrtCellSt':
|
2017-02-10 19:23:01 +00:00
|
|
|
p = ({t:val[2]}/*:any*/);
|
2014-01-28 16:38:02 +00:00
|
|
|
switch(val[2]) {
|
|
|
|
case 'n': p.v = val[1]; break;
|
2014-06-29 18:29:45 +00:00
|
|
|
case 's': sstr = strs[val[1]]; p.v = sstr.t; p.r = sstr.r; break;
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'b': p.v = val[1] ? true : false; break;
|
2014-10-26 05:26:18 +00:00
|
|
|
case 'e': p.v = val[1]; p.w = BErr[p.v]; break;
|
|
|
|
case 'str': p.t = 's'; p.v = utf8read(val[1]); break;
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
2014-02-13 06:22:42 +00:00
|
|
|
if(opts.cellFormula && val.length > 3) p.f = val[3];
|
2014-06-02 05:19:07 +00:00
|
|
|
if((cf = styles.CellXf[val[0].iStyleRef])) safe_format(p,cf.ifmt,null,opts);
|
2014-06-29 18:29:45 +00:00
|
|
|
s[encode_col(C=val[0].c) + rr] = p;
|
2014-02-19 03:03:28 +00:00
|
|
|
if(refguess.s.r > row.r) refguess.s.r = row.r;
|
2014-06-29 18:29:45 +00:00
|
|
|
if(refguess.s.c > C) refguess.s.c = C;
|
2014-02-19 03:03:28 +00:00
|
|
|
if(refguess.e.r < row.r) refguess.e.r = row.r;
|
2014-06-29 18:29:45 +00:00
|
|
|
if(refguess.e.c < C) refguess.e.c = C;
|
2014-02-19 03:03:28 +00:00
|
|
|
break;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-03-29 22:53:15 +00:00
|
|
|
case 'BrtCellBlank': if(!opts.sheetStubs) break;
|
2017-02-10 19:23:01 +00:00
|
|
|
p = ({t:'s',v:undefined}/*:any*/);
|
2014-06-29 18:29:45 +00:00
|
|
|
s[encode_col(C=val[0].c) + rr] = p;
|
2014-03-29 22:53:15 +00:00
|
|
|
if(refguess.s.r > row.r) refguess.s.r = row.r;
|
2014-06-29 18:29:45 +00:00
|
|
|
if(refguess.s.c > C) refguess.s.c = C;
|
2014-03-29 22:53:15 +00:00
|
|
|
if(refguess.e.r < row.r) refguess.e.r = row.r;
|
2014-06-29 18:29:45 +00:00
|
|
|
if(refguess.e.c < C) refguess.e.c = C;
|
2014-03-29 22:53:15 +00:00
|
|
|
break;
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-03-23 21:30:00 +00:00
|
|
|
/* Merge Cells */
|
|
|
|
case 'BrtBeginMergeCells': break;
|
|
|
|
case 'BrtEndMergeCells': break;
|
|
|
|
case 'BrtMergeCell': mergecells.push(val); break;
|
2014-04-15 09:04:03 +00:00
|
|
|
|
|
|
|
case 'BrtHLink':
|
|
|
|
var rel = rels['!id'][val.relId];
|
|
|
|
if(rel) {
|
|
|
|
val.Target = rel.Target;
|
|
|
|
if(val.loc) val.Target += "#"+val.loc;
|
|
|
|
val.Rel = rel;
|
|
|
|
}
|
|
|
|
for(R=val.rfx.s.r;R<=val.rfx.e.r;++R) for(C=val.rfx.s.c;C<=val.rfx.e.c;++C) {
|
|
|
|
addr = encode_cell({c:C,r:R});
|
2014-10-26 05:26:18 +00:00
|
|
|
if(!s[addr]) s[addr] = {t:'s',v:undefined};
|
2014-04-15 09:04:03 +00:00
|
|
|
s[addr].l = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtArrFmla': break; // TODO
|
|
|
|
case 'BrtShrFmla': break; // TODO
|
|
|
|
case 'BrtBeginSheet': break;
|
|
|
|
case 'BrtWsProp': break; // TODO
|
|
|
|
case 'BrtSheetCalcProp': break; // TODO
|
|
|
|
case 'BrtBeginWsViews': break; // TODO
|
|
|
|
case 'BrtBeginWsView': break; // TODO
|
2014-03-19 17:53:20 +00:00
|
|
|
case 'BrtPane': break; // TODO
|
|
|
|
case 'BrtSel': break; // TODO
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtEndWsView': break; // TODO
|
|
|
|
case 'BrtEndWsViews': break; // TODO
|
|
|
|
case 'BrtACBegin': break; // TODO
|
2014-03-19 17:53:20 +00:00
|
|
|
case 'BrtRwDescent': break; // TODO
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtACEnd': break; // TODO
|
|
|
|
case 'BrtWsFmtInfoEx14': break; // TODO
|
|
|
|
case 'BrtWsFmtInfo': break; // TODO
|
|
|
|
case 'BrtBeginColInfos': break; // TODO
|
|
|
|
case 'BrtColInfo': break; // TODO
|
|
|
|
case 'BrtEndColInfos': break; // TODO
|
|
|
|
case 'BrtBeginSheetData': break; // TODO
|
|
|
|
case 'BrtEndSheetData': break; // TODO
|
|
|
|
case 'BrtSheetProtection': break; // TODO
|
|
|
|
case 'BrtPrintOptions': break; // TODO
|
|
|
|
case 'BrtMargins': break; // TODO
|
|
|
|
case 'BrtPageSetup': break; // TODO
|
2014-01-31 11:52:18 +00:00
|
|
|
case 'BrtFRTBegin': pass = true; break;
|
|
|
|
case 'BrtFRTEnd': pass = false; break;
|
2014-01-28 16:38:02 +00:00
|
|
|
case 'BrtEndSheet': break; // TODO
|
2014-03-19 17:53:20 +00:00
|
|
|
case 'BrtDrawing': break; // TODO
|
2014-02-13 06:22:42 +00:00
|
|
|
case 'BrtLegacyDrawing': break; // TODO
|
2014-03-29 02:05:50 +00:00
|
|
|
case 'BrtLegacyDrawingHF': break; // TODO
|
2014-03-19 17:53:20 +00:00
|
|
|
case 'BrtPhoneticInfo': break; // TODO
|
|
|
|
case 'BrtBeginHeaderFooter': break; // TODO
|
|
|
|
case 'BrtEndHeaderFooter': break; // TODO
|
|
|
|
case 'BrtBrk': break; // TODO
|
|
|
|
case 'BrtBeginRwBrk': break; // TODO
|
|
|
|
case 'BrtEndRwBrk': break; // TODO
|
|
|
|
case 'BrtBeginColBrk': break; // TODO
|
|
|
|
case 'BrtEndColBrk': break; // TODO
|
|
|
|
case 'BrtBeginUserShViews': break; // TODO
|
|
|
|
case 'BrtBeginUserShView': break; // TODO
|
|
|
|
case 'BrtEndUserShView': break; // TODO
|
|
|
|
case 'BrtEndUserShViews': break; // TODO
|
|
|
|
case 'BrtBkHim': break; // TODO
|
|
|
|
case 'BrtBeginOleObjects': break; // TODO
|
|
|
|
case 'BrtOleObject': break; // TODO
|
|
|
|
case 'BrtEndOleObjects': break; // TODO
|
|
|
|
case 'BrtBeginListParts': break; // TODO
|
|
|
|
case 'BrtListPart': break; // TODO
|
|
|
|
case 'BrtEndListParts': break; // TODO
|
|
|
|
case 'BrtBeginSortState': break; // TODO
|
|
|
|
case 'BrtBeginSortCond': break; // TODO
|
|
|
|
case 'BrtEndSortCond': break; // TODO
|
|
|
|
case 'BrtEndSortState': break; // TODO
|
|
|
|
case 'BrtBeginConditionalFormatting': break; // TODO
|
|
|
|
case 'BrtEndConditionalFormatting': break; // TODO
|
|
|
|
case 'BrtBeginCFRule': break; // TODO
|
|
|
|
case 'BrtEndCFRule': break; // TODO
|
|
|
|
case 'BrtBeginDVals': break; // TODO
|
|
|
|
case 'BrtDVal': break; // TODO
|
|
|
|
case 'BrtEndDVals': break; // TODO
|
|
|
|
case 'BrtRangeProtection': break; // TODO
|
2014-03-29 02:05:50 +00:00
|
|
|
case 'BrtBeginDCon': break; // TODO
|
|
|
|
case 'BrtEndDCon': break; // TODO
|
|
|
|
case 'BrtBeginDRefs': break;
|
|
|
|
case 'BrtDRef': break;
|
|
|
|
case 'BrtEndDRefs': break;
|
2014-03-21 02:44:27 +00:00
|
|
|
|
|
|
|
/* ActiveX */
|
|
|
|
case 'BrtBeginActiveXControls': break;
|
|
|
|
case 'BrtActiveX': break;
|
|
|
|
case 'BrtEndActiveXControls': break;
|
|
|
|
|
|
|
|
/* AutoFilter */
|
|
|
|
case 'BrtBeginAFilter': break;
|
|
|
|
case 'BrtEndAFilter': break;
|
|
|
|
case 'BrtBeginFilterColumn': break;
|
|
|
|
case 'BrtBeginFilters': break;
|
2014-04-15 09:04:03 +00:00
|
|
|
case 'BrtFilter': break;
|
2014-03-21 02:44:27 +00:00
|
|
|
case 'BrtEndFilters': break;
|
|
|
|
case 'BrtEndFilterColumn': break;
|
|
|
|
case 'BrtDynamicFilter': break;
|
|
|
|
case 'BrtTop10Filter': break;
|
|
|
|
case 'BrtBeginCustomFilters': break;
|
|
|
|
case 'BrtCustomFilter': break;
|
|
|
|
case 'BrtEndCustomFilters': break;
|
|
|
|
|
2014-07-28 13:22:32 +00:00
|
|
|
/* Smart Tags */
|
|
|
|
case 'BrtBeginSmartTags': break;
|
|
|
|
case 'BrtBeginCellSmartTags': break;
|
|
|
|
case 'BrtBeginCellSmartTag': break;
|
|
|
|
case 'BrtCellSmartTagProperty': break;
|
|
|
|
case 'BrtEndCellSmartTag': break;
|
|
|
|
case 'BrtEndCellSmartTags': break;
|
|
|
|
case 'BrtEndSmartTags': break;
|
|
|
|
|
2014-03-29 02:05:50 +00:00
|
|
|
/* Cell Watch */
|
|
|
|
case 'BrtBeginCellWatches': break;
|
|
|
|
case 'BrtCellWatch': break;
|
|
|
|
case 'BrtEndCellWatches': break;
|
|
|
|
|
|
|
|
/* Table */
|
|
|
|
case 'BrtTable': break;
|
|
|
|
|
|
|
|
/* Ignore Cell Errors */
|
|
|
|
case 'BrtBeginCellIgnoreECs': break;
|
|
|
|
case 'BrtCellIgnoreEC': break;
|
|
|
|
case 'BrtEndCellIgnoreECs': break;
|
|
|
|
|
2017-02-10 19:23:01 +00:00
|
|
|
default: if(!pass || opts.WTF) throw new Error("Unexpected record " + Record.n);
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
2014-02-13 06:22:42 +00:00
|
|
|
}, opts);
|
2017-02-10 19:23:01 +00:00
|
|
|
if(!s["!ref"] && (refguess.s.r < 2000000 || ref && (ref.e.r > 0 || ref.e.c > 0 || ref.s.r > 0 || ref.s.c > 0))) s["!ref"] = encode_range(ref || refguess);
|
2014-03-29 22:53:15 +00:00
|
|
|
if(opts.sheetRows && s["!ref"]) {
|
2014-06-29 18:29:45 +00:00
|
|
|
var tmpref = safe_decode_range(s["!ref"]);
|
2014-02-19 03:03:28 +00:00
|
|
|
if(opts.sheetRows < +tmpref.e.r) {
|
|
|
|
tmpref.e.r = opts.sheetRows - 1;
|
|
|
|
if(tmpref.e.r > refguess.e.r) tmpref.e.r = refguess.e.r;
|
|
|
|
if(tmpref.e.r < tmpref.s.r) tmpref.s.r = tmpref.e.r;
|
|
|
|
if(tmpref.e.c > refguess.e.c) tmpref.e.c = refguess.e.c;
|
|
|
|
if(tmpref.e.c < tmpref.s.c) tmpref.s.c = tmpref.e.c;
|
|
|
|
s["!fullref"] = s["!ref"];
|
|
|
|
s["!ref"] = encode_range(tmpref);
|
|
|
|
}
|
|
|
|
}
|
2014-03-23 21:30:00 +00:00
|
|
|
if(mergecells.length > 0) s["!merges"] = mergecells;
|
2014-01-28 16:38:02 +00:00
|
|
|
return s;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-07-28 13:22:32 +00:00
|
|
|
/* TODO: something useful -- this is a stub */
|
2017-02-10 19:23:01 +00:00
|
|
|
function write_ws_bin_cell(ba/*:BufArray*/, cell/*:Cell*/, R/*:number*/, C/*:number*/, opts) {
|
2014-07-28 13:22:32 +00:00
|
|
|
if(cell.v === undefined) return "";
|
|
|
|
var vv = "";
|
|
|
|
switch(cell.t) {
|
|
|
|
case 'b': vv = cell.v ? "1" : "0"; break;
|
|
|
|
case 'n': case 'e': vv = ''+cell.v; break;
|
|
|
|
default: vv = cell.v; break;
|
|
|
|
}
|
2017-02-10 19:23:01 +00:00
|
|
|
var o/*:CellAddress*/ = ({r:R, c:C}/*:any*/);
|
2014-07-28 13:22:32 +00:00
|
|
|
/* TODO: cell style */
|
|
|
|
o.s = get_cell_style(opts.cellXfs, cell, opts);
|
|
|
|
switch(cell.t) {
|
|
|
|
case 's': case 'str':
|
|
|
|
if(opts.bookSST) {
|
|
|
|
vv = get_sst_id(opts.Strings, cell.v);
|
2017-02-03 20:50:45 +00:00
|
|
|
o.t = "s"; o.v = vv;
|
|
|
|
write_record(ba, "BrtCellIsst", write_BrtCellIsst(cell, o));
|
|
|
|
} else {
|
|
|
|
o.t = "str";
|
|
|
|
write_record(ba, "BrtCellSt", write_BrtCellSt(cell, o));
|
2014-07-28 13:22:32 +00:00
|
|
|
}
|
2017-02-03 20:50:45 +00:00
|
|
|
return;
|
|
|
|
case 'n':
|
|
|
|
/* TODO: determine threshold for Real vs RK */
|
|
|
|
if(cell.v == (cell.v | 0) && cell.v > -1000 && cell.v < 1000) write_record(ba, "BrtCellRk", write_BrtCellRk(cell, o));
|
|
|
|
else write_record(ba, "BrtCellReal", write_BrtCellReal(cell, o));
|
|
|
|
return;
|
|
|
|
case 'b':
|
|
|
|
o.t = "b";
|
|
|
|
write_record(ba, "BrtCellBool", write_BrtCellBool(cell, o));
|
|
|
|
return;
|
|
|
|
case 'e': /* TODO: error */ o.t = "e"; break;
|
2014-07-28 13:22:32 +00:00
|
|
|
}
|
|
|
|
write_record(ba, "BrtCellBlank", write_BrtCellBlank(cell, o));
|
|
|
|
}
|
|
|
|
|
2014-05-29 22:30:03 +00:00
|
|
|
function write_CELLTABLE(ba, ws, idx, opts, wb) {
|
2014-07-28 13:22:32 +00:00
|
|
|
var range = safe_decode_range(ws['!ref'] || "A1"), ref, rr = "", cols = [];
|
2014-05-29 22:30:03 +00:00
|
|
|
write_record(ba, 'BrtBeginSheetData');
|
2014-07-28 13:22:32 +00:00
|
|
|
for(var R = range.s.r; R <= range.e.r; ++R) {
|
|
|
|
rr = encode_row(R);
|
2014-05-29 22:30:03 +00:00
|
|
|
/* [ACCELLTABLE] */
|
|
|
|
/* BrtRowHdr */
|
2017-02-03 20:50:45 +00:00
|
|
|
write_row_header(ba, ws, range, R);
|
2014-07-28 13:22:32 +00:00
|
|
|
for(var C = range.s.c; C <= range.e.c; ++C) {
|
|
|
|
/* *16384CELL */
|
|
|
|
if(R === range.s.r) cols[C] = encode_col(C);
|
|
|
|
ref = cols[C] + rr;
|
|
|
|
if(!ws[ref]) continue;
|
|
|
|
/* write cell */
|
|
|
|
write_ws_bin_cell(ba, ws[ref], R, C, opts);
|
|
|
|
}
|
2014-05-29 22:30:03 +00:00
|
|
|
}
|
|
|
|
write_record(ba, 'BrtEndSheetData');
|
|
|
|
}
|
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function write_ws_bin(idx, opts, wb) {
|
2014-05-29 22:30:03 +00:00
|
|
|
var ba = buf_array();
|
|
|
|
var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
|
2014-06-29 18:29:45 +00:00
|
|
|
var r = safe_decode_range(ws['!ref'] || "A1");
|
2014-05-29 22:30:03 +00:00
|
|
|
write_record(ba, "BrtBeginSheet");
|
|
|
|
/* [BrtWsProp] */
|
|
|
|
write_record(ba, "BrtWsDim", write_BrtWsDim(r));
|
|
|
|
/* [WSVIEWS2] */
|
|
|
|
/* [WSFMTINFO] */
|
|
|
|
/* *COLINFOS */
|
|
|
|
write_CELLTABLE(ba, ws, idx, opts, wb);
|
|
|
|
/* [BrtSheetCalcProp] */
|
|
|
|
/* [[BrtSheetProtectionIso] BrtSheetProtection] */
|
|
|
|
/* *([BrtRangeProtectionIso] BrtRangeProtection) */
|
|
|
|
/* [SCENMAN] */
|
|
|
|
/* [AUTOFILTER] */
|
|
|
|
/* [SORTSTATE] */
|
|
|
|
/* [DCON] */
|
|
|
|
/* [USERSHVIEWS] */
|
|
|
|
/* [MERGECELLS] */
|
|
|
|
/* [BrtPhoneticInfo] */
|
|
|
|
/* *CONDITIONALFORMATTING */
|
|
|
|
/* [DVALS] */
|
|
|
|
/* *BrtHLink */
|
|
|
|
/* [BrtPrintOptions] */
|
|
|
|
/* [BrtMargins] */
|
|
|
|
/* [BrtPageSetup] */
|
|
|
|
/* [HEADERFOOTER] */
|
|
|
|
/* [RWBRK] */
|
|
|
|
/* [COLBRK] */
|
|
|
|
/* *BrtBigName */
|
|
|
|
/* [CELLWATCHES] */
|
|
|
|
/* [IGNOREECS] */
|
|
|
|
/* [SMARTTAGS] */
|
|
|
|
/* [BrtDrawing] */
|
|
|
|
/* [BrtLegacyDrawing] */
|
|
|
|
/* [BrtLegacyDrawingHF] */
|
|
|
|
/* [BrtBkHim] */
|
|
|
|
/* [OLEOBJECTS] */
|
|
|
|
/* [ACTIVEXCONTROLS] */
|
|
|
|
/* [WEBPUBITEMS] */
|
|
|
|
/* [LISTPARTS] */
|
|
|
|
/* FRTWORKSHEET */
|
|
|
|
write_record(ba, "BrtEndSheet");
|
|
|
|
return ba.end();
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|