aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/ss
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-09-17 00:00:57 +0000
committerJosh Micich <josh@apache.org>2009-09-17 00:00:57 +0000
commit30dcd662576e1fbbf52a6551c149582de2f1fef9 (patch)
tree05e02da2ec8e47921ea051f3d3ec75c96036ea28 /src/java/org/apache/poi/ss
parenta82e264754e5a6e74968ab1032892283764538f3 (diff)
downloadpoi-30dcd662576e1fbbf52a6551c149582de2f1fef9.tar.gz
poi-30dcd662576e1fbbf52a6551c149582de2f1fef9.zip
Improvements to patch 47809 (support for UDFs)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@816016 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/ss')
-rw-r--r--src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java14
-rw-r--r--src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java5
-rw-r--r--src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java16
-rw-r--r--src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java6
-rw-r--r--src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java16
-rw-r--r--src/java/org/apache/poi/ss/usermodel/Name.java8
-rw-r--r--src/java/org/apache/poi/ss/usermodel/Workbook.java32
7 files changed, 36 insertions, 61 deletions
diff --git a/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java b/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java
index 0d65af92df..a3b2325719 100644
--- a/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java
+++ b/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java
@@ -20,7 +20,6 @@ package org.apache.poi.ss.formula;
import org.apache.poi.hssf.record.formula.NamePtg;
import org.apache.poi.hssf.record.formula.NameXPtg;
import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
/**
* Abstracts a workbook for the purpose of formula evaluation.<br/>
@@ -28,8 +27,6 @@ import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
* For POI internal use only
*
* @author Josh Micich
- *
- * Modified 09/07/09 by Petr Udalau - added methods for searching for UDFs of this Workbook.
*/
public interface EvaluationWorkbook {
String getSheetName(int sheetIndex);
@@ -54,17 +51,6 @@ public interface EvaluationWorkbook {
String resolveNameXText(NameXPtg ptg);
Ptg[] getFormulaTokens(EvaluationCell cell);
- /**
- * Find and return user defined function (UDF) contained by workbook with
- * specified name.
- *
- * @param functionName UDF name
- * @return instance of FreeRefFunction or null if no UDF with the specified
- * name exists.
- */
- FreeRefFunction findUserDefinedFunction(String functionName);
-
-
class ExternalSheet {
private final String _workbookName;
private final String _sheetName;
diff --git a/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java b/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java
index 2ec5f5791c..e1a28a6fee 100644
--- a/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java
+++ b/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java
@@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet;
@@ -256,4 +257,8 @@ public final class OperationEvaluationContext {
}
return CellReference.classifyCellReference(str, ssVersion);
}
+
+ public FreeRefFunction findUserDefinedFunction(String functionName) {
+ return _bookEvaluator.findUserDefinedFunction(functionName);
+ }
}
diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
index 806c002bb1..ed8abb7dfa 100644
--- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
+++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
@@ -59,6 +59,8 @@ import org.apache.poi.hssf.record.formula.eval.OperationEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
+import org.apache.poi.hssf.record.formula.udf.UDFFinder;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException;
import org.apache.poi.ss.formula.eval.NotImplementedException;
@@ -87,12 +89,16 @@ public final class WorkbookEvaluator {
private final Map<String, Integer> _sheetIndexesByName;
private CollaboratingWorkbooksEnvironment _collaboratingWorkbookEnvironment;
private final IStabilityClassifier _stabilityClassifier;
+ private final UDFFinder _udfFinder;
- public WorkbookEvaluator(EvaluationWorkbook workbook, IStabilityClassifier stabilityClassifier) {
- this (workbook, null, stabilityClassifier);
+ /**
+ * @param udfFinder pass <code>null</code> for default (AnalysisToolPak only)
+ */
+ public WorkbookEvaluator(EvaluationWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
+ this (workbook, null, stabilityClassifier, udfFinder);
}
/* package */ WorkbookEvaluator(EvaluationWorkbook workbook, IEvaluationListener evaluationListener,
- IStabilityClassifier stabilityClassifier) {
+ IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
_workbook = workbook;
_evaluationListener = evaluationListener;
_cache = new EvaluationCache(evaluationListener);
@@ -101,6 +107,7 @@ public final class WorkbookEvaluator {
_collaboratingWorkbookEnvironment = CollaboratingWorkbooksEnvironment.EMPTY;
_workbookIx = 0;
_stabilityClassifier = stabilityClassifier;
+ _udfFinder = udfFinder == null ? UDFFinder.DEFAULT : udfFinder;
}
/**
@@ -516,4 +523,7 @@ public final class WorkbookEvaluator {
EvaluationCell cell = sheet.getCell(rowIndex, columnIndex);
return evaluateAny(cell, sheetIndex, rowIndex, columnIndex, tracker);
}
+ public FreeRefFunction findUserDefinedFunction(String functionName) {
+ return _udfFinder.findFunction(functionName);
+ }
}
diff --git a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
index 1525708f31..08ed7f5346 100644
--- a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
+++ b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
@@ -36,8 +36,6 @@ import org.apache.poi.ss.usermodel.Workbook;
* updated after a call to {@link #getOrCreateUpdatableCell(String, int, int)}.
*
* @author Josh Micich
- *
- * Modified 09/07/09 by Petr Udalau - added methods for searching for UDFs of this Workbook.
*/
final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
@@ -144,8 +142,4 @@ final class ForkedEvaluationWorkbook implements EvaluationWorkbook {
return _index - o._index;
}
}
-
- public FreeRefFunction findUserDefinedFunction(String functionName) {
- return _masterBook.findUserDefinedFunction(functionName);
- }
}
diff --git a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java
index e89d2a6104..7985603748 100644
--- a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java
+++ b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluator.java
@@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.record.formula.udf.UDFFinder;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -47,9 +48,9 @@ public final class ForkedEvaluator {
private WorkbookEvaluator _evaluator;
private ForkedEvaluationWorkbook _sewb;
- private ForkedEvaluator(EvaluationWorkbook masterWorkbook, IStabilityClassifier stabilityClassifier) {
+ private ForkedEvaluator(EvaluationWorkbook masterWorkbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
_sewb = new ForkedEvaluationWorkbook(masterWorkbook);
- _evaluator = new WorkbookEvaluator(_sewb, stabilityClassifier);
+ _evaluator = new WorkbookEvaluator(_sewb, stabilityClassifier, udfFinder);
}
private static EvaluationWorkbook createEvaluationWorkbook(Workbook wb) {
if (wb instanceof HSSFWorkbook) {
@@ -61,8 +62,17 @@ public final class ForkedEvaluator {
// }
throw new IllegalArgumentException("Unexpected workbook type (" + wb.getClass().getName() + ")");
}
+ /**
+ * @deprecated (Sep 2009) (reduce overloading) use {@link #create(Workbook, IStabilityClassifier, UDFFinder)}
+ */
public static ForkedEvaluator create(Workbook wb, IStabilityClassifier stabilityClassifier) {
- return new ForkedEvaluator(createEvaluationWorkbook(wb), stabilityClassifier);
+ return create(wb, stabilityClassifier, null);
+ }
+ /**
+ * @param udfFinder pass <code>null</code> for default (AnalysisToolPak only)
+ */
+ public static ForkedEvaluator create(Workbook wb, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) {
+ return new ForkedEvaluator(createEvaluationWorkbook(wb), stabilityClassifier, udfFinder);
}
/**
diff --git a/src/java/org/apache/poi/ss/usermodel/Name.java b/src/java/org/apache/poi/ss/usermodel/Name.java
index 0cc9d98e9e..a07154e5fe 100644
--- a/src/java/org/apache/poi/ss/usermodel/Name.java
+++ b/src/java/org/apache/poi/ss/usermodel/Name.java
@@ -49,8 +49,6 @@ package org.apache.poi.ss.usermodel;
* name.setRefersToFormula("IF(Loan_Amount*Interest_Rate>0,1,0)");
*
* </blockquote></pre>
- *
- * Modified 8/31/09 by Petr Udalau - added method setFunction(boolean)
*/
public interface Name {
@@ -61,14 +59,14 @@ public interface Name {
*/
String getSheetName();
- /**
+ /**
* Gets the name of the named range
*
* @return named range name
*/
String getNameName();
- /**
+ /**
* Sets the name of the named range
*
* <p>The following is a list of syntax rules that you need to be aware of when you create and edit names.</p>
@@ -118,7 +116,7 @@ public interface Name {
void setNameName(String name);
/**
- * Returns the formula that the name is defined to refer to.
+ * Returns the formula that the name is defined to refer to.
*
* @return the reference for this name, <code>null</code> if it has not been set yet. Never empty string
* @see #setRefersToFormula(String)
diff --git a/src/java/org/apache/poi/ss/usermodel/Workbook.java b/src/java/org/apache/poi/ss/usermodel/Workbook.java
index cbbc2a4268..99f4ddba89 100644
--- a/src/java/org/apache/poi/ss/usermodel/Workbook.java
+++ b/src/java/org/apache/poi/ss/usermodel/Workbook.java
@@ -21,15 +21,12 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
-import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
/**
* High level representation of a Excel workbook. This is the first object most users
* will construct whether they are reading or writing a workbook. It is also the
* top level object for creating new sheets/etc.
- *
- * Modified 09/07/09 by Petr Udalau - added methods for work with UDFs of this Workbook.
*/
public interface Workbook {
@@ -189,7 +186,7 @@ public interface Workbook {
* @param index of the sheet to remove (0-based)
*/
void removeSheetAt(int index);
-
+
/**
* Sets the repeating rows and columns for a sheet (as found in
* File->PageSetup->Sheet). This is function is included in the workbook
@@ -374,7 +371,7 @@ public interface Workbook {
* Sets the policy on what to do when
* getting missing or blank cells from a row.
*
- * This will then apply to all calls to
+ * This will then apply to all calls to
* {@link Row#getCell(int)} }. See
* {@link MissingCellPolicy}
*/
@@ -467,29 +464,4 @@ public interface Workbook {
* @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
*/
void setSheetHidden(int sheetIx, int hidden);
-
- /**
- * Find and return user defined function (UDF) with specified name.
- *
- * @param functionName
- * UDF name
- * @return instance of FreeRefFunction or null if no UDF with the specified
- * name exists.
- */
- FreeRefFunction getUserDefinedFunction(String functionName);
-
- /**
- * Add user defined function (UDF) to workbook
- *
- * @param name
- * @param function
- */
- void registerUserDefinedFunction(String name, FreeRefFunction function);
-
- /**
- * Returns user defined functions (UDF) names
- *
- * @return list of UDF names
- */
- List<String> getUserDefinedFunctionNames();
}