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.TypedefA general utility class that abstracts the POI details of loading the workbook, accessing and updating cells.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedExcelAntWorkbookUtil(String fName)Constructs an instance using a String that contains the fully qualified path of the Excel file.protectedExcelAntWorkbookUtil(Workbook wb)Constructs an instance based on a Workbook instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFunction(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.ExcelAntEvaluationResultevaluateCell(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.StringgetCellAsString(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.StringgetFileName()Returns the fileName that was used to initialize this instance.protected UDFFindergetFunctions()returns a UDFFinder that contains all of the functions added.List<String>getSheets()Returns the list of sheet names.WorkbookgetWorkbook()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, setRestrict
-
Methods inherited from class org.apache.tools.ant.taskdefs.DefBase
createClasspath, createLoader, getClasspath, getClasspathId, getLoaderId, hasCpDelegate, init, isReverseLoader, setClasspath, setClasspathRef, setLoaderRef, setReverseLoader
-
Methods inherited from class org.apache.tools.ant.taskdefs.AntlibDefinition
getAntlibClassLoader, getURI, setAntlibClassLoader, setURI
-
Methods 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, setTaskType
-
-
-
-
Constructor Detail
-
ExcelAntWorkbookUtil
protected ExcelAntWorkbookUtil(String fName)
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
protected ExcelAntWorkbookUtil(Workbook wb)
Constructs an instance based on a Workbook instance.- Parameters:
wb- The Workbook to use for this instance.
-
-
Method Detail
-
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
protected void addFunction(String name, FreeRefFunction func)
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
protected UDFFinder getFunctions()
returns a UDFFinder that contains all of the functions added.- Returns:
- An instance of
UDFFinderwhich can be used to lookup functions
-
getEvaluator
protected FormulaEvaluator getEvaluator(String fileName)
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
public Workbook getWorkbook()
Returns the Workbook instance associated with this WorkbookUtil.
-
getFileName
public String getFileName()
Returns the fileName that was used to initialize this instance. May return null if the instance was constructed from a Workbook object.
-
setDoubleValue
public void setDoubleValue(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.
-
setStringValue
public void setStringValue(String cellName, String value)
Utility method for setting the value of a Cell with a String.
-
setFormulaValue
public void setFormulaValue(String cellName, String formula)
Utility method for setting the value of a Cell with a Formula.
-
setDateValue
public void setDateValue(String cellName, Date date)
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.
-
getCellAsDouble
public double getCellAsDouble(String cellName)
Returns the value of the Cell as a double.
-
-