Class SpreadSheet

java.lang.Object
com.github.miachm.sods.SpreadSheet
All Implemented Interfaces:
Cloneable

public class SpreadSheet extends Object implements Cloneable
Spreadsheet is the base class for handle a Spreadsheet. You can create an empty Spreadsheet or load an existing one.
  • Constructor Details

  • Method Details

    • appendSheet

      public void appendSheet(Sheet sheet)
      Append a new sheet at the end of the book
      Parameters:
      sheet - A valid not-null sheet
      Throws:
      NullPointerException - if the sheet is null
    • addSheet

      public void addSheet(Sheet sheet, int pos)
      Add a new sheet in a specific position
      Parameters:
      sheet - A valid not-null sheet.
      pos - Position where insert. It must be in the range [0, getNumSheets()]
      Throws:
      NullPointerException - if the sheet is null
      IndexOutOfBoundsException - If the position is out of range
    • clear

      public void clear()
      Remove all sheets of the book. This only remove the link, the sheets objects are not modified in any way.
    • deleteSheet

      public void deleteSheet(int pos)
      Remove a specific sheet from the book
      Parameters:
      pos - The index of the sheet
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • deleteSheet

      public boolean deleteSheet(String name)
      Remove a specific sheet from the book specified by the name.
      Parameters:
      name - The name of the sheet.
      Returns:
      True if the sheet was removed, false otherwise
      See Also:
    • deleteSheet

      public boolean deleteSheet(Sheet sheet)
      Remove the specified sheet of the book.
      Parameters:
      sheet - sheet to remove.
      Returns:
      True if the sheet was removed.
      See Also:
    • getSheets

      public List<Sheet> getSheets()
      Return all the sheets of the book in a list.
      Returns:
      An unmodifiable sheets list.
    • getNumSheets

      public int getNumSheets()
      Return the number of sheets in the book
      Returns:
      The number of sheets in the book
    • getSheet

      public Sheet getSheet(String name)
      Return a sheet with a given name. If the sheet doesn't exist will return null
      Parameters:
      name - The name to look up.
      Returns:
      The sheet with a given name, if it doesn't exist return null
    • getSheet

      public Sheet getSheet(int index)
      Return a sheet with a given index.
      Parameters:
      index - Position of the sheet
      Returns:
      The sheet
      Throws:
      IndexOutOfBoundsException - If the position is invalid.
    • setSheet

      public void setSheet(Sheet sheet, int pos)
      Replace the sheet in the position pos.
      Parameters:
      sheet - The new sheet, it must be not-null.
      pos - The position where insert the sheet
      Throws:
      NullPointerException - if the sheet is null
      IndexOutOfBoundsException - if the position is invalid
    • save

      public void save(File out) throws IOException
      Save this SpreadSheet in a ODS file.
      Parameters:
      out - The file to be writted. It must be no-null and be in a valid path
      Throws:
      NullPointerException - If the file is null
      FileNotFoundException - If the file is an invalid path
      IOException - In case of an io error.
    • save

      public void save(OutputStream out) throws IOException
      Save this Spreadsheet to the stream in the ODS format
      Parameters:
      out - The outputstream to be writted. It must be no-null
      Throws:
      NullPointerException - If the OutputStream is null
      IOException - In case of an io error.
    • setAdditionalFile

      public boolean setAdditionalFile(String path, String mimetype, byte[] data)
      This function allows you to add/edit additional files inside your Spreadsheet This is an advanced feature which could be useful if you intent to store macros inside the Spreadsheet file.This function will override existing files. You can define folders using the '/' separator There are some reserved paths that you can not use: - content.xml - styles.xml - mimetype - META-INF/manifest.xml
      Parameters:
      path - : Location (inside the Spreadsheet) where the file should be placed
      mimetype - : Type of the file
      data - : The file content itself
      Returns:
      True if the file already existed, false if not
      Throws:
      IllegalArgumentException - The path belongs to a reserved file
    • removeAdditionalFile

      public void removeAdditionalFile(String path)
      This function allows you to remove files that you have added to the Spreadsheet
      Parameters:
      path - : Location (inside the Spreadsheet) where the file is placed
      Throws:
      NullPointerException - if the string is null
    • sortSheets

      @Deprecated public void sortSheets()
      Deprecated.
      This operation will be discarded for simplicity. You can easily recreate it with client code
      Sort the sheets by name
    • sortSheets

      @Deprecated public void sortSheets(Comparator<Sheet> comparator)
      Deprecated.
      This operation will be discarded for simplicity. You can easily recreate it with client code
      Sort the sheets by a custom comparator
      Parameters:
      comparator - The comparator used in the sorting
    • trimSheets

      public void trimSheets()
      Deprecated.
      this operation relay in sheet.trim(), which is also deprecated
      Trim the sheets to the minimum dimensions possible This method is equivalent to call sheet.trim() to each sheet of the spreadsheet
    • equals

      public boolean equals(Object o)
      Compare two spreadsheets. Two spreadsheets are equals if they have the same sheets and in the same order
      Overrides:
      equals in class Object
    • hashCode

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

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • toString

      public String toString()
      Overrides:
      toString in class Object