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, wrapper

    Fields inherited from class org.apache.tools.ant.ProjectComponent

    description, location, project
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructs an instance using a String that contains the fully qualified path of the Excel file.
    protected
    Constructs an instance based on a Workbook instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addFunction(String name, String clazzName)
    Used to add a UDF to the evaluator.
    protected void
    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.
    double
    Returns the value of the Cell as a double.
    Returns a Cell as a String value.
    getEvaluator(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 UDFFinder
    returns a UDFFinder that contains all of the functions added.
    Returns the list of sheet names.
    Returns the Workbook instance associated with this WorkbookUtil.
    void
    setDateValue(String cellName, Date date)
    Utility method for setting the value of a Cell with a Date.
    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.
    void
    setFormulaValue(String cellName, String formula)
    Utility method for setting the value of a Cell with a Formula.
    void
    setStringValue(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

    Methods inherited from class org.apache.tools.ant.ProjectComponent

    clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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 Details

    • addFunction

      Used to add a UDF to the evaluator.
      Parameters:
      name - The name of the function to add
      clazzName - The class which implements this function
      Throws:
      ClassNotFoundException - if the class cannot be found
      InstantiationException - if the class cannot be constructed
      IllegalAccessException - if the constructor or the class is not accessible
      NoSuchMethodException
      InvocationTargetException
    • 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 replace
      func - the function to use
    • getFunctions

      protected UDFFinder getFunctions()
      returns a UDFFinder that contains all of the functions added.
      Returns:
      An instance of UDFFinder which 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 FormulaEvaluator constructed 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.
    • getSheets

      public List<String> getSheets()
      Returns the list of sheet names.
    • 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.
    • getCellAsString

      public String getCellAsString(String cellName)
      Returns a Cell as a String value.
    • getCellAsDouble

      public double getCellAsDouble(String cellName)
      Returns the value of the Cell as a double.