2015-04-02 20:32:22 +00:00
|
|
|
/* XLS ranges enforced */
|
2017-05-13 18:21:22 +00:00
|
|
|
function shift_cell_xls(cell/*:CellAddress*/, tgt/*:any*/, opts/*:?any*/)/*:CellAddress*/ {
|
2017-02-19 20:36:32 +00:00
|
|
|
var out = dup(cell);
|
2015-04-02 20:32:22 +00:00
|
|
|
if(tgt.s) {
|
2017-02-19 20:36:32 +00:00
|
|
|
if(out.cRel) out.c += tgt.s.c;
|
|
|
|
if(out.rRel) out.r += tgt.s.r;
|
2015-04-02 20:32:22 +00:00
|
|
|
} else {
|
2018-01-09 07:36:02 +00:00
|
|
|
if(out.cRel) out.c += tgt.c;
|
|
|
|
if(out.rRel) out.r += tgt.r;
|
2015-04-02 20:32:22 +00:00
|
|
|
}
|
2017-02-19 20:36:32 +00:00
|
|
|
if(!opts || opts.biff < 12) {
|
|
|
|
while(out.c >= 0x100) out.c -= 0x100;
|
|
|
|
while(out.r >= 0x10000) out.r -= 0x10000;
|
|
|
|
}
|
|
|
|
return out;
|
2015-04-02 20:32:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 08:39:51 +00:00
|
|
|
function shift_range_xls(cell, range, opts) {
|
|
|
|
var out = dup(cell);
|
|
|
|
out.s = shift_cell_xls(out.s, range.s, opts);
|
|
|
|
out.e = shift_cell_xls(out.e, range.s, opts);
|
|
|
|
return out;
|
2015-04-02 20:32:22 +00:00
|
|
|
}
|
|
|
|
|
2018-02-21 07:01:34 +00:00
|
|
|
function encode_cell_xls(c/*:CellAddress*/, biff/*:number*/)/*:string*/ {
|
|
|
|
if(c.cRel && c.c < 0) { c = dup(c); c.c += (biff > 8) ? 0x4000 : 0x100; }
|
|
|
|
if(c.rRel && c.r < 0) { c = dup(c); c.r += (biff > 8) ? 0x100000 : ((biff > 5) ? 0x10000 : 0x4000); }
|
2017-02-19 20:36:32 +00:00
|
|
|
var s = encode_cell(c);
|
|
|
|
if(c.cRel === 0) s = fix_col(s);
|
|
|
|
if(c.rRel === 0) s = fix_row(s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2017-03-10 08:39:51 +00:00
|
|
|
function encode_range_xls(r, opts)/*:string*/ {
|
|
|
|
if(r.s.r == 0 && !r.s.rRel) {
|
2018-02-21 07:01:34 +00:00
|
|
|
if(r.e.r == (opts.biff >= 12 ? 0xFFFFF : (opts.biff >= 8 ? 0x10000 : 0x4000)) && !r.e.rRel) {
|
2017-03-10 08:39:51 +00:00
|
|
|
return (r.s.cRel ? "" : "$") + encode_col(r.s.c) + ":" + (r.e.cRel ? "" : "$") + encode_col(r.e.c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(r.s.c == 0 && !r.s.cRel) {
|
2017-07-27 20:07:51 +00:00
|
|
|
if(r.e.c == (opts.biff >= 12 ? 0xFFFF : 0xFF) && !r.e.cRel) {
|
2017-03-10 08:39:51 +00:00
|
|
|
return (r.s.rRel ? "" : "$") + encode_row(r.s.r) + ":" + (r.e.rRel ? "" : "$") + encode_row(r.e.r);
|
|
|
|
}
|
|
|
|
}
|
2018-02-21 07:01:34 +00:00
|
|
|
return encode_cell_xls(r.s, opts.biff) + ":" + encode_cell_xls(r.e, opts.biff);
|
2017-02-19 20:36:32 +00:00
|
|
|
}
|