spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ROW] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-07-11 00:06:21
stats
8 file(s) changed, 66 insertions(+), 5 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Info.js
src/Formulas/AllFormulas.ts
src/Formulas/Info.ts
tests/Formulas/InfoTest.ts
tests/SheetFormulaTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 1b2844b..1cc745c 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -692,6 +692,14 @@
  6 @param cell - Cell, defaults to the cell calling this formula, when used in the context of a spreadsheet. 
  7 @constructor
  8 ```
  9+
 10+### ROW 
 11+
 12+```
 13+  Returns the row number of a specified cell, starting with row 1 for A1. 
 14+@param cell - Cell, defaults to the cell calling this formula, when used in the context of a spreadsheet. 
 15+@constructor
 16+```
 17 ## Logical
 18 
 19 
 20diff --git a/TODO.md b/TODO.md
 21index 884fa24..5ce3f92 100644
 22--- a/TODO.md
 23+++ b/TODO.md
 24@@ -48,7 +48,6 @@ Many of these formulas can be written by allowing the Sheet and Parser to return
 25 * LOOKUP
 26 * MATCH
 27 * OFFSET
 28-* ROW
 29 * ROWS
 30 * VLOOKUP
 31 * COUNTBLANK - Requires changes to to Parser/Sheet so when we iterate through a range to return an array, we call a special function that accumulates all values, blank/null/undefined or otherwise.
 32diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 33index c1165bc..cf0a251 100644
 34--- a/dist/Formulas/AllFormulas.js
 35+++ b/dist/Formulas/AllFormulas.js
 36@@ -97,6 +97,7 @@ exports.ISNA = Info_1.ISNA;
 37 exports.IFERROR = Info_1.IFERROR;
 38 exports.TYPE = Info_1.TYPE;
 39 exports.COLUMN = Info_1.COLUMN;
 40+exports.ROW = Info_1.ROW;
 41 var Lookup_1 = require("./Lookup");
 42 exports.CHOOSE = Lookup_1.CHOOSE;
 43 var Logical_1 = require("./Logical");
 44diff --git a/dist/Formulas/Info.js b/dist/Formulas/Info.js
 45index 682b230..178afae 100644
 46--- a/dist/Formulas/Info.js
 47+++ b/dist/Formulas/Info.js
 48@@ -333,3 +333,16 @@ var COLUMN = function (cell) {
 49     return cell.getColumn() + 1;
 50 };
 51 exports.COLUMN = COLUMN;
 52+/**
 53+ * Returns the row number of a specified cell, starting with row 1 for A1.
 54+ * @param cell - Cell, defaults to the cell calling this formula, when used in the context of a spreadsheet.
 55+ * @constructor
 56+ */
 57+var ROW = function (cell) {
 58+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "ROW");
 59+    if (!(cell instanceof Cell_1.Cell)) {
 60+        throw new Errors_1.NAError("Argument must be a range or reference.");
 61+    }
 62+    return cell.getRow() + 1;
 63+};
 64+exports.ROW = ROW;
 65diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 66index 266c9a4..86b8bee 100644
 67--- a/src/Formulas/AllFormulas.ts
 68+++ b/src/Formulas/AllFormulas.ts
 69@@ -96,7 +96,8 @@ import {
 70   ISNA,
 71   IFERROR,
 72   TYPE,
 73-  COLUMN
 74+  COLUMN,
 75+  ROW
 76 } from "./Info";
 77 import {
 78   CHOOSE
 79@@ -443,5 +444,6 @@ export {
 80   ISNA,
 81   IFERROR,
 82   TYPE,
 83-  COLUMN
 84+  COLUMN,
 85+  ROW
 86 }
 87\ No newline at end of file
 88diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
 89index 58d0236..6831656 100644
 90--- a/src/Formulas/Info.ts
 91+++ b/src/Formulas/Info.ts
 92@@ -353,6 +353,20 @@ var COLUMN =  function (cell) {
 93 };
 94 
 95 
 96+/**
 97+ * Returns the row number of a specified cell, starting with row 1 for A1.
 98+ * @param cell - Cell, defaults to the cell calling this formula, when used in the context of a spreadsheet.
 99+ * @constructor
100+ */
101+var ROW =  function (cell) {
102+  ArgsChecker.checkLength(arguments, 1, "ROW");
103+  if (!(cell instanceof Cell)) {
104+    throw new NAError("Argument must be a range or reference.");
105+  }
106+  return cell.getRow() + 1;
107+};
108+
109+
110 export {
111   NA,
112   ISTEXT,
113@@ -370,5 +384,6 @@ export {
114   ISNA,
115   IFERROR,
116   TYPE,
117-  COLUMN
118+  COLUMN,
119+  ROW
120 }
121\ No newline at end of file
122diff --git a/tests/Formulas/InfoTest.ts b/tests/Formulas/InfoTest.ts
123index 038912a..ebeb050 100644
124--- a/tests/Formulas/InfoTest.ts
125+++ b/tests/Formulas/InfoTest.ts
126@@ -15,7 +15,8 @@ import {
127   ISNA,
128   IFERROR,
129   TYPE,
130-  COLUMN
131+  COLUMN,
132+  ROW
133 } from "../../src/Formulas/Info";
134 import * as ERRORS from "../../src/Errors";
135 import {
136@@ -260,6 +261,7 @@ test("TYPE", function(){
137 
138 test("COLUMN", function(){
139   assertEquals(COLUMN(new Cell("A1")), 1);
140+  assertEquals(COLUMN(new Cell("A2")), 1);
141   assertEquals(COLUMN(new Cell("B1")), 2);
142   assertEquals(COLUMN(new Cell("C1")), 3);
143   catchAndAssertEquals(function() {
144@@ -269,3 +271,16 @@ test("COLUMN", function(){
145     COLUMN.apply(this, [])
146   }, ERRORS.NA_ERROR);
147 });
148+
149+test("ROW", function(){
150+  assertEquals(ROW(new Cell("A1")), 1);
151+  assertEquals(ROW(new Cell("A2")), 2);
152+  assertEquals(ROW(new Cell("A3")), 3);
153+  assertEquals(ROW(new Cell("M3")), 3);
154+  catchAndAssertEquals(function() {
155+    ROW(10)
156+  }, ERRORS.NA_ERROR);
157+  catchAndAssertEquals(function() {
158+    ROW.apply(this, [])
159+  }, ERRORS.NA_ERROR);
160+});
161diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
162index 074a5d3..1fe1496 100644
163--- a/tests/SheetFormulaTest.ts
164+++ b/tests/SheetFormulaTest.ts
165@@ -873,6 +873,11 @@ test("Sheet COLUMN", function(){
166   assertFormulaEqualsDependsOnReference('D1', 10, '=COLUMN(D1)', 4);
167 });
168 
169+test("Sheet ROW", function(){
170+  assertFormulaEqualsDependsOnReference('D2', 10, '=ROW(D2)', 2);
171+});
172+
173+
174 test("Sheet *", function(){
175   assertFormulaEquals('= 10 * 10', 100);
176   assertFormulaEquals('= 10 * 0', 0);