Class Cell

  • All Implemented Interfaces:
    java.lang.Comparable<Cell>

    public class Cell
    extends java.lang.Object
    implements java.lang.Comparable<Cell>
    Class representing a cell of a worksheet
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Cell.AddressType
      Enum for the referencing style of the address
      static class  Cell.CellType
      Enum defines the basic data types of a cell
    • Constructor Summary

      Constructors 
      Constructor Description
      Cell()
      Default constructor.
      Cell​(java.lang.Object value, Cell.CellType type)
      Constructor with value and cell type.
      Cell​(java.lang.Object value, Cell.CellType type, int column, int row, Worksheet reference)
      Constructor with value, cell type, row number, column number and the link to a worksheet
      Cell​(java.lang.Object value, Cell.CellType type, java.lang.String address)
      Constructor with value, cell type and address.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Cell o)
      Implemented compareTo method
      static <T> java.util.List<Cell> convertArray​(java.util.List<T> list)
      Converts a List of supported objects into a list of cells
      java.lang.String getCellAddress()
      Gets the combined cell Address as string in the format A1 - XFD1048576
      Address getCellAddress2()
      Gets the combined cell address as class
      static java.util.List<Address> getCellRange​(int startColumn, int startRow, int endColumn, int endRow)
      Get a list of cell addresses from a cell range
      static java.util.List<Address> getCellRange​(Address startAddress, Address endAddress)
      Get a list of cell addresses from a cell range
      static java.util.List<Address> getCellRange​(java.lang.String range)
      Gets a list of cell addresses from a cell range (format A1:B3 or AAD556:AAD1000)
      static java.util.List<Address> getCellRange​(java.lang.String startAddress, java.lang.String endAddress)
      Get a list of cell addresses from a cell range
      Style getCellStyle()
      Gets the assigned style of the cell
      int getColumnNumber()
      Gets the number of the column (zero-based)
      Cell.CellType getDataType()
      Gets the type of the cell
      int getRowNumber()
      Gets the number of the row (zero-based)
      java.lang.Object getValue()
      Gets the value of the cell (generic object type)
      Worksheet getWorksheetReference()
      Gets or sets the parent worksheet reference
      void removeStyle()
      Removes the assigned style from the cell
      static java.lang.String resolveCellAddress​(int column, int row)
      Gets the address of a cell by the column and row number (zero based)
      static java.lang.String resolveCellAddress​(int column, int row, Cell.AddressType type)
      Gets the address of a cell by the column and row number (zero based)
      static Address resolveCellCoordinate​(java.lang.String address)
      Gets the column and row number (zero based) of a cell by the address
      static Range resolveCellRange​(java.lang.String range)
      Resolves a cell range from the format like A1:B3 or AAD556:AAD1000
      void resolveCellType()
      Method resets the Cell type and tries to find the actual type.
      static int resolveColumn​(java.lang.String columnAddress)
      Gets the column number from the column address (A - XFD)
      static java.lang.String resolveColumnAddress​(int columnNumber)
      Gets the column address (A - XFD)
      void setCellAddress​(java.lang.String address)
      Sets the combined cell Address as string in the format A1 - XFD1048576
      void setCellAddress2​(Address address)
      Sets the combined cell address as class
      void setCellLockedState​(boolean isLocked, boolean isHidden)
      Sets the lock state of the cell
      void setColumnNumber​(int columnNumber)
      Sets the number of the column (zero-based)
      void setDataType​(Cell.CellType dataType)
      Sets the type of the cell
      void setRowNumber​(int rowNumber)
      Sets the number of the row (zero-based)
      Style setStyle​(Style style)
      Sets the style of the cell
      void setValue​(java.lang.Object value)
      Sets the value of the cell (generic object type)
      void setWorksheetReference​(Worksheet reference)
      Sets the parent worksheet reference
      (package private) static void validateColumnNumber​(int columnNumber)
      Validates the passed (zero-based) column number. an exception will be thrown if the column is invalid
      (package private) static void validateRowNumber​(int rowNumber)
      Validates the passed (zero-based) row number. an exception will be thrown if the row is invalid
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Cell

        public Cell()
        Default constructor. Cells created with this constructor do not have a link to a worksheet initially
      • Cell

        public Cell​(java.lang.Object value,
                    Cell.CellType type)
        Constructor with value and cell type. Cells created with this constructor do not have a link to a worksheet initially
        Parameters:
        value - Value of the cell
        type - Type of the cell
      • Cell

        public Cell​(java.lang.Object value,
                    Cell.CellType type,
                    java.lang.String address)
        Constructor with value, cell type and address. The worksheet reference is set to null and must be assigned later
        Parameters:
        value - Value of the cell
        type - Type of the cell
        address - Address of the cell
      • Cell

        public Cell​(java.lang.Object value,
                    Cell.CellType type,
                    int column,
                    int row,
                    Worksheet reference)
        Constructor with value, cell type, row number, column number and the link to a worksheet
        Parameters:
        value - Value of the cell
        type - Type of the cell
        column - Column number of the cell (zero-based)
        row - Row number of the cell (zero-based)
        reference - Worksheet reference
    • Method Detail

      • getCellAddress

        public java.lang.String getCellAddress()
        Gets the combined cell Address as string in the format A1 - XFD1048576
        Returns:
        Cell address
      • setCellAddress

        public void setCellAddress​(java.lang.String address)
        Sets the combined cell Address as string in the format A1 - XFD1048576
        Parameters:
        address - Cell address
        Throws:
        RangeException - Thrown in case of a illegal address
      • getCellAddress2

        public Address getCellAddress2()
        Gets the combined cell address as class
        Returns:
        Cell address
      • setCellAddress2

        public void setCellAddress2​(Address address)
        Sets the combined cell address as class
        Parameters:
        address - Cell address
      • getCellStyle

        public Style getCellStyle()
        Gets the assigned style of the cell
        Returns:
        Assigned style
      • getColumnNumber

        public int getColumnNumber()
        Gets the number of the column (zero-based)
        Returns:
        Column number (zero-based)
      • setColumnNumber

        public void setColumnNumber​(int columnNumber)
        Sets the number of the column (zero-based)
        Parameters:
        columnNumber - Column number (zero-based)
      • getDataType

        public Cell.CellType getDataType()
        Gets the type of the cell
        Returns:
        Type of the cell
      • setDataType

        public void setDataType​(Cell.CellType dataType)
        Sets the type of the cell
        Parameters:
        dataType - Type of the cell
      • getRowNumber

        public int getRowNumber()
        Gets the number of the row (zero-based)
        Returns:
        Row number (zero-based)
      • setRowNumber

        public void setRowNumber​(int rowNumber)
        Sets the number of the row (zero-based)
        Parameters:
        rowNumber - Row number (zero-based)
      • getValue

        public java.lang.Object getValue()
        Gets the value of the cell (generic object type)
        Returns:
        Value of the cell
      • setValue

        public void setValue​(java.lang.Object value)
        Sets the value of the cell (generic object type)
        Parameters:
        value - Value of the cell
      • getWorksheetReference

        public Worksheet getWorksheetReference()
        Gets or sets the parent worksheet reference
        Returns:
        Worksheet reference
      • setWorksheetReference

        public void setWorksheetReference​(Worksheet reference)
        Sets the parent worksheet reference
        Parameters:
        reference - Worksheet reference
      • compareTo

        public int compareTo​(Cell o)
        Implemented compareTo method
        Specified by:
        compareTo in interface java.lang.Comparable<Cell>
        Parameters:
        o - Object to compare
        Returns:
        0 if values are the same, -1 if this object is smaller, 1 if it is bigger
      • removeStyle

        public void removeStyle()
        Removes the assigned style from the cell
        Throws:
        StyleException - Thrown if the workbook to remove was not found in the style sheet collection
      • resolveCellType

        public void resolveCellType()
        Method resets the Cell type and tries to find the actual type. This is used if a Cell was created with the CellType DEFAULT. CellTypes FORMULA and EMPTY will skip this method
      • setCellLockedState

        public void setCellLockedState​(boolean isLocked,
                                       boolean isHidden)
        Sets the lock state of the cell
        Parameters:
        isLocked - If true, the cell will be locked if the worksheet is protected
        isHidden - If true, the value of the cell will be invisible if the worksheet is protected
      • setStyle

        public Style setStyle​(Style style)
        Sets the style of the cell
        Parameters:
        style - style to assign
        Returns:
        If the passed style already exists in the workbook, the existing one will be returned, otherwise the passed one
        Throws:
        StyleException - Thrown if the style is not referenced in the workbook
      • getCellRange

        public static java.util.List<Address> getCellRange​(int startColumn,
                                                           int startRow,
                                                           int endColumn,
                                                           int endRow)
        Get a list of cell addresses from a cell range
        Parameters:
        startColumn - Start column (zero based)
        startRow - Start row (zero based)
        endColumn - End column (zero based)
        endRow - End row (zero based)
        Returns:
        List of cell addresses
      • convertArray

        public static <T> java.util.List<Cell> convertArray​(java.util.List<T> list)
        Converts a List of supported objects into a list of cells
        Type Parameters:
        T - Generic data type
        Parameters:
        list - List of generic objects
        Returns:
        List of cells
      • getCellRange

        public static java.util.List<Address> getCellRange​(java.lang.String range)
        Gets a list of cell addresses from a cell range (format A1:B3 or AAD556:AAD1000)
        Parameters:
        range - Range to process
        Returns:
        List of cell addresses
        Throws:
        FormatException - Thrown if the passed address range is malformed
      • getCellRange

        public static java.util.List<Address> getCellRange​(java.lang.String startAddress,
                                                           java.lang.String endAddress)
        Get a list of cell addresses from a cell range
        Parameters:
        startAddress - Start address as string in the format A1 - XFD1048576
        endAddress - End address as string in the format A1 - XFD1048576
        Returns:
        List of cell addresses
        Throws:
        FormatException - Thrown if one of the passed addresses contains malformed information
        RangeException - Thrown if one of the passed addresses is out of range
      • getCellRange

        public static java.util.List<Address> getCellRange​(Address startAddress,
                                                           Address endAddress)
        Get a list of cell addresses from a cell range
        Parameters:
        startAddress - Start address
        endAddress - End address
        Returns:
        List of cell addresses
      • resolveCellAddress

        public static java.lang.String resolveCellAddress​(int column,
                                                          int row)
        Gets the address of a cell by the column and row number (zero based)
        Parameters:
        column - Column address of the cell (zero-based)
        row - Row address of the cell (zero-based)
        Returns:
        Cell Address as string in the format A1 - XFD1048576
        Throws:
        RangeException - Thrown if one of the passed addresses is out of range
      • resolveCellAddress

        public static java.lang.String resolveCellAddress​(int column,
                                                          int row,
                                                          Cell.AddressType type)
        Gets the address of a cell by the column and row number (zero based)
        Parameters:
        column - Column address of the cell (zero-based)
        row - Row address of the cell (zero-based)
        type - Referencing type of the address
        Returns:
        Cell Address as string in the format A1 - XFD1048576
        Throws:
        RangeException - Thrown if one of the passed addresses is out of range
      • resolveCellCoordinate

        public static Address resolveCellCoordinate​(java.lang.String address)
        Gets the column and row number (zero based) of a cell by the address
        Parameters:
        address - Address as string in the format A1 - XFD1048576. '$' signs indicating fixed rows and / or columns are considered
        Returns:
        Address object of the passed string
        Throws:
        FormatException - Thrown if the passed address was malformed
        RangeException - Thrown if the resolved address is out of range
      • resolveCellRange

        public static Range resolveCellRange​(java.lang.String range)
        Resolves a cell range from the format like A1:B3 or AAD556:AAD1000
        Parameters:
        range - Range to process
        Returns:
        Range object of the passed string range
        Throws:
        FormatException - Thrown if the passed range is malformed
      • resolveColumn

        public static int resolveColumn​(java.lang.String columnAddress)
        Gets the column number from the column address (A - XFD)
        Parameters:
        columnAddress - Column address (A - XFD)
        Returns:
        Column number (zero-based)
        Throws:
        RangeException - Thrown if the column is out of range
      • resolveColumnAddress

        public static java.lang.String resolveColumnAddress​(int columnNumber)
        Gets the column address (A - XFD)
        Parameters:
        columnNumber - Column number (zero-based)
        Returns:
        Column address (A - XFD)
        Throws:
        RangeException - Thrown if the passed column number is out of range
      • validateColumnNumber

        static void validateColumnNumber​(int columnNumber)
        Validates the passed (zero-based) column number. an exception will be thrown if the column is invalid
        Parameters:
        columnNumber - Number to check
        Throws:
        RangeException - Thrown if the passed column number is out of range
      • validateRowNumber

        static void validateRowNumber​(int rowNumber)
        Validates the passed (zero-based) row number. an exception will be thrown if the row is invalid
        Parameters:
        rowNumber - Number to check
        Throws:
        RangeException - Thrown if the passed row number is out of range