Package ch.rabanti.picoxlsx4j
Class Worksheet
- java.lang.Object
-
- ch.rabanti.picoxlsx4j.Worksheet
-
public class Worksheet extends Object
Class representing a worksheet of a workbook
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Worksheet.CellDirection
Enum to define the direction when using AddNextCell methodstatic class
Worksheet.SheetProtectionValue
Enum to define the possible protection types when protecting a worksheet
-
Field Summary
Fields Modifier and Type Field Description static float
DEFAULT_COLUMN_WIDTH
Default column width as constantstatic float
DEFAULT_ROW_HEIGHT
Default row height as constantstatic int
MAX_COLUMN_NUMBER
Maximum column number (zero-based)static float
MAX_COLUMN_WIDTH
Maximum column width as constantstatic float
MAX_ROW_HEIGHT
Maximum row height as constantstatic int
MAX_ROW_NUMBER
Maximum row number (zero-based)static int
MIN_COLUMN_NUMBER
Minimum column number (zero-based)static float
MIN_COLUMN_WIDTH
Minimum column width as constantstatic float
MIN_ROW_HEIGHT
Minimum row height as constantstatic int
MIN_ROW_NUMBER
Minimum row number (zero-based)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAllowedActionOnSheetProtection(Worksheet.SheetProtectionValue typeOfProtection)
Method to add allowed actions if the worksheet is protected.void
addCell(Object value, int columnAddress, int rowAddress)
Adds an object to the defined cell address.void
addCell(Object value, int columnAddress, int rowAddress, Style style)
Adds an object to the defined cell address.void
addCell(Object value, String address)
Adds an object to the defined cell address.void
addCell(Object value, String address, Style style)
Adds an object to the defined cell address.void
addCellFormula(String formula, int columnAddress, int rowAddress)
Adds a cell formula as string to the defined cell addressvoid
addCellFormula(String formula, int columnAddress, int rowAddress, Style style)
Adds a cell formula as string to the defined cell addressvoid
addCellFormula(String formula, String address)
Adds a cell formula as string to the defined cell addressvoid
addCellFormula(String formula, String address, Style style)
Adds a cell formula as string to the defined cell addressvoid
addCellRange(List<Object> values, Address startAddress, Address endAddress)
Adds a list of object values to a defined cell range.void
addCellRange(List<Object> values, Address startAddress, Address endAddress, Style style)
Adds a list of object values to a defined cell range.void
addCellRange(List<Object> values, String cellRange)
Adds a list of object values to a defined cell range.void
addCellRange(List<Object> values, String cellRange, Style style)
Adds a list of object values to a defined cell range.void
addHiddenColumn(int columnNumber)
Sets the defined column as hiddenvoid
addHiddenColumn(String columnAddress)
Sets the defined column as hiddenvoid
addHiddenRow(int rowNumber)
Sets the defined row as hiddenvoid
addNextCell(Object value)
Adds an object to the next cell position.void
addNextCell(Object value, Style style)
Adds an object to the next cell position.void
addNextCellFormula(String formula)
Adds a formula as string to the next cell positionvoid
addNextCellFormula(String formula, Style style)
Adds a formula as string to the next cell positionvoid
clearActiveStyle()
Clears the active style of the worksheet.Range
getAutoFilterRange()
Gets the range of the auto filter.Cell
getCell(int columnNumber, int rowNumber)
Gets the cell of the specified column and row number (zero-based)Cell
getCell(Address address)
Gets the cell of the specified addressMap<String,Cell>
getCells()
Gets the cells of the worksheet as map with the cell address as key and the cell object as valueMap<Integer,Column>
getColumns()
Gets all columns with non-standard properties, like auto filter applied or a special width as map with the zero-based column index as key and the column object as valueWorksheet.CellDirection
getCurrentCellDirection()
Gets the direction when using AddNextCell methodint
getCurrentColumnNumber()
Gets the current column number (zero based)int
getCurrentRowNumber()
Gets the current row number (zero based)float
getDefaultColumnWidth()
Gets the default column widthfloat
getDefaultRowHeight()
Map<Integer,Boolean>
getHiddenRows()
Gets the hidden rows as map with the zero-based row number as key and a boolean as value.int
getLastColumnNumber()
Gets the last existing column number in the current worksheet (zero-based)int
getLastRowNumber()
Gets the last existing row number in the current worksheet (zero-based)Map<String,Range>
getMergedCells()
Gets the merged cells (only references) as map with the cell address as key and the range object as valueMap<Integer,Float>
getRowHeights()
Gets defined row heights as map with the zero-based row number as key and the height (float from 0 to 409.5) as valueRange
getSelectedCells()
Gets the range of selected cells of this worksheet.int
getSheetID()
Gets the internal ID of the worksheetString
getSheetName()
Gets the name of the sheetString
getSheetProtectionPassword()
Gets the password used for sheet protectionList<Worksheet.SheetProtectionValue>
getSheetProtectionValues()
Gets the list of SheetProtectionValues.Workbook
getWorkbookReference()
Gets the Reference to the parent Workbookvoid
goToNextColumn()
Moves the current position to the next columnvoid
goToNextColumn(int numberOfColumns)
Moves the current position to the next column with the number of cells to movevoid
goToNextRow()
Moves the current position to the next row (use for a new line)void
goToNextRow(int numberOfRows)
Moves the current position to the next row with the number of cells to move (use for a new line)boolean
hasCell(int columnNumber, int rowNumber)
Gets whether the specified address exists in the worksheet.boolean
hasCell(Address address)
Gets whether the specified address exists in the worksheet.boolean
isUseSheetProtection()
Gets whether the worksheet is protectedString
mergeCells(Address startAddress, Address endAddress)
Merges the defined cell rangeString
mergeCells(Range cellRange)
Merges the defined cell rangeString
mergeCells(String cellRange)
Merges the defined cell rangevoid
recalculateAutoFilter()
Method to recalculate the auto filter (columns) of this worksheet.void
recalculateColumns()
Method to recalculate the collection of columns of this worksheet.void
removeAutoFilter()
Removes auto filters from the worksheetboolean
removeCell(int columnAddress, int rowAddress)
Removes a previous inserted cell at the defined addressboolean
removeCell(String address)
Removes a previous inserted cell at the defined addressvoid
removeHiddenColumn(int columnNumber)
Sets a previously defined, hidden column as visible againvoid
removeHiddenColumn(String columnAddress)
Sets a previously defined, hidden column as visible againvoid
removeHiddenRow(int rowNumber)
Sets a previously defined, hidden row as visible againvoid
removeMergedCells(String range)
Removes the defined merged cell rangevoid
removeSelectedCells()
Removes the cell selection of this worksheetstatic String
sanitizeWorksheetName(String input, Workbook workbook)
Sanitizes a worksheet namevoid
setActiveStyle(Style style)
Sets the active style of the worksheet.void
setAutoFilter(int startColumn, int endColumn)
Sets the column auto filter within the defined column rangevoid
setAutoFilterRange(String range)
Sets the column auto filter within the defined column rangevoid
setColumnWidth(int columnNumber, float width)
Sets the width of the passed column number (zero-based)void
setColumnWidth(String columnAddress, float width)
Set the current cell addressvoid
setCurrentCellAddress(int columnAddress, int rowAddress)
Set the current cell addressvoid
setCurrentCellAddress(String address)
Set the current cell addressvoid
setCurrentCellDirection(Worksheet.CellDirection currentCellDirection)
Sets the direction when using AddNextCell methodvoid
setCurrentColumnNumber(int columnNumber)
Sets the current column number (zero based)void
setCurrentRowNumber(int rowNumber)
Sets the current row number (zero based)void
setDefaultColumnWidth(float defaultColumnWidth)
Sets the default column widthvoid
setDefaultRowHeight(float defaultRowHeight)
Sets the default Row heightvoid
setRowHeight(int rowNumber, float height)
Sets the height of the passed row number (zero-based)void
setSelectedCells(Address startAddress, Address endAddress)
Sets the selected cells on this worksheetvoid
setSelectedCells(Range range)
Sets the selected cells on this worksheetvoid
setSelectedCells(String range)
Sets the selected cells on this worksheetvoid
setSheetID(int sheetID)
Sets the internal ID of the worksheetvoid
setSheetName(String sheetName)
Sets the name of the sheetvoid
setSheetName(String sheetName, boolean sanitize)
Sets the name of the sheetvoid
setSheetProtectionPassword(String password)
Sets or removes the password for worksheet protection.void
setUseSheetProtection(boolean useSheetProtection)
Sets whether the worksheet is protectedvoid
setWorkbookReference(Workbook workbookReference)
Sets the Reference to the parent Workbook
-
-
-
Field Detail
-
DEFAULT_COLUMN_WIDTH
public static final float DEFAULT_COLUMN_WIDTH
Default column width as constant- See Also:
- Constant Field Values
-
DEFAULT_ROW_HEIGHT
public static final float DEFAULT_ROW_HEIGHT
Default row height as constant- See Also:
- Constant Field Values
-
MAX_COLUMN_NUMBER
public static final int MAX_COLUMN_NUMBER
Maximum column number (zero-based)- See Also:
- Constant Field Values
-
MAX_COLUMN_WIDTH
public static final float MAX_COLUMN_WIDTH
Maximum column width as constant- See Also:
- Constant Field Values
-
MAX_ROW_NUMBER
public static final int MAX_ROW_NUMBER
Maximum row number (zero-based)- See Also:
- Constant Field Values
-
MAX_ROW_HEIGHT
public static final float MAX_ROW_HEIGHT
Maximum row height as constant- See Also:
- Constant Field Values
-
MIN_COLUMN_NUMBER
public static final int MIN_COLUMN_NUMBER
Minimum column number (zero-based)- See Also:
- Constant Field Values
-
MIN_COLUMN_WIDTH
public static final float MIN_COLUMN_WIDTH
Minimum column width as constant- See Also:
- Constant Field Values
-
MIN_ROW_NUMBER
public static final int MIN_ROW_NUMBER
Minimum row number (zero-based)- See Also:
- Constant Field Values
-
MIN_ROW_HEIGHT
public static final float MIN_ROW_HEIGHT
Minimum row height as constant- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Worksheet
public Worksheet()
Default constructor. A worksheet created with this constructor cannot be used to assign styles to a cell. This will cause an exception unless a reference to the workbook was set- Throws:
StyleException
- Thrown if a style is added to the worksheet without w workbook reference
-
Worksheet
public Worksheet(Workbook reference)
Constructor with workbook reference- Parameters:
reference
- Reference to the parent Workbook- Throws:
FormatException
- Thrown if the name contains illegal characters or is too long
-
Worksheet
public Worksheet(String name, int id, Workbook reference)
Constructor with workbook reference, name and sheet ID- Parameters:
name
- Name of the worksheetid
- ID of the worksheet (for internal use)reference
- Reference to the parent Workbook- Throws:
FormatException
- Thrown if the name contains illegal characters or is too long
-
-
Method Detail
-
setAutoFilterRange
public void setAutoFilterRange(String range)
Sets the column auto filter within the defined column range- Parameters:
range
- Range to apply auto filter on. The range could be 'A1:C10' for instance. The end row will be recalculated automatically when saving the file- Throws:
RangeException
- Thrown if the passed range out of rangeFormatException
- Thrown if the passed range is malformed
-
getAutoFilterRange
public Range getAutoFilterRange()
Gets the range of the auto filter. If null, no auto filters are applied- Returns:
- Range of auto filter
-
getCells
public Map<String,Cell> getCells()
Gets the cells of the worksheet as map with the cell address as key and the cell object as value- Returns:
- List of Cell objects
-
getColumns
public Map<Integer,Column> getColumns()
Gets all columns with non-standard properties, like auto filter applied or a special width as map with the zero-based column index as key and the column object as value- Returns:
- map of columns
-
getCurrentCellDirection
public Worksheet.CellDirection getCurrentCellDirection()
Gets the direction when using AddNextCell method- Returns:
- Cell direction
-
setCurrentCellDirection
public void setCurrentCellDirection(Worksheet.CellDirection currentCellDirection)
Sets the direction when using AddNextCell method- Parameters:
currentCellDirection
- Cell direction
-
setCurrentColumnNumber
public void setCurrentColumnNumber(int columnNumber)
Sets the current column number (zero based)- Parameters:
columnNumber
- Column number (zero based)- Throws:
RangeException
- Thrown if the number is out of the valid range. Range is from 0 to 16383 (16384 columns)
-
setCurrentRowNumber
public void setCurrentRowNumber(int rowNumber)
Sets the current row number (zero based)- Parameters:
rowNumber
- Row number (zero based)- Throws:
RangeException
- Thrown if the number is out of the valid range. Range is from 0 to 1048575 (1048576 rows)
-
getCurrentColumnNumber
public int getCurrentColumnNumber()
Gets the current column number (zero based)- Returns:
- Column number (zero-based)
-
getCurrentRowNumber
public int getCurrentRowNumber()
Gets the current row number (zero based)- Returns:
- Row number (zero-based)
-
getDefaultColumnWidth
public float getDefaultColumnWidth()
Gets the default column width- Returns:
- Default column width
-
setDefaultColumnWidth
public void setDefaultColumnWidth(float defaultColumnWidth)
Sets the default column width- Parameters:
defaultColumnWidth
- Default column width- Throws:
RangeException
- Throws a RangeException exception if the passed width is out of range (set)
-
getDefaultRowHeight
public float getDefaultRowHeight()
-
setDefaultRowHeight
public void setDefaultRowHeight(float defaultRowHeight)
Sets the default Row height- Parameters:
defaultRowHeight
- Default Row height- Throws:
RangeException
- Throws a RangeException exception if the passed height is out of range (set)
-
getHiddenRows
public Map<Integer,Boolean> getHiddenRows()
Gets the hidden rows as map with the zero-based row number as key and a boolean as value. True indicates hidden, false visible. Entries with the value false are not affecting the worksheet. These entries can be removed- Returns:
- Map with hidden rows
-
getMergedCells
public Map<String,Range> getMergedCells()
Gets the merged cells (only references) as map with the cell address as key and the range object as value- Returns:
- Hashmap with merged cell references
-
getRowHeights
public Map<Integer,Float> getRowHeights()
Gets defined row heights as map with the zero-based row number as key and the height (float from 0 to 409.5) as value- Returns:
- Map of row heights
-
getSelectedCells
public Range getSelectedCells()
Gets the range of selected cells of this worksheet. Null if no cells are selected- Returns:
- Cell range of the selected cells
-
setSelectedCells
public void setSelectedCells(String range)
Sets the selected cells on this worksheet- Parameters:
range
- Cell range to select- Throws:
RangeException
- Thrown if the passed range out of rangeFormatException
- Thrown if the passed range is malformed
-
setSelectedCells
public void setSelectedCells(Range range)
Sets the selected cells on this worksheet- Parameters:
range
- Cell range to select
-
getSheetID
public int getSheetID()
Gets the internal ID of the worksheet- Returns:
- Worksheet ID
-
setSheetID
public void setSheetID(int sheetID)
Sets the internal ID of the worksheet- Parameters:
sheetID
- Worksheet ID
-
getSheetName
public String getSheetName()
Gets the name of the sheet- Returns:
- Name of the sheet
-
isUseSheetProtection
public boolean isUseSheetProtection()
Gets whether the worksheet is protected- Returns:
- If true, the worksheet is protected
-
setUseSheetProtection
public void setUseSheetProtection(boolean useSheetProtection)
Sets whether the worksheet is protected- Parameters:
useSheetProtection
- If true, the worksheet is protected
-
getSheetProtectionPassword
public String getSheetProtectionPassword()
Gets the password used for sheet protection- Returns:
- Password (UTF-8)
-
setSheetProtectionPassword
public void setSheetProtectionPassword(String password)
Sets or removes the password for worksheet protection. If set, UseSheetProtection will be also set to true- Parameters:
password
- Password (UTF-8) to protect the worksheet. If the password is null or empty, no password will be used
-
getSheetProtectionValues
public List<Worksheet.SheetProtectionValue> getSheetProtectionValues()
Gets the list of SheetProtectionValues. These values define the allowed actions if the worksheet is protected- Returns:
- List of SheetProtectionValues
-
getWorkbookReference
public Workbook getWorkbookReference()
Gets the Reference to the parent Workbook- Returns:
- Workbook reference
-
setWorkbookReference
public void setWorkbookReference(Workbook workbookReference)
Sets the Reference to the parent Workbook- Parameters:
workbookReference
- Workbook reference
-
addNextCell
public void addNextCell(Object value)
Adds an object to the next cell position. If the type of the value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
value
- Unspecified value to insert- Throws:
RangeException
- Thrown if the next cell is out of range (on row or column)
-
addNextCell
public void addNextCell(Object value, Style style)
Adds an object to the next cell position. If the type of the value does not match with one of the supported data types, it will be casted to a String.A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
value
- Unspecified value to insertstyle
- Style object to apply on this cell- Throws:
StyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCell
public void addCell(Object value, int columnAddress, int rowAddress)
Adds an object to the defined cell address. If the type of the value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
value
- Unspecified value to insertcolumnAddress
- Column number (zero based)rowAddress
- Row number (zero based)- Throws:
StyleException
- Thrown if the active style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCell
public void addCell(Object value, int columnAddress, int rowAddress, Style style)
Adds an object to the defined cell address. If the type of the value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
value
- Unspecified value to insertcolumnAddress
- Column number (zero based)rowAddress
- Row number (zero based)style
- Style to apply on the cell- Throws:
StyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCell
public void addCell(Object value, String address)
Adds an object to the defined cell address. If the type of the value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
value
- Unspecified value to insertaddress
- Cell address in the format A1 - XFD1048576- Throws:
FormatException
- Thrown if the passed address is malformedStyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCell
public void addCell(Object value, String address, Style style)
Adds an object to the defined cell address. If the type of the value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
value
- Unspecified value to insertaddress
- Cell address in the format A1 - XFD1048576style
- Style to apply on the cell- Throws:
FormatException
- Thrown if the passed address is malformedStyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellFormula
public void addCellFormula(String formula, String address)
Adds a cell formula as string to the defined cell address- Parameters:
formula
- Formula to insertaddress
- Cell address in the format A1 - XFD1048576- Throws:
FormatException
- Thrown if the passed address is malformedStyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellFormula
public void addCellFormula(String formula, String address, Style style)
Adds a cell formula as string to the defined cell address- Parameters:
formula
- Formula to insertaddress
- Cell address in the format A1 - XFD1048576style
- Style to apply on the cell- Throws:
FormatException
- Thrown if the passed address is malformedStyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellFormula
public void addCellFormula(String formula, int columnAddress, int rowAddress)
Adds a cell formula as string to the defined cell address- Parameters:
formula
- Formula to insertcolumnAddress
- Column number (zero based)rowAddress
- Row number (zero based)- Throws:
StyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellFormula
public void addCellFormula(String formula, int columnAddress, int rowAddress, Style style)
Adds a cell formula as string to the defined cell address- Parameters:
formula
- Formula to insertcolumnAddress
- Column number (zero based)rowAddress
- Row number (zero based)style
- Style to apply on the cell- Throws:
StyleException
- Thrown if the passed style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addNextCellFormula
public void addNextCellFormula(String formula)
Adds a formula as string to the next cell position- Parameters:
formula
- Formula to insert- Throws:
StyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addNextCellFormula
public void addNextCellFormula(String formula, Style style)
Adds a formula as string to the next cell position- Parameters:
formula
- Formula to insertstyle
- Style to apply on the cell- Throws:
StyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellRange
public void addCellRange(List<Object> values, Address startAddress, Address endAddress)
Adds a list of object values to a defined cell range. If the type of the a particular value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
values
- List of unspecified objects to insertstartAddress
- Start addressendAddress
- End address- Throws:
StyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellRange
public void addCellRange(List<Object> values, Address startAddress, Address endAddress, Style style)
Adds a list of object values to a defined cell range. If the type of the a particular value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
values
- List of unspecified objects to insertstartAddress
- Start addressendAddress
- End addressstyle
- Style to apply on the all cells of the range- Throws:
StyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellRange
public void addCellRange(List<Object> values, String cellRange)
Adds a list of object values to a defined cell range. If the type of the a particular value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
The data types in the passed list can be mixed. Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
values
- List of unspecified objects to insertcellRange
- Cell range as string in the format like A1:D1 or X10:X22- Throws:
FormatException
- Thrown if the passed address is malformedStyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
addCellRange
public void addCellRange(List<Object> values, String cellRange, Style style)
Adds a list of object values to a defined cell range. If the type of the a particular value does not match with one of the supported data types, it will be casted to a String. A prepared object of the type Cell will not be casted but adjusted
The data types in the passed list can be mixed. Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, LocalTime, boolean. All other types will be casted into a String using the default toString() method- Parameters:
values
- List of unspecified objects to insertcellRange
- Cell range as string in the format like A1:D1 or X10:X22style
- Style to apply on the all cells of the range- Throws:
FormatException
- Thrown if the passed address is malformedStyleException
- Thrown if the default style was malformedRangeException
- Thrown if the next cell is out of range (on row or column)
-
removeCell
public boolean removeCell(int columnAddress, int rowAddress)
Removes a previous inserted cell at the defined address- Parameters:
columnAddress
- Column number (zero based)rowAddress
- Row number (zero based)- Returns:
- Returns true if the cell could be removed (existed), otherwise false (did not exist)
- Throws:
RangeException
- Thrown if the resolved cell address is out of range
-
removeCell
public boolean removeCell(String address)
Removes a previous inserted cell at the defined address- Parameters:
address
- Cell address in the format A1 - XFD1048576- Returns:
- Returns true if the cell could be removed (existed), otherwise false (did not exist)
- Throws:
RangeException
- Thrown if the resolved cell address is out of rangeFormatException
- Thrown if the passed address is malformed
-
addAllowedActionOnSheetProtection
public void addAllowedActionOnSheetProtection(Worksheet.SheetProtectionValue typeOfProtection)
Method to add allowed actions if the worksheet is protected. If one or more values are added, UseSheetProtection will be set to true- Parameters:
typeOfProtection
- Allowed action on the worksheet or cells
-
addHiddenColumn
public void addHiddenColumn(int columnNumber)
Sets the defined column as hidden- Parameters:
columnNumber
- Column number to hide on the worksheet- Throws:
RangeException
- Thrown if the passed row number was out of range
-
addHiddenColumn
public void addHiddenColumn(String columnAddress)
Sets the defined column as hidden- Parameters:
columnAddress
- Column address to hide on the worksheet- Throws:
RangeException
- Thrown if the passed row number was out of range
-
addHiddenRow
public void addHiddenRow(int rowNumber)
Sets the defined row as hidden- Parameters:
rowNumber
- Row number to hide on the worksheet- Throws:
RangeException
- Thrown if the passed column number was out of range
-
clearActiveStyle
public void clearActiveStyle()
Clears the active style of the worksheet. All later added cells will contain no style unless another active style is set
-
getCell
public Cell getCell(Address address)
Gets the cell of the specified address- Parameters:
address
- Address of the cell- Returns:
- Cell object
- Throws:
WorksheetException
- Throws a WorksheetException if the cell was not found on the cell table of this worksheet
-
getCell
public Cell getCell(int columnNumber, int rowNumber)
Gets the cell of the specified column and row number (zero-based)- Parameters:
columnNumber
- Column address of the cellrowNumber
- Row address of the cell- Returns:
- Cell object
- Throws:
WorksheetException
- Throws a WorksheetException if the cell was not found on the cell table of this worksheet
-
hasCell
public boolean hasCell(Address address)
Gets whether the specified address exists in the worksheet. Existing means that a value was stored at the address- Parameters:
address
- Address to check- Returns:
- True if the cell exists, otherwise false
-
hasCell
public boolean hasCell(int columnNumber, int rowNumber)
Gets whether the specified address exists in the worksheet. Existing means that a value was stored at the address- Parameters:
columnNumber
- Column number of the cell to check (zero-based)rowNumber
- Row number of the cell to check (zero-based)- Returns:
- True if the cell exists, otherwise false
-
getLastColumnNumber
public int getLastColumnNumber()
Gets the last existing column number in the current worksheet (zero-based)- Returns:
- Zero-based column number. In case of a empty worksheet, -1 will be returned
-
getLastRowNumber
public int getLastRowNumber()
Gets the last existing row number in the current worksheet (zero-based)- Returns:
- Zero-based row number. In case of a empty worksheet, -1 will be returned
-
setColumnWidth
public void setColumnWidth(String columnAddress, float width)
Set the current cell address- Parameters:
columnAddress
- Column number (zero based)width
- Row number (zero based)- Throws:
RangeException
- Thrown if the address is out of the valid range. Range is from 0 to 16383 (16384 columns)
-
setCurrentCellAddress
public void setCurrentCellAddress(String address)
Set the current cell address- Parameters:
address
- Cell address in the format A1 - XFD1048576- Throws:
RangeException
- Thrown if the address is out of the valid range. Range is for rows from 0 to 1048575 (1048576 rows) and for columns from 0 to 16383 (16384 columns)FormatException
- Thrown if the passed address is malformed
-
setSheetName
public void setSheetName(String sheetName)
Sets the name of the sheet- Parameters:
sheetName
- Name of the sheet- Throws:
FormatException
- Thrown if the name contains illegal characters or is longer than 31 characters
-
setSheetName
public void setSheetName(String sheetName, boolean sanitize)
Sets the name of the sheet- Parameters:
sheetName
- Name of the sheetsanitize
- If true, the filename will be sanitized automatically according to the specifications of Excel- Throws:
WorksheetException
- Thrown if no workbook is referenced. This information is necessary to determine whether the name already exists
-
goToNextColumn
public void goToNextColumn()
Moves the current position to the next column
-
goToNextColumn
public void goToNextColumn(int numberOfColumns)
Moves the current position to the next column with the number of cells to move- Parameters:
numberOfColumns
- Number of columns to move
-
goToNextRow
public void goToNextRow()
Moves the current position to the next row (use for a new line)
-
goToNextRow
public void goToNextRow(int numberOfRows)
Moves the current position to the next row with the number of cells to move (use for a new line)- Parameters:
numberOfRows
- Number of rows to move
-
mergeCells
public String mergeCells(Range cellRange)
Merges the defined cell range- Parameters:
cellRange
- Range to merge- Returns:
- Returns the validated range of the merged cells (e.g. 'A1:B12')
-
mergeCells
public String mergeCells(String cellRange)
Merges the defined cell range- Parameters:
cellRange
- Range to merge (e.g. 'A1:B12')- Returns:
- Returns the validated range of the merged cells (e.g. 'A1:B12')
- Throws:
FormatException
- Thrown if the passed address is malformed
-
mergeCells
public String mergeCells(Address startAddress, Address endAddress)
Merges the defined cell range- Parameters:
startAddress
- Start address of the merged cell rangeendAddress
- End address of the merged cell range- Returns:
- Returns the validated range of the merged cells (e.g. 'A1:B12')
-
recalculateAutoFilter
public void recalculateAutoFilter()
Method to recalculate the auto filter (columns) of this worksheet. This is an internal method. There is no need to use it. It must be public to require access from the LowLevel class
-
recalculateColumns
public void recalculateColumns()
Method to recalculate the collection of columns of this worksheet. This is an internal method. There is no need to use it. It must be public to require access from the LowLevel class
-
removeAutoFilter
public void removeAutoFilter()
Removes auto filters from the worksheet
-
removeHiddenColumn
public void removeHiddenColumn(int columnNumber)
Sets a previously defined, hidden column as visible again- Parameters:
columnNumber
- Column number to make visible again- Throws:
RangeException
- Thrown if the passed row number was out of range
-
removeHiddenColumn
public void removeHiddenColumn(String columnAddress)
Sets a previously defined, hidden column as visible again- Parameters:
columnAddress
- Column address to make visible again- Throws:
RangeException
- Thrown if the passed row number was out of range
-
removeHiddenRow
public void removeHiddenRow(int rowNumber)
Sets a previously defined, hidden row as visible again- Parameters:
rowNumber
- Row number to hide on the worksheet- Throws:
RangeException
- Thrown if the passed column number was out of range
-
removeMergedCells
public void removeMergedCells(String range)
Removes the defined merged cell range- Parameters:
range
- Cell range to remove the merging- Throws:
RangeException
- Thrown if the passed cell range was not merged earlierFormatException
- Thrown if the passed address is malformed
-
removeSelectedCells
public void removeSelectedCells()
Removes the cell selection of this worksheet
-
setActiveStyle
public void setActiveStyle(Style style)
Sets the active style of the worksheet. This style will be assigned to all later added cells- Parameters:
style
- Style to set as active style- Throws:
StyleException
- Thrown if the worksheet has no workbook referenced when trying to set the active style
-
setAutoFilter
public void setAutoFilter(int startColumn, int endColumn)
Sets the column auto filter within the defined column range- Parameters:
startColumn
- Column number with the first appearance of an auto filter drop downendColumn
- Column number with the last appearance of an auto filter drop down- Throws:
RangeException
- Thrown if one of the passed column numbers are out of range
-
setColumnWidth
public void setColumnWidth(int columnNumber, float width)
Sets the width of the passed column number (zero-based)- Parameters:
columnNumber
- Column number (zero-based, from 0 to 16383)width
- Width from 0 to 255.0- Throws:
RangeException
- Thrown if the address is out of the valid range. Range is from 0 to 16383 (16384 columns)
-
setCurrentCellAddress
public void setCurrentCellAddress(int columnAddress, int rowAddress)
Set the current cell address- Parameters:
columnAddress
- Column number (zero based)rowAddress
- Row number (zero based)- Throws:
RangeException
- Thrown if the address is out of the valid range. Range is for rows from 0 to 1048575 (1048576 rows) and for columns from 0 to 16383 (16384 columns)
-
setRowHeight
public void setRowHeight(int rowNumber, float height)
Sets the height of the passed row number (zero-based)- Parameters:
rowNumber
- Row number (zero-based, 0 to 1048575)height
- Height from 0 to 409.5- Throws:
RangeException
- Thrown if the address is out of the valid range. Range is from 0 to 1048575 (1048576 rows)
-
setSelectedCells
public void setSelectedCells(Address startAddress, Address endAddress)
Sets the selected cells on this worksheet- Parameters:
startAddress
- Start address of the rangeendAddress
- End address of the range
-
-