Originally reported as a re-open of bug 42541. If the example file (https://issues.apache.org/bugzilla/attachment.cgi?id=22062) is read and re-written by POI, the formulas in Sheet1!C6:C21 all display as '#VALUE!' in Excel. The formulas contain tokens with operand class 'array'. The code in SharedFormulaRecord.convertSharedFormulas() does not propagate the operand class correctly.
The following patch fixes this bug: Index: SharedFormulaRecord.java =================================================================== --- SharedFormulaRecord.java (revision 661934) +++ SharedFormulaRecord.java (working copy) @@ -201,6 +201,10 @@ if (ptgs != null) for (int k = 0; k < ptgs.size(); k++) { Ptg ptg = (Ptg) ptgs.get(k); + byte originalOperandClass = -1; + if (!ptg.isBaseToken()) { + originalOperandClass = ptg.getPtgClass(); + } if (ptg instanceof RefNPtg) { RefNPtg refNPtg = (RefNPtg)ptg; ptg = new ReferencePtg(fixupRelativeRow(formulaRow,refNPtg.getRow(),refNPtg.isRowRelative()), @@ -249,7 +253,11 @@ areaNAPtg.isLastRowRelative(), areaNAPtg.isFirstColRelative(), areaNAPtg.isLastColRelative()); - } + } + if (!ptg.isBaseToken()) { + ptg.setClass(originalOperandClass); + } + newPtgStack.add(ptg); } return newPtgStack; A junit also needs to be added.
Josh, Could you send me the revised SharedFormulaRecord.java file or give me the location to get that file. I want to test it out. Thanks
Created attachment 22065 [details] Draft of SharedFormulaRecord (.java and .class) base version is r652934
(In reply to comment #3) > Created an attachment (id=22065) [details] This file can be patched into the svn trunk (I think it depends on bug 45060, which is very recent). You can get the latest from subversion with the following command: svn co https://svn.apache.org/repos/asf/poi/trunk
(In reply to comment #1) > The following patch fixes this bug ... Applied patch in svn r663436 junit test added as well.