2015-04-02 20:32:22 +00:00
|
|
|
/* TODO: it will be useful to parse the function str */
|
|
|
|
var rc_to_a1 = (function(){
|
2019-11-01 03:09:14 +00:00
|
|
|
var rcregex = /(^|[^A-Za-z_])R(\[?-?\d+\]|[1-9]\d*|)C(\[?-?\d+\]|[1-9]\d*|)(?![A-Za-z0-9_])/g;
|
2017-04-16 04:32:13 +00:00
|
|
|
var rcbase/*:Cell*/ = ({r:0,c:0}/*:any*/);
|
2019-11-01 03:09:14 +00:00
|
|
|
function rcfunc($$,$1,$2,$3) {
|
2017-02-19 20:36:32 +00:00
|
|
|
var cRel = false, rRel = false;
|
2019-11-01 03:09:14 +00:00
|
|
|
|
|
|
|
if($2.length == 0) rRel = true;
|
|
|
|
else if($2.charAt(0) == "[") { rRel = true; $2 = $2.slice(1, -1); }
|
|
|
|
|
|
|
|
if($3.length == 0) cRel = true;
|
|
|
|
else if($3.charAt(0) == "[") { cRel = true; $3 = $3.slice(1, -1); }
|
|
|
|
|
|
|
|
var R = $2.length>0?parseInt($2,10)|0:0, C = $3.length>0?parseInt($3,10)|0:0;
|
|
|
|
|
|
|
|
if(cRel) C += rcbase.c; else --C;
|
|
|
|
if(rRel) R += rcbase.r; else --R;
|
2017-02-19 20:36:32 +00:00
|
|
|
return $1 + (cRel ? "" : "$") + encode_col(C) + (rRel ? "" : "$") + encode_row(R);
|
2015-04-02 20:32:22 +00:00
|
|
|
}
|
2017-04-16 04:32:13 +00:00
|
|
|
return function rc_to_a1(fstr/*:string*/, base/*:Cell*/)/*:string*/ {
|
2015-04-02 20:32:22 +00:00
|
|
|
rcbase = base;
|
|
|
|
return fstr.replace(rcregex, rcfunc);
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2017-03-13 06:46:37 +00:00
|
|
|
var crefregex = /(^|[^._A-Z0-9])([$]?)([A-Z]{1,2}|[A-W][A-Z]{2}|X[A-E][A-Z]|XF[A-D])([$]?)([1-9]\d{0,5}|10[0-3]\d{4}|104[0-7]\d{3}|1048[0-4]\d{2}|10485[0-6]\d|104857[0-6])(?![_.\(A-Za-z0-9])/g;
|
2017-03-14 08:19:51 +00:00
|
|
|
var a1_to_rc =(function(){
|
2018-01-09 07:36:02 +00:00
|
|
|
return function a1_to_rc(fstr/*:string*/, base/*:CellAddress*/) {
|
2018-01-23 09:07:51 +00:00
|
|
|
return fstr.replace(crefregex, function($0, $1, $2, $3, $4, $5) {
|
2018-01-09 07:36:02 +00:00
|
|
|
var c = decode_col($3) - ($2 ? 0 : base.c);
|
|
|
|
var r = decode_row($5) - ($4 ? 0 : base.r);
|
|
|
|
var R = (r == 0 ? "" : !$4 ? "[" + r + "]" : (r+1));
|
|
|
|
var C = (c == 0 ? "" : !$2 ? "[" + c + "]" : (c+1));
|
|
|
|
return $1 + "R" + R + "C" + C;
|
2017-03-14 08:19:51 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
/* no defined name can collide with a valid cell address A1:XFD1048576 ... except LOG10! */
|
2017-02-19 20:36:32 +00:00
|
|
|
function shift_formula_str(f/*:string*/, delta/*:Cell*/)/*:string*/ {
|
2018-01-23 09:07:51 +00:00
|
|
|
return f.replace(crefregex, function($0, $1, $2, $3, $4, $5) {
|
2017-02-19 20:36:32 +00:00
|
|
|
return $1+($2=="$" ? $2+$3 : encode_col(decode_col($3)+delta.c))+($4=="$" ? $4+$5 : encode_row(decode_row($5) + delta.r));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function shift_formula_xlsx(f/*:string*/, range/*:string*/, cell/*:string*/)/*:string*/ {
|
|
|
|
var r = decode_range(range), s = r.s, c = decode_cell(cell);
|
|
|
|
var delta = {r:c.r - s.r, c:c.c - s.c};
|
|
|
|
return shift_formula_str(f, delta);
|
|
|
|
}
|
2017-08-18 18:10:18 +00:00
|
|
|
|
|
|
|
/* TODO: parse formula */
|
|
|
|
function fuzzyfmla(f/*:string*/)/*:boolean*/ {
|
|
|
|
if(f.length == 1) return false;
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-30 05:40:35 +00:00
|
|
|
|
|
|
|
function _xlfn(f/*:string*/)/*:string*/ {
|
|
|
|
return f.replace(/_xlfn\./g,"");
|
|
|
|
}
|