Am 03.11.2012 19:51, schrieb Matthias Schlaipfer:
Hi,
I have already posted this question to
http://stackoverflow.com/questions/13195020/is-it-possible-to-get-the-operands-from-a-funcvarptg-in-apache-poi.
As there was not much of a response I was pointed to the mailing list:
I want to compute a slice
(http://en.wikipedia.org/wiki/Program_slicing) of an Excel Spreadsheet
starting from some cell. That means I need to find out what cells are
referenced in a cell and recursively follow those references. So far
so good.
Now I ran into a problem with if statements (and I assume other more
complex statements too) in that I get a Ptg of type FuncVarPtg, for
which I don't know how to get the operands and the references
contained in them.
FormulaParser.parse("IF(C2>D2,A1,B1)") yields the cells referenced in
the if condition, but not the ones in the then and else branches. Here
is some exemplary output (cell C2 holds value 1.0 and cell D2 holds
0.0, i.e. these references are resolved and followed without a problem
using RefPtg.getRow() and RefPtg.getColumn())
fromCell IF(C2>D2,A1,B1)
ptg org.apache.poi.ss.formula.ptg.RefPtg [C2]
fromCell 1.0
ptg org.apache.poi.ss.formula.ptg.RefPtg [D2]
fromCell 0.0
ptg org.apache.poi.ss.formula.ptg.FuncVarPtg [IF nArgs=3]
My question in short: Is there a way to get the referenced operands
out of a FuncVarPtg?
Best regards,
Matthias
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
I solved my problem and just updated my post on StackOverflow:
Okay, my mistake was that I assumed POI would handle this differently.
It is not needed to access the FuncVarPtg in order to get the nested
operands (and in turn RefPtgs and AreaPtgs which I need for my
application). FormulaParser.parse() returns an array of all the Ptgs
(including the nested ones) appearing in the formula. So, for my
application it is sufficient to filter that array for RefPtgs and AreaPtgs.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]