Package com.github.miachm.sods
Class SpreadSheet
java.lang.Object
com.github.miachm.sods.SpreadSheet
- All Implemented Interfaces:
Cloneable
Spreadsheet is the base class for handle a Spreadsheet.
You can create an empty Spreadsheet or load an existing one.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty spreadsheetSpreadSheet(File file) Load a Spreadsheet from an ODS file.Load a Spreadsheet from an inputstream.SpreadSheet(InputStream in, OdsOptionParameters options) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a new sheet in a specific positionvoidappendSheet(Sheet sheet) Append a new sheet at the end of the bookvoidclear()Remove all sheets of the book.clone()voiddeleteSheet(int pos) Remove a specific sheet from the bookbooleandeleteSheet(Sheet sheet) Remove the specified sheet of the book.booleandeleteSheet(String name) Remove a specific sheet from the book specified by the name.booleanCompare two spreadsheets.intReturn the number of sheets in the bookgetSheet(int index) Return a sheet with a given index.Return a sheet with a given name.Return all the sheets of the book in a list.inthashCode()voidremoveAdditionalFile(String path) This function allows you to remove files that you have added to the SpreadsheetvoidSave this SpreadSheet in a ODS file.voidsave(OutputStream out) Save this Spreadsheet to the stream in the ODS formatbooleansetAdditionalFile(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.voidReplace the sheet in the position pos.voidDeprecated.This operation will be discarded for simplicity.voidsortSheets(Comparator<Sheet> comparator) Deprecated.This operation will be discarded for simplicity.toString()voidDeprecated.this operation relay in sheet.trim(), which is also deprecated
-
Constructor Details
-
SpreadSheet
public SpreadSheet()Create an empty spreadsheet -
SpreadSheet
Load a Spreadsheet from an ODS file.- Parameters:
file- The file to load. It must be a valid readable file- Throws:
NullPointerException- If the file is nullFileNotFoundException- If the file doesn't exist or it can be readedNotAnOdsException- If the file isn't an ODS file.OperationNotSupportedException- If the ODS file has a feature which it's not implemented in this libraryIOException- If an unexpected IO error is produced- See Also:
-
SpreadSheet
Load a Spreadsheet from an inputstream.- Parameters:
in- The inputstream to read- Throws:
NullPointerException- If the inputstream is nullNotAnOdsException- If the file isn't an ODS file.OperationNotSupportedException- If the ODS file has a feature which it's not implemented in this libraryIOException- If an unexpected IO error is produced- See Also:
-
SpreadSheet
- Throws:
IOException
-
-
Method Details
-
appendSheet
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
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 nullIndexOutOfBoundsException- 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
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
Remove the specified sheet of the book.- Parameters:
sheet- sheet to remove.- Returns:
- True if the sheet was removed.
- See Also:
-
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
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
Return a sheet with a given index.- Parameters:
index- Position of the sheet- Returns:
- The sheet
- Throws:
IndexOutOfBoundsException- If the position is invalid.
-
setSheet
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 nullIndexOutOfBoundsException- if the position is invalid
-
save
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 nullFileNotFoundException- If the file is an invalid pathIOException- In case of an io error.
-
save
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 nullIOException- In case of an io error.
-
setAdditionalFile
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 placedmimetype- : Type of the filedata- : The file content itself- Returns:
- True if the file already existed, false if not
- Throws:
IllegalArgumentException- The path belongs to a reserved file
-
removeAdditionalFile
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.This operation will be discarded for simplicity. You can easily recreate it with client codeSort the sheets by name -
sortSheets
Deprecated.This operation will be discarded for simplicity. You can easily recreate it with client codeSort 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 deprecatedTrim the sheets to the minimum dimensions possible This method is equivalent to call sheet.trim() to each sheet of the spreadsheet -
equals
Compare two spreadsheets. Two spreadsheets are equals if they have the same sheets and in the same order -
hashCode
public int hashCode() -
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
toString
-