Package ch.rabanti.picoxlsx4j
Class Cell
- java.lang.Object
-
- ch.rabanti.picoxlsx4j.Cell
-
- All Implemented Interfaces:
Comparable<Cell>
public class Cell extends Object implements Comparable<Cell>
Class representing a cell of a worksheet- Author:
- Raphael Stoeckli
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCell.AddressTypeEnum for the referencing style of the addressstatic classCell.CellTypeEnum defines the basic data types of a cell
-
Constructor Summary
Constructors Constructor Description Cell()Default constructor.Cell(Object value, Cell.CellType type)Constructor with value and cell type.Cell(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 worksheetCell(Object value, Cell.CellType type, String address)Constructor with value, cell type and address.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Cell o)Implemented compareTo methodstatic <T> List<Cell>convertArray(List<T> list)Converts a List of supported objects into a list of cellsStringgetCellAddress()Gets the combined cell Address as string in the format A1 - XFD1048576AddressgetCellAddress2()Gets the combined cell address as classstatic List<Address>getCellRange(int startColumn, int startRow, int endColumn, int endRow)Get a list of cell addresses from a cell rangestatic List<Address>getCellRange(Address startAddress, Address endAddress)Get a list of cell addresses from a cell rangestatic List<Address>getCellRange(String range)Gets a list of cell addresses from a cell range (format A1:B3 or AAD556:AAD1000)static List<Address>getCellRange(String startAddress, String endAddress)Get a list of cell addresses from a cell rangeStylegetCellStyle()Gets the assigned style of the cellintgetColumnNumber()Gets the number of the column (zero-based)Cell.CellTypegetDataType()Gets the type of the cellintgetRowNumber()Gets the number of the row (zero-based)ObjectgetValue()Gets the value of the cell (generic object type)WorksheetgetWorksheetReference()Gets or sets the parent worksheet referencevoidremoveStyle()Removes the assigned style from the cellstatic StringresolveCellAddress(int column, int row)Gets the address of a cell by the column and row number (zero based)static StringresolveCellAddress(int column, int row, Cell.AddressType type)Gets the address of a cell by the column and row number (zero based)static AddressresolveCellCoordinate(String address)Gets the column and row number (zero based) of a cell by the addressstatic RangeresolveCellRange(String range)Resolves a cell range from the format like A1:B3 or AAD556:AAD1000voidresolveCellType()Method resets the Cell type and tries to find the actual type.static intresolveColumn(String columnAddress)Gets the column number from the column address (A - XFD)static StringresolveColumnAddress(int columnNumber)Gets the column address (A - XFD)voidsetCellAddress(String address)Sets the combined cell Address as string in the format A1 - XFD1048576voidsetCellAddress2(Address address)Sets the combined cell address as classvoidsetCellLockedState(boolean isLocked, boolean isHidden)Sets the lock state of the cellvoidsetColumnNumber(int columnNumber)Sets the number of the column (zero-based)voidsetDataType(Cell.CellType dataType)Sets the type of the cellvoidsetRowNumber(int rowNumber)Sets the number of the row (zero-based)StylesetStyle(Style style)Sets the style of the cellvoidsetValue(Object value)Sets the value of the cell (generic object type)voidsetWorksheetReference(Worksheet reference)Sets the parent worksheet reference
-
-
-
Constructor Detail
-
Cell
public Cell()
Default constructor. Cells created with this constructor do not have a link to a worksheet initially
-
Cell
public Cell(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 celltype- Type of the cell
-
Cell
public Cell(Object value, Cell.CellType type, 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 celltype- Type of the celladdress- Address of the cell
-
Cell
public Cell(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 celltype- Type of the cellcolumn- Column number of the cell (zero-based)row- Row number of the cell (zero-based)reference- Worksheet reference
-
-
Method Detail
-
getCellAddress
public String getCellAddress()
Gets the combined cell Address as string in the format A1 - XFD1048576- Returns:
- Cell address
-
setCellAddress
public void setCellAddress(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 Object getValue()
Gets the value of the cell (generic object type)- Returns:
- Value of the cell
-
setValue
public void setValue(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:
compareToin interfaceComparable<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 protectedisHidden- 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 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> List<Cell> convertArray(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 List<Address> getCellRange(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 List<Address> getCellRange(String startAddress, String endAddress)
Get a list of cell addresses from a cell range- Parameters:
startAddress- Start address as string in the format A1 - XFD1048576endAddress- 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 informationRangeException- Thrown if one of the passed addresses is out of range
-
getCellRange
public static List<Address> getCellRange(Address startAddress, Address endAddress)
Get a list of cell addresses from a cell range- Parameters:
startAddress- Start addressendAddress- End address- Returns:
- List of cell addresses
-
resolveCellAddress
public static 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 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(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 malformedRangeException- Thrown if the resolved address is out of range
-
resolveCellRange
public static Range resolveCellRange(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(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 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
-
-