From: Avik Sengupta Date: Wed, 12 Jun 2002 12:40:03 +0000 (+0000) Subject: fix for bug 9802, we write simple sum ptg, tho we can also read attr ptg. trying... X-Git-Tag: REL_1_10~319 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dbe7ec2966a6a6341fd6db828346e9e8fa3924b9;p=poi.git fix for bug 9802, we write simple sum ptg, tho we can also read attr ptg. trying to write an attr ptg messes up the class change algo. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352687 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/dev/FormulaViewer.java b/src/java/org/apache/poi/hssf/dev/FormulaViewer.java index 30e2683806..879f894997 100644 --- a/src/java/org/apache/poi/hssf/dev/FormulaViewer.java +++ b/src/java/org/apache/poi/hssf/dev/FormulaViewer.java @@ -142,6 +142,7 @@ public class FormulaViewer StringBuffer buf = new StringBuffer(); + if (token instanceof ExpPtg) return; buf.append(name=((OperationPtg) token).toFormulaString()); buf.append(sep); switch (token.getPtgClass()) { diff --git a/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java b/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java index 50c76fdaf3..509d4156de 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java @@ -446,7 +446,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg { functionData[0][0]=new Byte(Ptg.CLASS_VALUE);functionData[0][1]=new byte[] {Ptg.CLASS_REF};functionData[0][2]=new Integer(-1); functionData[2][0]=new Byte(Ptg.CLASS_VALUE);functionData[2][1]=new byte[] {Ptg.CLASS_VALUE};functionData[2][2]=new Integer(1); functionData[3][0]=new Byte(Ptg.CLASS_VALUE);functionData[3][1]=new byte[] {Ptg.CLASS_VALUE};functionData[3][2]=new Integer(1); -functionData[4][0]=new Byte(Ptg.CLASS_REF);functionData[4][1]=new byte[] {Ptg.CLASS_REF};functionData[4][2]=new Integer(-1); +functionData[4][0]=new Byte(Ptg.CLASS_VALUE);functionData[4][1]=new byte[] {Ptg.CLASS_REF};functionData[4][2]=new Integer(-1); functionData[5][0]=new Byte(Ptg.CLASS_VALUE);functionData[5][1]=new byte[] {Ptg.CLASS_REF};functionData[5][2]=new Integer(-1); functionData[6][0]=new Byte(Ptg.CLASS_VALUE);functionData[6][1]=new byte[] {Ptg.CLASS_REF};functionData[6][2]=new Integer(-1); functionData[7][0]=new Byte(Ptg.CLASS_VALUE);functionData[7][1]=new byte[] {Ptg.CLASS_REF};functionData[7][2]=new Integer(-1); diff --git a/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java b/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java index cc7490aefd..a07199f19d 100644 --- a/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java +++ b/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java @@ -264,17 +264,17 @@ public class FormulaParser { private Ptg function(String name,byte numArgs) { Ptg retval = null; - - if (numArgs == 1 && name.equals("SUM")) { + retval = new FuncVarPtg(name,numArgs); + /** if (numArgs == 1 && name.equals("SUM")) { AttrPtg ptg = new AttrPtg(); ptg.setData((short)1); //sums don't care but this is what excel does. ptg.setSum(true); retval = ptg; } else { retval = new FuncVarPtg(name,numArgs); - } + }*/ - return retval; + return retval; } /** get arguments to a function */ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java index bbb5194f37..e3e17fa7e8 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java @@ -775,6 +775,12 @@ extends TestCase { c=r.createCell( (short) 5); c.setCellFormula("SIN(A2)"); + c=r.createCell( (short) 6); + c.setCellFormula("SUM(A2:A3)"); + + c=r.createCell( (short) 7); + c.setCellFormula("SUM(A2,A3)"); + r = s.createRow((short) 1);c=r.createCell( (short) 0); c.setCellValue(2.0); r = s.createRow((short) 2);c=r.createCell( (short) 0); c.setCellValue(3.0);