From 1ef8d27a1ef806570e2e3a46128d98be19b1abc4 Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Wed, 12 Jun 2002 12:40:03 +0000 Subject: [PATCH] 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 --- src/java/org/apache/poi/hssf/dev/FormulaViewer.java | 1 + .../poi/hssf/record/formula/AbstractFunctionPtg.java | 2 +- .../org/apache/poi/hssf/record/formula/FormulaParser.java | 8 ++++---- .../org/apache/poi/hssf/usermodel/TestFormulas.java | 6 ++++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/poi/hssf/dev/FormulaViewer.java b/src/java/org/apache/poi/hssf/dev/FormulaViewer.java index 30e268380..879f89499 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 50c76fdaf..509d4156d 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 cc7490aef..a07199f19 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 bbb5194f3..e3e17fa7e 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);