Bug 45123

Summary: Token operand class not being copied by SharedFormulaRecord.convertSharedFormulas()
Product: POI Reporter: Josh Micich <josh>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: sandeep30469, vkt3142
Priority: P2    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Draft of SharedFormulaRecord (.java and .class)

Description Josh Micich 2008-06-03 10:02:01 UTC
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.
Comment 1 Josh Micich 2008-06-03 10:06:48 UTC
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.
Comment 2 vijay 2008-06-03 11:48:05 UTC
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
Comment 3 Josh Micich 2008-06-03 12:54:27 UTC
Created attachment 22065 [details]
Draft of SharedFormulaRecord (.java and .class)

base version is r652934
Comment 4 Josh Micich 2008-06-03 13:00:10 UTC
(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


Comment 5 Josh Micich 2008-06-04 20:14:26 UTC
(In reply to comment #1)
> The following patch fixes this bug ...

Applied patch in svn r663436

junit test added as well.