spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Pulling out A1CellKey, Cell into class files
author
Ben Vogt <[email protected]>
date
2016-12-27 18:56:06
stats
3 file(s) changed, 82 insertions(+), 83 deletions(-)
files
ts/A1CellKey.ts
ts/Cell.ts
ts/Sheet.ts
  1diff --git a/ts/A1CellKey.ts b/ts/A1CellKey.ts
  2new file mode 100644
  3index 0000000..bc1e136
  4--- /dev/null
  5+++ b/ts/A1CellKey.ts
  6@@ -0,0 +1,49 @@
  7+/**
  8+ * A1-notation style cell id. Used to index the cells.
  9+ * */
 10+class A1CellKey {
 11+  private column: string;
 12+  private row: number;
 13+  private x: number;
 14+  private y: number;
 15+
 16+  constructor(key: string) {
 17+    this.row = parseInt(key.match(/\d+$/)[0], 10);
 18+    this.column = key.replace(this.row.toString(), '');
 19+    this.x = lettersToNumber(this.column);
 20+    this.y = this.row - 1;
 21+  }
 22+  static of(x: number, y: number): A1CellKey {
 23+    return new A1CellKey(numberToLetters(x+1) + (y+1).toString());
 24+  }
 25+  toString(): string {
 26+    return this.column + "" + this.row;
 27+  }
 28+  getColumn(): string {
 29+    return this.column;
 30+  }
 31+  getRow(): number {
 32+    return this.row;
 33+  }
 34+  getX(): number {
 35+    return this.x;
 36+  }
 37+  getY(): number {
 38+    return this.y;
 39+  }
 40+}
 41+
 42+function lettersToNumber(letters: string): number {
 43+  return letters.toLowerCase().charCodeAt(0) - 97;
 44+}
 45+
 46+function numberToLetters(num: number): string {
 47+  let mod = num % 26,
 48+    pow = num / 26 | 0,
 49+    out = mod ? String.fromCharCode(64 + mod) : (--pow, 'Z');
 50+  return pow ? numberToLetters(pow) + out : out;
 51+}
 52+
 53+export {
 54+  A1CellKey
 55+}
 56\ No newline at end of file
 57diff --git a/ts/Cell.ts b/ts/Cell.ts
 58new file mode 100644
 59index 0000000..501b904
 60--- /dev/null
 61+++ b/ts/Cell.ts
 62@@ -0,0 +1,33 @@
 63+class Cell {
 64+  public formula: string;
 65+  public value: string;
 66+  public dependencies: Array<string>;
 67+  public error: any;
 68+  public id: string;
 69+  public row: number;
 70+  public col: number;
 71+  constructor(formula: string, id: string) {
 72+    this.formula = formula;
 73+    this.value = "";
 74+    this.dependencies = [];
 75+    this.error = null;
 76+    this.id = id;
 77+  }
 78+  updateDependencies(dependencies: Array<string>) {
 79+    for (var index in dependencies) {
 80+      if (this.dependencies.indexOf(dependencies[index]) === -1) {
 81+        this.dependencies.push(dependencies[index]);
 82+      }
 83+    }
 84+  }
 85+  setValue(value: string) {
 86+    this.value = value;
 87+  }
 88+  setError(error: any) {
 89+    this.error = error;
 90+  }
 91+}
 92+
 93+export {
 94+  Cell
 95+}
 96\ No newline at end of file
 97diff --git a/ts/Sheet.ts b/ts/Sheet.ts
 98index 57607ff..1559b35 100644
 99--- a/ts/Sheet.ts
100+++ b/ts/Sheet.ts
101@@ -1,93 +1,9 @@
102 /// <reference path="parser.d.ts"/>
103 import { Parser } from "./Parser";
104-
105+import { A1CellKey } from "./A1CellKey"
106+import { Cell } from "./Cell"
107 import * as Formula from "formulajs"
108 
109-/**
110- * A1-notation style cell id. Used to index the cells.
111- * */
112-class A1CellKey {
113-  private column: string;
114-  private row: number;
115-  private x: number;
116-  private y: number;
117-
118-  constructor(key: string) {
119-    this.row = parseInt(key.match(/\d+$/)[0], 10);
120-    this.column = key.replace(this.row.toString(), '');
121-    this.x = lettersToNumber(this.column);
122-    this.y = this.row - 1;
123-  }
124-  static of(x: number, y: number): A1CellKey {
125-    return new A1CellKey(numberToLetters(x+1) + (y+1).toString());
126-  }
127-  toString(): string {
128-    return this.column + "" + this.row;
129-  }
130-  getColumn(): string {
131-    return this.column;
132-  }
133-  getRow(): number {
134-    return this.row;
135-  }
136-  getX(): number {
137-    return this.x;
138-  }
139-  getY(): number {
140-    return this.y;
141-  }
142-}
143-
144-function lettersToNumber(letters: string): number {
145-  return letters.toLowerCase().charCodeAt(0) - 97;
146-}
147-
148-function numberToLetters(num: number): string {
149-  let mod = num % 26,
150-    pow = num / 26 | 0,
151-    out = mod ? String.fromCharCode(64 + mod) : (--pow, 'Z');
152-  return pow ? numberToLetters(pow) + out : out;
153-}
154-
155-
156-class Cell {
157-  public formula: string;
158-  public value: string;
159-  public dependencies: Array<string>;
160-  public error: any;
161-  public id: string;
162-  public row: number;
163-  public col: number;
164-  constructor(formula: string, id: string) {
165-    this.formula = formula;
166-    this.value = "";
167-    this.dependencies = [];
168-    this.error = null;
169-    this.id = id;
170-  }
171-  updateDependencies(dependencies: Array<string>) {
172-    for (var index in dependencies) {
173-      if (this.dependencies.indexOf(dependencies[index]) === -1) {
174-        this.dependencies.push(dependencies[index]);
175-      }
176-    }
177-  }
178-  setValue(value: string) {
179-    this.value = value;
180-  }
181-  setError(error: any) {
182-    this.error = error;
183-  }
184-}
185-
186-
187-
188-
189-
190-
191-
192-
193-
194 var Sheet = (function () {
195   'use strict';
196   var instance = this;