views:

335

answers:

2

With a known formula extracted from a spreadsheet, is it possible to apply/evaluate the formula without having it reside in an actual cell?

I suppose one can create / locate a blank cell on the sheet (anyone have any ideas how this might be done efficiently?) and evaluate the formula this way, but is there a better way?

A: 

I'm not sure that POI is the way to do for this, given that it looks after creating/reading/writing spreadsheets. Have you looked at invoking the Excel COM object (via, say, JACOB), and running the formulas in Excel itself ?

Brian Agnew
A: 

Excel does let you evaluate a formula without it having to reside in a cell. You can do it via the old XLM macro language with EVALUATE or through the C API, and via VBA with Application.Evaluate or Worksheet.Evaluate.

Of course, that information might be of no help if all you have is the extracted formula and not access to Excel. If you know the formulas will be simple enough, I can see evaluating them yourself or with another tool (although I don't know of anything specific). In general, though, you will need not only access to Excel, but also the actual document the formulas are in, since a formula can call user-written VBA/XLL functions, use defined names, etc.

jtolle