|
1 | | -function decode_row(rowstr/*:string*/)/*:number*/ { return parseInt(unfix_row(rowstr),10) - 1; } |
2 | | -function encode_row(row/*:number*/)/*:string*/ { return "" + (row + 1); } |
3 | | -function fix_row(cstr/*:string*/)/*:string*/ { return cstr.replace(/([A-Z]|^)(\d+)$/,"$1$$$2"); } |
4 | | -function unfix_row(cstr/*:string*/)/*:string*/ { return cstr.replace(/\$(\d+)$/,"$1"); } |
5 | | - |
6 | | -function decode_col(colstr/*:string*/)/*:number*/ { var c = unfix_col(colstr), d = 0, i = 0; for(; i !== c.length; ++i) d = 26*d + c.charCodeAt(i) - 64; return d - 1; } |
7 | | -function encode_col(col/*:number*/)/*:string*/ { var s=""; for(++col; col; col=Math.floor((col-1)/26)) s = String.fromCharCode(((col-1)%26) + 65) + s; return s; } |
8 | | -function fix_col(cstr/*:string*/)/*:string*/ { return cstr.replace(/^([A-Z])/,"$$$1"); } |
9 | | -function unfix_col(cstr/*:string*/)/*:string*/ { return cstr.replace(/^\$([A-Z])/,"$1"); } |
10 | | - |
11 | | -function split_cell(cstr/*:string*/)/*:Array<string>*/ { return cstr.replace(/(\$?[A-Z]*)(\$?\d*)/,"$1,$2").split(","); } |
12 | | -function decode_cell(cstr/*:string*/)/*:CellAddress*/ { var splt = split_cell(cstr); return { c:decode_col(splt[0]), r:decode_row(splt[1]) }; } |
13 | | -function encode_cell(cell/*:CellAddress*/)/*:string*/ { return encode_col(cell.c) + encode_row(cell.r); } |
14 | | -function fix_cell(cstr/*:string*/)/*:string*/ { return fix_col(fix_row(cstr)); } |
15 | | -function unfix_cell(cstr/*:string*/)/*:string*/ { return unfix_col(unfix_row(cstr)); } |
16 | | -function decode_range(range/*:string*/)/*:Range*/ { var x =range.split(":").map(decode_cell); return {s:x[0],e:x[x.length-1]}; } |
17 | | -/*# if only one arg, it is assumed to be a Range. If 2 args, both are cell addresses */ |
18 | | -function encode_range(cs/*:CellAddrSpec|Range*/,ce/*:?CellAddrSpec*/)/*:string*/ { |
19 | | - if(typeof ce === 'undefined' || typeof ce === 'number') { |
20 | | -/*:: if(!(cs instanceof Range)) throw "unreachable"; */ |
21 | | - return encode_range(cs.s, cs.e); |
22 | | - } |
23 | | -/*:: if((cs instanceof Range)) throw "unreachable"; */ |
24 | | - if(typeof cs !== 'string') cs = encode_cell((cs/*:any*/)); |
25 | | - if(typeof ce !== 'string') ce = encode_cell((ce/*:any*/)); |
26 | | -/*:: if(typeof cs !== 'string') throw "unreachable"; */ |
27 | | -/*:: if(typeof ce !== 'string') throw "unreachable"; */ |
28 | | - return cs == ce ? cs : cs + ":" + ce; |
29 | | -} |
30 | | - |
31 | | -function safe_decode_range(range/*:string*/)/*:Range*/ { |
32 | | - var o = {s:{c:0,r:0},e:{c:0,r:0}}; |
33 | | - var idx = 0, i = 0, cc = 0; |
34 | | - var len = range.length; |
35 | | - for(idx = 0; i < len; ++i) { |
36 | | - if((cc=range.charCodeAt(i)-64) < 1 || cc > 26) break; |
37 | | - idx = 26*idx + cc; |
38 | | - } |
39 | | - o.s.c = --idx; |
40 | | - |
41 | | - for(idx = 0; i < len; ++i) { |
42 | | - if((cc=range.charCodeAt(i)-48) < 0 || cc > 9) break; |
43 | | - idx = 10*idx + cc; |
44 | | - } |
45 | | - o.s.r = --idx; |
46 | | - |
47 | | - if(i === len || range.charCodeAt(++i) === 58) { o.e.c=o.s.c; o.e.r=o.s.r; return o; } |
48 | | - |
49 | | - for(idx = 0; i != len; ++i) { |
50 | | - if((cc=range.charCodeAt(i)-64) < 1 || cc > 26) break; |
51 | | - idx = 26*idx + cc; |
52 | | - } |
53 | | - o.e.c = --idx; |
54 | | - |
55 | | - for(idx = 0; i != len; ++i) { |
56 | | - if((cc=range.charCodeAt(i)-48) < 0 || cc > 9) break; |
57 | | - idx = 10*idx + cc; |
58 | | - } |
59 | | - o.e.r = --idx; |
60 | | - return o; |
61 | | -} |
62 | | - |
63 | | -function safe_format_cell(cell/*:Cell*/, v/*:any*/) { |
64 | | - var q = (cell.t == 'd' && v instanceof Date); |
65 | | - if(cell.z != null) try { return (cell.w = SSF.format(cell.z, q ? datenum(v) : v)); } catch(e) { } |
66 | | - try { return (cell.w = SSF.format((cell.XF||{}).ifmt||(q ? 14 : 0), q ? datenum(v) : v)); } catch(e) { return ''+v; } |
67 | | -} |
68 | | - |
69 | | -function format_cell(cell/*:Cell*/, v/*:any*/, o/*:any*/) { |
70 | | - if(cell == null || cell.t == null || cell.t == 'z') return ""; |
71 | | - if(cell.w !== undefined) return cell.w; |
72 | | - if(cell.t == 'd' && !cell.z && o && o.dateNF) cell.z = o.dateNF; |
73 | | - if(v == undefined) return safe_format_cell(cell, cell.v, o); |
74 | | - return safe_format_cell(cell, v, o); |
75 | | -} |
76 | | - |
77 | 1 | function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/){ |
78 | 2 | if(sheet == null || sheet["!ref"] == null) return []; |
79 | 3 | var val = {t:'n',v:0}, header = 0, offset = 1, hdr/*:Array<any>*/ = [], isempty = true, v=0, vv=""; |
|
0 commit comments