

Excel formulas in JavaScript  - clxl
https://github.com/sutoiku/formula.js

======
nathell
Any support for i18n?

(For English-only speakers: Excel's translation to other languages goes as far
as translating function names, thus rendering non-English Excel users'
knowledge useless when confronted with an English Excel. E.g.,
IF(ROUND(A1)=1,B1,C1) in English Excel is JEŻELI(ZAOKR.DO.CAŁK(A1)=1,B1,C1) in
Polish Excel -- yes, with all those funky non-ASCII letters.)

~~~
brudgers
Every time I read some comment about how people shouldn't use excel for
complex calculations and should use relational databases or Python or whatever
else, I'll know why it will never happen.

It's really easy to implement the easy parts of spreadsheets, getting the hard
parts right is why Excel continues to dominate the space.

~~~
nhebb
Most spreadsheets I've dealt with don't hold relational data. Are there people
who use them as such? Sure. But I don't think that's the typical use case.

~~~
recursive
I would say relational data is the dominant use case for spreadsheets. It's a
natural fit given the rows and columns. What other kind of data do you see in
spreadsheets? Hierarchical data is not a great fit for spreadsheets.

------
dhotson
Very cool!

Slightly related... I reckon a command line / ncurses version of Excel would
be really useful. Am I crazy?

e.g. something like
[http://upload.wikimedia.org/wikipedia/en/e/ec/Lotus-123-3.0-...](http://upload.wikimedia.org/wikipedia/en/e/ec/Lotus-123-3.0-dos.png)

Spreadsheets are a pretty useful and powerful tool when it comes to doing ad-
hoc data analysis, but it's kind of annoying to get data in and out of them
from command line tools.

~~~
DanBC
Fat-finger errors are already terrifying in spreadsheets. How would you help
prevent them in command line tools?

~~~
dhotson
Isn't that true for a lot of tools? Including programming languages?

------
brudgers
I honestly admire the thought and effort that went into it.

I fear that JavaScript's use of floating point as its single numeric type is
likely to create surprising results for the unwary. I have come to the
suspicion that the longevity of Excel's dominance is in part due to a
sophisticated system for inferring numeric types.

~~~
clxl
Excel only supports numbers that fit in an IEEE754 double, just like
JavaScript.

There is some fancy logic to format numbers, however (including some mess for
date codes). [http://oss.sheetjs.com/ssf/](http://oss.sheetjs.com/ssf/) is a
pretty decent implementation in JavaScript.

~~~
brudgers
All versions of Excel have native support for integers.

[http://msdn.microsoft.com/en-
us/library/office/bb687869%28v=...](http://msdn.microsoft.com/en-
us/library/office/bb687869%28v=office.15%29.aspx)

~~~
clxl
Excel supports 32 bit integers, which fit comfortably in IEEE754 doubles
(there are 64 bit integers which cannot be exactly represented)

------
Aardwolf
I've been trying to find which js file has the actual meat of the
implementation, but didn't manage to find it. function.js seems the biggest
candidate, but didn't contain that much. The rest are all minified other JS
libraries or bootstrapping. Any hint on where the actual mapping of names to
formulas, and implementation of the formulas, is? Thanks.

As for the unimplemented.js formulas, for Gamma you could use the lanczos
approximation, it's easy to convert the C code of it which you can find on the
internet, to JS.

~~~
frik
[https://raw.githubusercontent.com/sutoiku/formula.js/master/...](https://raw.githubusercontent.com/sutoiku/formula.js/master/lib/formula.js)

------
khc
This reminds me of my college days. At Statistical Computing Facility at UC
Berkeley, a grad student and I (I just finished 1st year at the time) built a
web-based spreadsheet for tracking students' homework and exam scores. We
called it StatGrades. One feature that it had was that you could write
javascript for each column for calculation/validation. I looked at the excel
help docs and implemented most of the relevant/useful functions, so people
could do something like:

AVERAGE(homework1, homework2) * 0.2 + AVERAGE(exam1, exam2) * 0.8

for the final grade. We used rhino for javascript and the service was built on
jsp/servlet. It also had access controls so different readers/GSIs had access
to different students and columns, and students could see their own grades.
Everyone hated Blackboard and loved what we built, but unfortunately they
couldn't find anyone to maintain it after I graduated (I was the only person
working on it shortly after I joined). The service was shutdown a couple years
after I left.

------
ozh
Well done, but I fail at seeing how that could be useful?

~~~
clxl
Stringing this together with other libraries like
[http://github.com/warpech/jquery-
handsontable](http://github.com/warpech/jquery-handsontable) and
[http://github.com/SheetJS/js-xlsx](http://github.com/SheetJS/js-xlsx) and
[http://github.com/SheetJS/js-xls](http://github.com/SheetJS/js-xls) could
lead to a better web spreadsheet.

EDIT: someone already thought about combining those libraries:
[http://SheetJS.github.io](http://SheetJS.github.io)

~~~
SunboX
There's a really nice XLSX reader and writer by Stephen Hardy, a Microsoft
developer: [https://github.com/stephen-
hardy/xlsx.js/](https://github.com/stephen-hardy/xlsx.js/) blog post:
[http://blog.innovatejs.com/?p=24](http://blog.innovatejs.com/?p=24)

~~~
clxl
I looked at that project but it uses a really strange non-free license that
should be avoided. [https://github.com/stephen-
hardy/xlsx.js/issues/8](https://github.com/stephen-hardy/xlsx.js/issues/8)

------
maartenba
Cool! Pretty similar to what www.phpexcel.net does for PHP.

------
chiph
They even included IRR, which is pretty impressive.

~~~
personZ
IRR is one of those things that is remarkably simple to calculate and grok,
but is made difficult in the number of _horrendous_ instructions across the
web, many of them simply wrong. Until I corrected it the NPV entry on
Wikipedia (NPV being a dependency of IRR) sat with incorrect input / result
data.

It all makes me think that some in the financial industry think this is some
sort of trade secret.

------
baconner
This plus something like crossfilter and you'll really be able to build.some
exciting in browser data exploration apps. Cool stuff.

------
Robin_Message
What licence is this under please? (MIT preferred!)

~~~
nivla
It is included in the js file [1] and seems to be under MIT and Apache.

[1]
[https://raw.githubusercontent.com/sutoiku/formula.js/master/...](https://raw.githubusercontent.com/sutoiku/formula.js/master/lib/formula.js)

------
robmcm
Is there a demo?

~~~
yaddayadda
Examples are available at:
[http://www.stoic.com/formula](http://www.stoic.com/formula)

------
doppenhe
very nice thanks

