Package org.apache.poi.ss.excelant.util
Class ExcelAntWorkbookUtil
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.AntlibDefinition
org.apache.tools.ant.taskdefs.DefBase
org.apache.tools.ant.taskdefs.Definer
org.apache.tools.ant.taskdefs.Typedef
org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil
- All Implemented Interfaces:
Cloneable
public class ExcelAntWorkbookUtil
extends org.apache.tools.ant.taskdefs.Typedef
A general utility class that abstracts the POI details of loading the
workbook, accessing and updating cells.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.tools.ant.taskdefs.Definer
org.apache.tools.ant.taskdefs.Definer.Format, org.apache.tools.ant.taskdefs.Definer.OnError -
Field Summary
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExcelAntWorkbookUtil(String fName) Constructs an instance using a String that contains the fully qualified path of the Excel file.protectedConstructs an instance based on a Workbook instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFunction(String name, String clazzName) Used to add a UDF to the evaluator.protected voidaddFunction(String name, FreeRefFunction func) Updates the internal HashMap of functions with instance and alias passed in.evaluateCell(String cellName, double expectedValue, double precision) Uses a String in standard Excel format (SheetName!CellId) to locate a cell and evaluate it.doublegetCellAsDouble(String cellName) Returns the value of the Cell as a double.getCellAsString(String cellName) Returns a Cell as a String value.protected FormulaEvaluatorgetEvaluator(String fileName) Returns a formula evaluator that is loaded with the functions that have been supplied.Returns the fileName that was used to initialize this instance.protected UDFFinderreturns a UDFFinder that contains all of the functions added.Returns the list of sheet names.Returns the Workbook instance associated with this WorkbookUtil.voidsetDateValue(String cellName, Date date) Utility method for setting the value of a Cell with a Date.voidsetDoubleValue(String cellName, double value) This method uses a String in standard Excel format (SheetName!CellId) to locate the cell and set it to the value of the double in value.voidsetFormulaValue(String cellName, String formula) Utility method for setting the value of a Cell with a Formula.voidsetStringValue(String cellName, String value) Utility method for setting the value of a Cell with a String.Methods inherited from class org.apache.tools.ant.taskdefs.Definer
addDefinition, execute, getClassname, getFile, getName, getResource, loadProperties, makeResourceFromURI, setAdapter, setAdapterClass, setAdaptTo, setAdaptToClass, setAntlib, setClassname, setFile, setFormat, setName, setOnError, setResource, setRestrictMethods inherited from class org.apache.tools.ant.taskdefs.DefBase
createClasspath, createLoader, getClasspath, getClasspathId, getLoaderId, hasCpDelegate, init, isReverseLoader, setClasspath, setClasspathRef, setLoaderRef, setReverseLoaderMethods inherited from class org.apache.tools.ant.taskdefs.AntlibDefinition
getAntlibClassLoader, getURI, setAntlibClassLoader, setURIMethods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Constructor Details
-
ExcelAntWorkbookUtil
Constructs an instance using a String that contains the fully qualified path of the Excel file. This constructor initializes a Workbook instance based on that file name.- Parameters:
fName- The fully qualified path of the Excel file.- Throws:
org.apache.tools.ant.BuildException- If the workbook cannot be loaded.
-
ExcelAntWorkbookUtil
Constructs an instance based on a Workbook instance.- Parameters:
wb- The Workbook to use for this instance.
-
-
Method Details
-
addFunction
public void addFunction(String name, String clazzName) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException Used to add a UDF to the evaluator.- Parameters:
name- The name of the function to addclazzName- The class which implements this function- Throws:
ClassNotFoundException- if the class cannot be foundInstantiationException- if the class cannot be constructedIllegalAccessException- if the constructor or the class is not accessibleNoSuchMethodExceptionInvocationTargetException
-
addFunction
Updates the internal HashMap of functions with instance and alias passed in.- Parameters:
name- the name of the function to replacefunc- the function to use
-
getFunctions
returns a UDFFinder that contains all of the functions added.- Returns:
- An instance of
UDFFinderwhich can be used to lookup functions
-
getEvaluator
Returns a formula evaluator that is loaded with the functions that have been supplied.- Parameters:
fileName- Specifies if XSSF or HSSF should be used for the evaluator- Returns:
- A
FormulaEvaluatorconstructed accordingly
-
getWorkbook
Returns the Workbook instance associated with this WorkbookUtil. -
getFileName
Returns the fileName that was used to initialize this instance. May return null if the instance was constructed from a Workbook object. -
getSheets
Returns the list of sheet names. -
setDoubleValue
This method uses a String in standard Excel format (SheetName!CellId) to locate the cell and set it to the value of the double in value. -
setStringValue
Utility method for setting the value of a Cell with a String. -
setFormulaValue
Utility method for setting the value of a Cell with a Formula. -
setDateValue
Utility method for setting the value of a Cell with a Date. -
evaluateCell
public ExcelAntEvaluationResult evaluateCell(String cellName, double expectedValue, double precision) Uses a String in standard Excel format (SheetName!CellId) to locate a cell and evaluate it. -
getCellAsString
Returns a Cell as a String value. -
getCellAsDouble
Returns the value of the Cell as a double.
-