spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Fixing up usages of instance where we don't need it
author
Ben Vogt <[email protected]>
date
2016-12-30 23:03:03
stats
2 file(s) changed, 17 insertions(+), 20 deletions(-)
files
src/Main.ts
src/Sheet.ts
  1diff --git a/src/Main.ts b/src/Main.ts
  2index 76d91c0..c8b141b 100644
  3--- a/src/Main.ts
  4+++ b/src/Main.ts
  5@@ -2,4 +2,4 @@ import { Sheet } from "./Sheet"
  6 
  7 var sheet = new Sheet();
  8 sheet.load();
  9-sheet.toString();
 10+console.log(sheet.toString());
 11diff --git a/src/Sheet.ts b/src/Sheet.ts
 12index 7c3bbce..139931f 100644
 13--- a/src/Sheet.ts
 14+++ b/src/Sheet.ts
 15@@ -53,10 +53,6 @@ var Sheet = (function () {
 16     addItem(cell: Cell) {
 17       var cellId = cell.id;
 18       var key = new A1CellKey(cellId);
 19-      var coords = instance.utils.cellCoords(cellId);
 20-
 21-      cell.row = coords.row;
 22-      cell.col = coords.col;
 23 
 24       if (!(cellId in this.data)) {
 25         this.data[cellId] = cell;
 26@@ -136,7 +132,6 @@ var Sheet = (function () {
 27     var parsed = parse(cell.formula, cell.id);
 28     var key =  new A1CellKey(cell.id);
 29 
 30-    // instance.matrix.updateCellItem(key, {value: value, error: error});
 31     instance.matrix.getItem(key).setValue(parsed.result);
 32     instance.matrix.getItem(key).setError(parsed.error);
 33 
 34@@ -174,11 +169,11 @@ var Sheet = (function () {
 35     },
 36 
 37     isSet: function (value) {
 38-      return !instance.utils.isUndefined(value) && !instance.utils.isNull(value);
 39+      return !utils.isUndefined(value) && !utils.isNull(value);
 40     },
 41 
 42     toNum: function (chr) {
 43-      chr = instance.utils.clearFormula(chr);
 44+      chr = utils.clearFormula(chr);
 45       var base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', i, j, result = 0;
 46 
 47       for (i = 0, j = chr.length - 1; i < chr.length; i += 1, j -= 1) {
 48@@ -217,7 +212,7 @@ var Sheet = (function () {
 49 
 50       return {
 51         row: parseInt(num[0], 10) - 1,
 52-        col: instance.utils.toNum(alpha)
 53+        col: utils.toNum(alpha)
 54       };
 55     },
 56 
 57@@ -267,7 +262,7 @@ var Sheet = (function () {
 58 
 59       for (var column = cols.start; column <= cols.end; column++) {
 60         for (var row = rows.start; row <= rows.end; row++) {
 61-          var cellIndex = instance.utils.toChar(column) + (row + 1),
 62+          var cellIndex = utils.toChar(column) + (row + 1),
 63             cellValue = instance.helper.cellValue.call(this, cellIndex);
 64 
 65           result.index.push(cellIndex);
 66@@ -275,7 +270,7 @@ var Sheet = (function () {
 67         }
 68       }
 69 
 70-      if (instance.utils.isFunction(callback)) {
 71+      if (utils.isFunction(callback)) {
 72         return callback.apply(callback, [result]);
 73       } else {
 74         return result;
 75@@ -448,7 +443,6 @@ var Sheet = (function () {
 76       // get value
 77       value = item ? item.value : "0"; // TODO: fix this, it's sloppy.
 78       //update dependencies
 79-      // instance.matrix.updateCellItem(new A1CellKey(origin), {deps: [cell]});
 80       instance.matrix.getItem(new A1CellKey(origin)).updateDependencies([cell]);
 81       // check references error
 82       if (item && item.dependencies) {
 83@@ -463,7 +457,7 @@ var Sheet = (function () {
 84       }
 85 
 86       // return value if is set
 87-      if (instance.utils.isSet(value)) {
 88+      if (utils.isSet(value)) {
 89         var result = instance.helper.number(value);
 90 
 91         return !isNaN(result) ? result : value;
 92@@ -474,8 +468,8 @@ var Sheet = (function () {
 93     },
 94 
 95     cellRangeValue: function (start: string, end: string) {
 96-      var coordsStart = instance.utils.cellCoords(start),
 97-        coordsEnd = instance.utils.cellCoords(end),
 98+      var coordsStart = utils.cellCoords(start),
 99+        coordsEnd = utils.cellCoords(end),
100         origin = this;
101 
102       // iterate cells to get values and indexes
103@@ -545,7 +539,8 @@ var Sheet = (function () {
104       [-1, -10, 2, 4, 100, 1, 50, 20, 200, -100, "MAX(A2:J2)"],
105       [-1, -40, -53, 1, 10, 30, 10, 301, -1, -20, "MIN(A3:J3)"],
106       [20, 50, 100, 20, 1, 5, 15, 25, 45, 23, "AVERAGE(A4:J4)"],
107-      [0, 10, 1, 10, 2, 10, 3, 10, 4, 10, "SUMIF(A5:J5,'>5')"]
108+      [0, 10, 1, 10, 2, 10, 3, 10, 4, 10, "SUMIF(A5:J5,'>5')"],
109+      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "SUM(K1, K2, K3, K4)"]
110     ];
111     for (var y = 0; y < input.length; y++) {
112       for (var x = 0; x < input[0].length; x++) {
113@@ -557,9 +552,11 @@ var Sheet = (function () {
114   };
115 
116   this.toString = function () {
117+    var toReturn = "";
118     for (var key in this.matrix.data) {
119-      console.log(this.matrix.data[key].id, this.matrix.data[key].formula, this.matrix.data[key].value);
120+      toReturn += this.matrix.data[key].id + " " + this.matrix.data[key].formula + " " + this.matrix.data[key].value + "\n";
121     }
122+    return toReturn;
123   };
124 
125   parser  = FormulaParser(instance);