From b8802bb4298fabb2967e033c38e34b0316ece4cc Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Tue, 30 Apr 2002 00:19:49 +0000 Subject: [PATCH] Aviks patches for numbers mostly. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352562 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/record/formula/FormulaParser.java | 27 ++++++++++++------- .../poi/hssf/record/formula/FunctionPtg.java | 9 +------ .../poi/hssf/record/formula/IntPtg.java | 4 +++ 3 files changed, 22 insertions(+), 18 deletions(-) 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 a47cbf5aa..54122c0d3 100644 --- a/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java +++ b/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java @@ -247,16 +247,14 @@ public class FormulaParser { tokens.add(new FunctionPtg(name,(byte)numArgs)); } else if (Look == ':') { // this is a AreaReference String first = name; - GetChar(); + Match(':'); String second = GetName(); - tokens.add(new AreaPtg(first+":"+second)); - //String second = ; + tokens.add(new AreaPtg(first+":"+second)); } else { //this can be either a cell ref or a named range !! - boolean cellRef = true ; //we should probably do it with reg exp?? if (cellRef) { - tokens.add(new ReferencePtg(name)); //TODO we need to pass in Name somewhere?? + tokens.add(new ReferencePtg(name)); }else { //handle after named range is integrated!! } @@ -270,7 +268,7 @@ public class FormulaParser { numArgs++; Expression(); } - while (Look == ',') { + while (Look == ',') { //TODO handle EmptyArgs Match(','); Expression(); numArgs++; @@ -289,10 +287,17 @@ public class FormulaParser { } else if (IsAlpha(Look)){ Ident(); }else{ - - IntPtg p = new IntPtg(); - p.setValue(Short.parseShort(GetNum())); - tokens.add(p); + String number = GetNum(); + if (Look=='.') { + Match('.'); + String decimalPart = null; + if (IsDigit(Look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234." + tokens.add(new NumberPtg(number)); + } else { + //IntPtg p = new IntPtg(GetNum()); // removing since a ptg should be able to create itself from parser results. + //p.setValue(Short.parseShort(GetNum())); + tokens.add(new IntPtg(number)); //TODO:what if the number is too big to be a short? ..add factory to return Int or Number! + } } } @@ -489,6 +494,8 @@ end; wb.write(out); out.close(); + + System.out.println(file.getCanonicalPath()); } catch (java.io.IOException ioe) { ioe.printStackTrace(); } diff --git a/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java b/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java index 1fba83ea3..02324bc25 100644 --- a/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java @@ -1,16 +1,9 @@ -/* - * DummyFunctionPtg.java - * - * - */ - - package org.apache.poi.hssf.record.formula; import java.util.List; /** * This class provides functions with variable arguments. - * @author aviks + * @author Avik Sengupta * @author Andrew C. Oliver (acoliver at apache dot org) * @version */ diff --git a/src/java/org/apache/poi/hssf/record/formula/IntPtg.java b/src/java/org/apache/poi/hssf/record/formula/IntPtg.java index 71b5157ee..f673ec293 100644 --- a/src/java/org/apache/poi/hssf/record/formula/IntPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/IntPtg.java @@ -95,6 +95,10 @@ public class IntPtg field_1_value = Short.parseShort(val); } + // IntPtg should be able to create itself, shouldnt have to call setValue + protected IntPtg(String formulaToken) { + setValue(Short.parseShort(formulaToken)); + } public void setValue(short value) {