From 05b35ebaf370b337d439cb142bd3283307ff2894 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 15 Oct 2007 10:34:40 +0000 Subject: [PATCH] Allow users to get a FormulaParser armed only with a HSSFWorkbook, through a convenience method on HSSFFormulaEvaluator git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@584721 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/model/FormulaParser.java | 15 +++++++++++---- .../apache/poi/hssf/usermodel/HSSFWorkbook.java | 2 +- .../poi/hssf/usermodel/HSSFFormulaEvaluator.java | 11 +++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/FormulaParser.java b/src/java/org/apache/poi/hssf/model/FormulaParser.java index af3382f155..0132945565 100644 --- a/src/java/org/apache/poi/hssf/model/FormulaParser.java +++ b/src/java/org/apache/poi/hssf/model/FormulaParser.java @@ -74,10 +74,17 @@ public class FormulaParser { private Workbook book; - /** create the parser with the string that is to be parsed - * later call the parse() method to return ptg list in rpn order - * then call the getRPNPtg() to retrive the parse results - * This class is recommended only for single threaded use + /** + * Create the formula parser, with the string that is to be + * parsed against the supplied workbook. + * A later call the parse() method to return ptg list in + * rpn order, then call the getRPNPtg() to retrive the + * parse results. + * This class is recommended only for single threaded use. + * + * If you only have a usermodel.HSSFWorkbook, and not a + * model.Workbook, then use the convenience method on + * usermodel.HSSFFormulaEvaluator */ public FormulaParser(String formula, Workbook book){ formulaString = formula; diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 691dc1e4d0..d56303d42a 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -1019,7 +1019,7 @@ public class HSSFWorkbook extends POIDocument return workbook.getSSTString(index).getString(); } - Workbook getWorkbook() + protected Workbook getWorkbook() { return workbook; } diff --git a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index 1b4118a648..2a9fc6c64b 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -165,6 +165,17 @@ public class HSSFFormulaEvaluator { } + /** + * Returns an underlying FormulaParser, for the specified + * Formula String and HSSFWorkbook. + * This will allow you to generate the Ptgs yourself, if + * your needs are more complex than just having the + * formula evaluated. + */ + public static FormulaParser getUnderlyingParser(HSSFWorkbook workbook, String formula) { + return new FormulaParser(formula, workbook.getWorkbook()); + } + /** * If cell contains a formula, the formula is evaluated and returned, * else the CellValue simply copies the appropriate cell value from -- 2.39.5