Package com.github.miachm.sods
Class Sheet
java.lang.Object
com.github.miachm.sods.Sheet
- All Implemented Interfaces:
Cloneable,Comparable<Sheet>
Represents a sheet in a Spreadsheet.
You can create empty sheets and add to an existing Spreadsheet
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppend a column at the end of the SpreadsheetvoidappendColumns(int howmany) Append many columns at the end of the Spreadsheet.voidAppend a new row at the end of the heetvoidappendRows(int howmany) Append many rows at the end of the Spreadsheetvoidclear()Clear all the content of the sheet.clone()booleancolumnIsHidden(int column) Determinies if a specific column is hidden or notintcompareTo method, this comparator only compare the names Note: this class has a natural ordering that is inconsistent with equals.voiddeleteColumn(int column) Delete a specific column on the sheetvoiddeleteColumns(int column, int howmany) Delete a number of columns starting in a specific indexvoiddeleteRow(int row) Delete a specific row in the sheetvoiddeleteRows(int row, int howmany) Delete a number of rows starting in a specific indexbooleanEquals method, two sheets are considered the same if have the same name and the same content (include formatting)getColumnWidth(int column) Get the width of a column.Get a @Range which contains the whole Sheet content.getDefaultColumnCellStyle(int column) Gets the default cell style of a specific column.intDeprecated.Use getMaxColumn() instead Return the last column of the sheet which contains useful dataintDeprecated.Use getMaxRow() instead Return the last row of the sheet which contains useful dataintThe number of columns created in this sheetintThe number of rows created in this sheetgetName()Obtains the name of this sheetgetRange(int row, int column) Obtains a @Range which contains a specific cell of the sheetgetRange(int row, int column, int numRows) Obtains a @Range which represents a number of rows starting in a specific Cell.getRange(int row, int column, int numRows, int numColumns) Obtains a @Range which represents a subset of the Sheet.Obtains a @Range using the A1 Notation format.getRowHeight(int row) Get the height of a row.inthashCode()voidhideColumn(int column) Hides a column specified by his indexvoidhideColumns(int column, int howmany) Hides a column specified by a rangevoidhideRow(int row) Hides a row specified by his indexvoidhideRows(int row, int howmany) Hides a row specified by a rangevoidMark this sheet as hiddenvoidinsertColumnAfter(int afterPosition) Insert a column after a specific positionvoidinsertColumnBefore(int beforePosition) Insert a column before a specific positionvoidinsertColumnsAfter(int columnIndex, int howmany) Insert a number of columns after a specific positionvoidinsertColumnsBefore(int columnIndex, int howmany) Insert a number of columns before a specific positionvoidinsertRowAfter(int afterPosition) Insert a row after a specific positionvoidinsertRowBefore(int beforePosition) Insert a row before a specific positionvoidinsertRowsAfter(int rowIndex, int howmany) Insert a row after a specific positionvoidinsertRowsBefore(int rowIndex, int howmany) Insert a row before a specific positionbooleanisHidden()Determinies if the sheet is marked as hidden or notbooleanDetermines if this sheet is protected by a password or notbooleanrowIsHidden(int row) Determinies if a specific row is hidden or notvoidsetColumnWidth(int column, Double width) Set a specific column width to a specific column.voidsetColumnWidths(int column, int numColumns, Double width) Set a column width to a specific set of columns.voidsetDefaultColumnCellStyle(int column, Style defaultColumnCellStyle) Sets the default cell style of a specific column.voidRename this sheetvoidsetPassword(String key) Sets a password for a sheet.voidsetRowHeight(int row, Double height) Set a specific row height to a specific row.voidsetRowHeights(int row, int numRows, Double height) Set a row height to a specific set of rows.voidshowColumn(int column) Unhides the columns at the given index.voidshowRow(int row) Unhides the row at the given index.voidMark this sheet as visibletoString()voidtrim()Deprecated.This function should not be called since it won't make any visible difference to the user.
-
Constructor Details
-
Sheet
Create an empty sheet with a given name. The sheet will have a 1x1 GRID by default.- Parameters:
name- A name which identifies this sheet
-
Sheet
Create an empty sheet with a given name and dimmensions- Parameters:
name- A name which identifies this sheetrows- Number of rows in the sheetcolumns- Number of columns in the sheet- Throws:
IllegalArgumentException- If the number of rows/columns are negativeNullPointerException- If the number of rows/columns are negative
-
-
Method Details
-
appendRow
public void appendRow()Append a new row at the end of the heet- See Also:
-
appendRows
public void appendRows(int howmany) Append many rows at the end of the Spreadsheet- Parameters:
howmany- The number of rows to be appended- Throws:
IllegalArgumentException- if howmany is negative, no changes will be done to the sheet
-
appendColumn
public void appendColumn()Append a column at the end of the Spreadsheet- See Also:
-
appendColumns
public void appendColumns(int howmany) Append many columns at the end of the Spreadsheet.- Parameters:
howmany- The number of columns to be appended- Throws:
IllegalArgumentException- if howmany is negative, no changes will be done to the sheet
-
clear
public void clear()Clear all the content of the sheet. This doesn't change the number of rows/columns -
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
deleteColumn
public void deleteColumn(int column) Delete a specific column on the sheet- Parameters:
column- The column index to be deleted- Throws:
IndexOutOfBoundsException- if the index is invalid- See Also:
-
deleteColumns
public void deleteColumns(int column, int howmany) Delete a number of columns starting in a specific index- Parameters:
column- The column index to starthowmany- The number of columns to be deleted- Throws:
IndexOutOfBoundsException- If columns + howmany is out bounds of the sheet. No changes will be done to the sheetIllegalArgumentException- if howmany is negative, no changes will be done to the sheet
-
deleteRow
public void deleteRow(int row) Delete a specific row in the sheet- Parameters:
row- The row index to be deleted- Throws:
IndexOutOfBoundsException- if the index is out of bounds- See Also:
-
deleteRows
public void deleteRows(int row, int howmany) Delete a number of rows starting in a specific index- Parameters:
row- The row index where starthowmany- How many rows will be deleted- Throws:
IndexOutOfBoundsException- if row + howmany is out of bounds, no changes will be done to the sheet- See Also:
-
getColumnWidth
Get the width of a column. Unit: millimeters (mm).- Parameters:
column- The column index where start- Returns:
- The width of the column in millimeters, or null if not specified
- Throws:
IndexOutOfBoundsException- if the column index is invalid
-
getRowHeight
Get the height of a row. Unit: millimeters (mm).- Parameters:
row- The row index where start- Returns:
- The height of the row in millimeters, or null if not specified
-
getDataRange
Get a @Range which contains the whole Sheet content. Its useful if you want look at the entire sheet content- Returns:
- The range which contains the whole sheet's content
-
getMaxColumns
public int getMaxColumns()The number of columns created in this sheet- Returns:
- An integer which represents the number of columns in this sheet
-
getMaxRows
public int getMaxRows()The number of rows created in this sheet- Returns:
- An integer which represents the number of rows in this sheet
-
getName
Obtains the name of this sheet- Returns:
- The name of the sheet
-
getRange
Obtains a @Range which contains a specific cell of the sheet- Parameters:
row- X Coordinate of the cellcolumn- Y Coordinate of the cell- Returns:
- A range which represents the cell
- Throws:
IndexOutOfBoundsException- if it represents a invalid range
-
getRange
Obtains a @Range which represents a number of rows starting in a specific Cell. Note: This function only take the first column of every row- Parameters:
row- X Coordinate of the starting cellcolumn- Y Coordinate of the starting cellnumRows- How many rows to take- Returns:
- A range which represents the cell
- Throws:
IndexOutOfBoundsException- if it represents a invalid range- See Also:
-
getRange
Obtains a @Range which represents a subset of the Sheet.- Parameters:
row- X Coordinate of the starting cellcolumn- Y Coordinate of the starting cellnumRows- How many rows to takenumColumns- How many columns to take- Returns:
- A range which represents the cell
- Throws:
IndexOutOfBoundsException- if it represents a invalid range
-
getRange
Obtains a @Range using the A1 Notation format. A1 notation is a string representation of a subset in a Spreadsheet where the column is represented by a capital letter (starting in A) and the row by a row number (starting in 1). For example, you would write: "B3" to obtain the Cell of column B and row 3. You would write "A2:D2" to obtain the cells between A2 and D2 (included). Inconsistent ranges ("C2:A3") are reinterpreted when it's possible. In the example would be ("A3:C2")- Parameters:
a1Notation- The string representation of the range in A1Notation- Returns:
- The range requested
- Throws:
NullPointerException- If the argument is nullIllegalArgumentException- If the argument is not a valid A1NotationIndexOutOfBoundsException- If it represents a invalid range
-
hideRow
public void hideRow(int row) Hides a row specified by his index- Parameters:
row- The index of the row- Throws:
IndexOutOfBoundsException- if the index is invalid
-
hideRows
public void hideRows(int row, int howmany) Hides a row specified by a range- Parameters:
row- The index of the rowhowmany- The number of different rows to hide- Throws:
IndexOutOfBoundsException- if the index is invalid
-
hideColumn
public void hideColumn(int column) Hides a column specified by his index- Parameters:
column- The index of the row- Throws:
IndexOutOfBoundsException- if the index is invalid
-
hideColumns
public void hideColumns(int column, int howmany) Hides a column specified by a range- Parameters:
column- The index of the rowhowmany- The number of columns- Throws:
IndexOutOfBoundsException- if the index is invalid
-
insertColumnAfter
public void insertColumnAfter(int afterPosition) Insert a column after a specific position- Parameters:
afterPosition- The index where insert- Throws:
IndexOutOfBoundsException- if the index is invalid
-
insertColumnBefore
public void insertColumnBefore(int beforePosition) Insert a column before a specific position- Parameters:
beforePosition- The index where insert- Throws:
IndexOutOfBoundsException- if the index is invalid
-
insertColumnsAfter
public void insertColumnsAfter(int columnIndex, int howmany) Insert a number of columns after a specific position- Parameters:
columnIndex- The index where inserthowmany- How many columns to insert- Throws:
IndexOutOfBoundsException- if the columnIndex is out of bounds, no changes will be doneIllegalArgumentException- if howmany is negative, no changes will be done
-
insertColumnsBefore
public void insertColumnsBefore(int columnIndex, int howmany) Insert a number of columns before a specific position- Parameters:
columnIndex- The index where inserthowmany- How many columns to insert- Throws:
IndexOutOfBoundsException- if the columnIndex is out of bounds, no changes will be doneIllegalArgumentException- if howmany is negative, no changes will be done
-
insertRowAfter
public void insertRowAfter(int afterPosition) Insert a row after a specific position- Parameters:
afterPosition- The index where insert- Throws:
IndexOutOfBoundsException- if the index is invalid
-
insertRowBefore
public void insertRowBefore(int beforePosition) Insert a row before a specific position- Parameters:
beforePosition- The index where insert- Throws:
IndexOutOfBoundsException- if the index is invalid
-
insertRowsBefore
public void insertRowsBefore(int rowIndex, int howmany) Insert a row before a specific position- Parameters:
rowIndex- The index where inserthowmany- How many rows to insert- Throws:
IndexOutOfBoundsException- if the index is out bounds, no changes will be done to the sheetIllegalArgumentException- if howmany is negative, no changes will be done to the sheet
-
insertRowsAfter
public void insertRowsAfter(int rowIndex, int howmany) Insert a row after a specific position- Parameters:
rowIndex- The index where inserthowmany- How many rows to insert- Throws:
IndexOutOfBoundsException- if the index is out bounds, no changes will be done to sheetIllegalArgumentException- if howmany is negative, no changes will be done to the sheet
-
setColumnWidth
Set a specific column width to a specific column. Unit: millimeters (mm).- Parameters:
column- The index of the columnwidth- The width of the column in millimeters. It can be null to "unset" the width- Throws:
IndexOutOfBoundsException- if the column is negative or >= numColumnsIllegalArgumentException- Width has to be positive
-
setColumnWidths
Set a column width to a specific set of columns. Unit: millimeters (mm).- Parameters:
column- The index of the columnnumColumns- The number of columns to be modified, starting on index.width- The width of the column in millimeters. It can be null to "unset" the width- Throws:
IndexOutOfBoundsException- if the column is negative or >= numColumnsIllegalArgumentException- Width and numColumns has to be positive
-
setRowHeight
Set a specific row height to a specific row. Unit: millimeters (mm).- Parameters:
row- The index of the rowheight- The height of the row in millimeters. It can be null to "unset" the height- Throws:
IndexOutOfBoundsException- if the row is negative or >= numRowsIllegalArgumentException- Height has to be positive
-
setRowHeights
Set a row height to a specific set of rows. Unit: millimeters (mm).- Parameters:
row- The index of the rownumRows- The number of rows to be modified, starting on index.height- The height of the row in millimeters. It can be null to "unset" the row- Throws:
IndexOutOfBoundsException- if the row is negative or >= numRowsIllegalArgumentException- Height has to be positive
-
showRow
public void showRow(int row) Unhides the row at the given index. If the row wasn't hidden, this method would not have any effect- Parameters:
row- The index of the row- Throws:
IndexOutOfBoundsException- if the row is negative or >= numRows
-
showColumn
public void showColumn(int column) Unhides the columns at the given index. If the column wasn't hidden, this method would not have any effect- Parameters:
column- The index of the row- Throws:
IndexOutOfBoundsException- if the column is negative or >= numColumns
-
rowIsHidden
public boolean rowIsHidden(int row) Determinies if a specific row is hidden or not- Parameters:
row- The index of the row- Returns:
- True if the row is hidden
- Throws:
IndexOutOfBoundsException- if the row is negative or >= numRows
-
columnIsHidden
public boolean columnIsHidden(int column) Determinies if a specific column is hidden or not- Parameters:
column- The index of the row- Returns:
- True if the row is hidden
- Throws:
IndexOutOfBoundsException- if the row is negative or >= numRows
-
isHidden
public boolean isHidden()Determinies if the sheet is marked as hidden or not- Returns:
- True if the sheet is hidden
-
hideSheet
public void hideSheet()Mark this sheet as hidden -
showSheet
public void showSheet()Mark this sheet as visible -
getDefaultColumnCellStyle
Gets the default cell style of a specific column. The default style is used as a fallback whenever a cell in the column doesn't specify its own style. It's safe to manipulate the returned style object since it is a copy of the original one.- Parameters:
column- The index of the column- Returns:
- The default cell style of the column. It cannot be null.
- Throws:
IndexOutOfBoundsException- if the column index is invalid
-
setDefaultColumnCellStyle
Sets the default cell style of a specific column. The default style is used as a fallback whenever a cell in the column doesn't specify its own style.- Parameters:
column- The index of the columndefaultColumnCellStyle- The default cell style of the column. A clone of this object will be stored.- Throws:
IndexOutOfBoundsException- if the column is negative or >= numColumnsIllegalArgumentException- if the style is null
-
getLastRow
public int getLastRow()Deprecated.Use getMaxRow() instead Return the last row of the sheet which contains useful data- Returns:
- The index of the last row
-
getLastColumn
public int getLastColumn()Deprecated.Use getMaxColumn() instead Return the last column of the sheet which contains useful data- Returns:
- The index of the last column
-
trim
public void trim()Deprecated.This function should not be called since it won't make any visible difference to the user. This is going to be moved to private visibilityTrim the sheet removing unused rows/columns -
isProtected
public boolean isProtected()Determines if this sheet is protected by a password or not- Returns:
- True if it's protected
-
setPassword
Sets a password for a sheet. SODS will ignore this setting but other consumers will ask for a password to the user in order to access this sheet- Parameters:
key- the password. Sets the password to null to disable the password protection- Throws:
IllegalArgumentException- if the password parameter is emptyNoSuchAlgorithmException- if your java installation doesn't have SHA-256 hash encryption
-
setName
Rename this sheet- Parameters:
newName- The new name of the sheet
-
equals
Equals method, two sheets are considered the same if have the same name and the same content (include formatting) -
hashCode
public int hashCode() -
compareTo
compareTo method, this comparator only compare the names Note: this class has a natural ordering that is inconsistent with equals.- Specified by:
compareToin interfaceComparable<Sheet>- Parameters:
o- The object to compare
-
toString
-