From 299fcceb90c29ac893d857e7509482ad3d633867 Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Sun, 28 Apr 2002 02:04:58 +0000 Subject: [PATCH] Now provides string formula, reads simple formulas, mmmm formulas PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352511 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/record/FormulaRecord.java | 4 ++-- .../poi/hssf/record/formula/FormulaParser.java | 12 ++++++++++++ src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | 9 +++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/FormulaRecord.java b/src/java/org/apache/poi/hssf/record/FormulaRecord.java index db6c28ed7..fa0f8ed6d 100644 --- a/src/java/org/apache/poi/hssf/record/FormulaRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormulaRecord.java @@ -157,7 +157,7 @@ public class FormulaRecord int offset) { Stack stack = new Stack(); - /*int pos = 22 + offset; + int pos = 22 + offset; while (pos < size) { @@ -165,7 +165,7 @@ public class FormulaRecord pos += ptg.getSize(); stack.push(ptg); - }*/ + } return stack; } 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 4c0cefe4f..f27e0fff0 100644 --- a/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java +++ b/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java @@ -390,6 +390,18 @@ end; return (Ptg[]) tokens.toArray(retval); } } + + /** + * Convience method which takes in a list then passes it to the other toFormulaString + * signature + */ + public static String toFormulaString(List lptgs) { + String retval = null; + Ptg[] ptgs = new Ptg[lptgs.size()]; + ptgs = (Ptg[])lptgs.toArray(ptgs); + retval = toFormulaString(ptgs); + return retval; + } /** Static method to convert an array of Ptgs in RPN order * to a human readable string format in infix mode diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 080e977da..fef0fc8b2 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -712,6 +712,15 @@ public class HSSFCell } } + public String getCellFormula() { + String retval=null; + + retval = + FormulaParser.toFormulaString(((FormulaRecord)record).getParsedExpression()); + + return retval; + } + /** * get the value of the cell as a number. For strings we throw an exception.