gcell2cell = function (cell, getValue, useTextValues) { //get formula AND has a formula? if(!getValue && /^=/.test(cell.inputValue)) { //must convert '=RC[-2]+R[3]C[-1]' to '=B5+C8' return cell.inputValue.replace(/(R(\[(-?\d+)\])?)(C(\[(-?\d+)\])?)/g, function() { return exports.int2cell( exports.num(cell.row) + exports.num(arguments[3] || 0), exports.num(cell.col) + exports.num(arguments[6] || 0) ); }); } //get value return (useTextValues) ? exports.num(cell.$t) : exports.num(cell.inputValue); }
...
r = cell.row,
c = cell.col;
if (!rows[r]) {
info.totalRows++;
rows[r] = {};
}
rows[r][c] = util.gcell2cell(cell, options.getValues, _this.opts.useCellTextValues);
info.lastRow = util.num(r);
});
if (entries.length)
info.nextRow = info.lastRow + 1;
_this.log(("Retrieved " + entries.length + " cells and " + info.totalRows + " rows").green);
...
int2cell = function (r, c) { return String.fromCharCode(64+c)+r; }
...
//dereference named cells {{ myCell }}
Spreadsheet.prototype.getNames = function(curr) {
var _this = this;
return curr.val
.replace(/\{\{\s*([\-\w\s]*?)\s*\}\}/g, function(str, name) {
var link = _this.names[name];
if (!link) return _this.log(("WARNING: could not find: " + name).yellow);
return util.int2cell(link.row, link.col);
})
.replace(/\{\{\s*([\-\d]+)\s*,\s*([\-\d]+)\s*\}\}/g, function(both, r, c) {
return util.int2cell(curr.row + util.num(r), curr.col + util.num(c));
});
};
Spreadsheet.prototype.addVal = function(val, row, col) {
...
num = function (obj) { if(obj === undefined) return 0; if(typeof obj === 'number' || typeof obj === 'boolean') return obj; if(typeof obj === 'string') { //ensure that the string is *only* a number if(!/^\-?\d+(\.\d+)?$/.test(obj)) return obj; var res = parseFloat(obj, 10); if(isNaN(res)) return obj; return res; } throw "Invalid number: " + JSON.stringify(obj); }
...
this.obj(cells, 0, 0);
};
Spreadsheet.prototype.arr = function(arr, ro, co) {
var i, j, rows, cols, rs, cs;
// _this.log("Add Array: " + JSON.stringify(arr));
ro = util.num(ro);
co = util.num(co);
rows = arr;
for (i = 0, rs = rows.length; i < rs; ++i) {
cols = rows[i];
if (!_.isArray(cols)) {
this.addVal(cols, i + 1 + ro, 1 + co);
...