Class Sheet

java.lang.Object
com.github.miachm.sods.Sheet
All Implemented Interfaces:
Cloneable, Comparable<Sheet>

public class Sheet extends Object implements Cloneable, Comparable<Sheet>
Represents a sheet in a Spreadsheet. You can create empty sheets and add to an existing Spreadsheet
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sheet(String name)
    Create an empty sheet with a given name.
    Sheet(String name, int rows, int columns)
    Create an empty sheet with a given name and dimmensions
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Append a column at the end of the Spreadsheet
    void
    appendColumns(int howmany)
    Append many columns at the end of the Spreadsheet.
    void
    Append a new row at the end of the heet
    void
    appendRows(int howmany)
    Append many rows at the end of the Spreadsheet
    void
    Clear all the content of the sheet.
     
    boolean
    columnIsHidden(int column)
    Determinies if a specific column is hidden or not
    int
    compareTo method, this comparator only compare the names Note: this class has a natural ordering that is inconsistent with equals.
    void
    deleteColumn(int column)
    Delete a specific column on the sheet
    void
    deleteColumns(int column, int howmany)
    Delete a number of columns starting in a specific index
    void
    deleteRow(int row)
    Delete a specific row in the sheet
    void
    deleteRows(int row, int howmany)
    Delete a number of rows starting in a specific index
    boolean
    Equals 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.
    Gets the default cell style of a specific column.
    int
    Deprecated.
    Use getMaxColumn() instead Return the last column of the sheet which contains useful data
    int
    Deprecated.
    Use getMaxRow() instead Return the last row of the sheet which contains useful data
    int
    The number of columns created in this sheet
    int
    The number of rows created in this sheet
    Obtains the name of this sheet
    getRange(int row, int column)
    Obtains a @Range which contains a specific cell of the sheet
    getRange(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.
    getRange(String a1Notation)
    Obtains a @Range using the A1 Notation format.
    getRowHeight(int row)
    Get the height of a row.
    int
     
    void
    hideColumn(int column)
    Hides a column specified by his index
    void
    hideColumns(int column, int howmany)
    Hides a column specified by a range
    void
    hideRow(int row)
    Hides a row specified by his index
    void
    hideRows(int row, int howmany)
    Hides a row specified by a range
    void
    Mark this sheet as hidden
    void
    insertColumnAfter(int afterPosition)
    Insert a column after a specific position
    void
    insertColumnBefore(int beforePosition)
    Insert a column before a specific position
    void
    insertColumnsAfter(int columnIndex, int howmany)
    Insert a number of columns after a specific position
    void
    insertColumnsBefore(int columnIndex, int howmany)
    Insert a number of columns before a specific position
    void
    insertRowAfter(int afterPosition)
    Insert a row after a specific position
    void
    insertRowBefore(int beforePosition)
    Insert a row before a specific position
    void
    insertRowsAfter(int rowIndex, int howmany)
    Insert a row after a specific position
    void
    insertRowsBefore(int rowIndex, int howmany)
    Insert a row before a specific position
    boolean
    Determinies if the sheet is marked as hidden or not
    boolean
    Determines if this sheet is protected by a password or not
    boolean
    rowIsHidden(int row)
    Determinies if a specific row is hidden or not
    void
    setColumnWidth(int column, Double width)
    Set a specific column width to a specific column.
    void
    setColumnWidths(int column, int numColumns, Double width)
    Set a column width to a specific set of columns.
    void
    setDefaultColumnCellStyle(int column, Style defaultColumnCellStyle)
    Sets the default cell style of a specific column.
    void
    setName(String newName)
    Rename this sheet
    void
    Sets a password for a sheet.
    void
    setRowHeight(int row, Double height)
    Set a specific row height to a specific row.
    void
    setRowHeights(int row, int numRows, Double height)
    Set a row height to a specific set of rows.
    void
    showColumn(int column)
    Unhides the columns at the given index.
    void
    showRow(int row)
    Unhides the row at the given index.
    void
    Mark this sheet as visible
     
    void
    Deprecated.
    This function should not be called since it won't make any visible difference to the user.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Sheet

      public Sheet(String name)
      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

      public Sheet(String name, int rows, int columns)
      Create an empty sheet with a given name and dimmensions
      Parameters:
      name - A name which identifies this sheet
      rows - Number of rows in the sheet
      columns - Number of columns in the sheet
      Throws:
      IllegalArgumentException - If the number of rows/columns are negative
      NullPointerException - 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

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      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 start
      howmany - 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 sheet
      IllegalArgumentException - 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 start
      howmany - 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

      public Double getColumnWidth(int column)
      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

      public Double getRowHeight(int row)
      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

      public Range 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

      public String getName()
      Obtains the name of this sheet
      Returns:
      The name of the sheet
    • getRange

      public Range getRange(int row, int column)
      Obtains a @Range which contains a specific cell of the sheet
      Parameters:
      row - X Coordinate of the cell
      column - Y Coordinate of the cell
      Returns:
      A range which represents the cell
      Throws:
      IndexOutOfBoundsException - if it represents a invalid range
    • getRange

      public Range getRange(int row, int column, int numRows)
      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 cell
      column - Y Coordinate of the starting cell
      numRows - How many rows to take
      Returns:
      A range which represents the cell
      Throws:
      IndexOutOfBoundsException - if it represents a invalid range
      See Also:
    • getRange

      public Range getRange(int row, int column, int numRows, int numColumns)
      Obtains a @Range which represents a subset of the Sheet.
      Parameters:
      row - X Coordinate of the starting cell
      column - Y Coordinate of the starting cell
      numRows - How many rows to take
      numColumns - How many columns to take
      Returns:
      A range which represents the cell
      Throws:
      IndexOutOfBoundsException - if it represents a invalid range
    • getRange

      public Range getRange(String a1Notation)
      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 null
      IllegalArgumentException - If the argument is not a valid A1Notation
      IndexOutOfBoundsException - 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 row
      howmany - 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 row
      howmany - 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 insert
      howmany - How many columns to insert
      Throws:
      IndexOutOfBoundsException - if the columnIndex is out of bounds, no changes will be done
      IllegalArgumentException - 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 insert
      howmany - How many columns to insert
      Throws:
      IndexOutOfBoundsException - if the columnIndex is out of bounds, no changes will be done
      IllegalArgumentException - 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 insert
      howmany - How many rows to insert
      Throws:
      IndexOutOfBoundsException - if the index is out bounds, no changes will be done to the sheet
      IllegalArgumentException - 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 insert
      howmany - How many rows to insert
      Throws:
      IndexOutOfBoundsException - if the index is out bounds, no changes will be done to sheet
      IllegalArgumentException - if howmany is negative, no changes will be done to the sheet
    • setColumnWidth

      public void setColumnWidth(int column, Double width)
      Set a specific column width to a specific column. Unit: millimeters (mm).
      Parameters:
      column - The index of the column
      width - The width of the column in millimeters. It can be null to "unset" the width
      Throws:
      IndexOutOfBoundsException - if the column is negative or >= numColumns
      IllegalArgumentException - Width has to be positive
    • setColumnWidths

      public void setColumnWidths(int column, int numColumns, Double width)
      Set a column width to a specific set of columns. Unit: millimeters (mm).
      Parameters:
      column - The index of the column
      numColumns - 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 >= numColumns
      IllegalArgumentException - Width and numColumns has to be positive
    • setRowHeight

      public void setRowHeight(int row, Double height)
      Set a specific row height to a specific row. Unit: millimeters (mm).
      Parameters:
      row - The index of the row
      height - The height of the row in millimeters. It can be null to "unset" the height
      Throws:
      IndexOutOfBoundsException - if the row is negative or >= numRows
      IllegalArgumentException - Height has to be positive
    • setRowHeights

      public void setRowHeights(int row, int numRows, Double height)
      Set a row height to a specific set of rows. Unit: millimeters (mm).
      Parameters:
      row - The index of the row
      numRows - 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 >= numRows
      IllegalArgumentException - 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

      public Style getDefaultColumnCellStyle(int column)
      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

      public void setDefaultColumnCellStyle(int column, Style defaultColumnCellStyle)
      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 column
      defaultColumnCellStyle - The default cell style of the column. A clone of this object will be stored.
      Throws:
      IndexOutOfBoundsException - if the column is negative or >= numColumns
      IllegalArgumentException - 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 visibility
      Trim 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

      public void setPassword(String key) throws NoSuchAlgorithmException
      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 empty
      NoSuchAlgorithmException - if your java installation doesn't have SHA-256 hash encryption
    • setName

      public void setName(String newName)
      Rename this sheet
      Parameters:
      newName - The new name of the sheet
    • equals

      public boolean equals(Object o)
      Equals method, two sheets are considered the same if have the same name and the same content (include formatting)
      Overrides:
      equals in class Object
      Parameters:
      o - The object to compare
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(Sheet o)
      compareTo method, this comparator only compare the names Note: this class has a natural ordering that is inconsistent with equals.
      Specified by:
      compareTo in interface Comparable<Sheet>
      Parameters:
      o - The object to compare
    • toString

      public String toString()
      Overrides:
      toString in class Object