Class 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 ExcelAntWorkbookUtil​(String fName)
      Constructs an instance using a String that contains the fully qualified path of the Excel file.
      protected ExcelAntWorkbookUtil​(Workbook wb)
      Constructs an instance based on a Workbook instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFunction​(String name, String clazzName)
      Used to add a UDF to the evaluator.
      protected void addFunction​(String name, FreeRefFunction func)
      Updates the internal HashMap of functions with instance and alias passed in.
      ExcelAntEvaluationResult evaluateCell​(String cellName, double expectedValue, double precision)
      Uses a String in standard Excel format (SheetName!CellId) to locate a cell and evaluate it.
      double getCellAsDouble​(String cellName)
      Returns the value of the Cell as a double.
      String getCellAsString​(String cellName)
      Returns a Cell as a String value.
      protected FormulaEvaluator getEvaluator​(String fileName)
      Returns a formula evaluator that is loaded with the functions that have been supplied.
      String getFileName()
      Returns the fileName that was used to initialize this instance.
      protected UDFFinder getFunctions()
      returns a UDFFinder that contains all of the functions added.
      List<String> getSheets()
      Returns the list of sheet names.
      Workbook getWorkbook()
      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
    • 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

        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.