Parses a spreadsheetlike CSV file and evaluates each cell by
-
Each cell is an expression in postfix notation (see Wikipedia).
-
Each token in the expression will be separated by one or more spaces.
-
One cell can refer to another cell with the {LETTER}{NUMBER} notation (e.g. “A2”, “B4”– letters refer to columns, numbers to rows).
-
Expressions may include the basic arithmetic operators +, , *, /
This program should output another CSV file of the same dimensions containing the results
of evaluating each cell to its final value. If any cell is an invalid expression, then for that cell
For example, for the following CSV input:
b1 b2 +,2 b2 3 * ,3 ,+
a1 ,5 , ,7 2 /
c2 3 * ,1 2 , ,5 1 2 + 4 * + 3
...output something like:
8,13,3,#ERR
0,#ERR,0,14
npm install -g spreadsheet-expr
spe {source csv file path} {output csv file path}
nodejs 4.x
npm run build
nm lint
npm run test
npm run coverage
This is a result of a programming task, please do not use this tool in production.
The design of this tool is pretty straightforward,
-
Data parse into a 2 dimensional array (csvData), after reading from the input file
[ [A1],[B1],[C1], [A2],[B2],[C2] ]
-
Process content of each cells via the
rpn expression engine
-
Save execution result to a new 2 dimensional array (resultData)
-
Finally, un-parse resultData to a string and write it to output file.