A simple Java library for reading and writing ODS (OpenDocument Spreadsheet) files. It supports parsing spreadsheets, editing cells and sheets, applying formatting, images, charts and saving the updated ODS documents back.
<dependency>
<groupId>com.github.miachm.sods</groupId>
<artifactId>SODS</artifactId>
<version>1.10.1</version>
</dependency>implementation("com.github.miachm.sods:SODS:1.10.1")implementation 'com.github.miachm.sods:SODS:1.10.1'You can access the javadocs here
There is an examples folder where you can read codes samples.
ODS means OpenDocument Spreadsheet. It's used in applications like LibreOffice or OpenOffice.
8
I needed to generate ODS files in Java. I looked for libraries, but they are:
- Deprecated or dead, like Apache ODF Toolkit. It's not working with Java 8.
- It has LibreOffice as dependency in the user's computer. That's so much (LibreOffice API).
- Poorly designed or bloated.
So, I decided create my own library from scratch. The objective is load and generate ODS files in a simple and easy way.
Right now you can:
- Reading existing ODS files (cell values and structure)
- Manipulating cell values and sheet layout (create, remove and rename sheets).
- Applying rich formatting, including:
- Bold, italic, underline and line through styles
- Font size and color
- Cell background color
- Borders
- Horizontal and vertical text alignment
- Text wrapping
- Conditional formatting
- Reading and writing chart objects with series data (Bar, Line...)
- Embedding images into sheets.
- Apply hashed password protection
- Writing changes back to a new or existing ODS file
This is an example of an ODS file in LibreOffice
Here, I am using SODS for load the file and rendering it with JavaFX
This is a code example:
package com.github.miachm.sods.examples;
import com.github.miachm.sods.Range;
import com.github.miachm.sods.Sheet;
import com.github.miachm.sods.SpreadSheet;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class BasicUsage{
public static void main(String args[]){
try {
SpreadSheet spread = new SpreadSheet(new File("resources/BasicExample.ods"));
System.out.println("Number of sheets: " + spread.getNumSheets());
List<Sheet> sheets = spread.getSheets();
for (Sheet sheet : sheets) {
System.out.println("In sheet " + sheet.getName());
Range range = sheet.getDataRange();
System.out.println(range.toString());
}
} catch (IOException e){
e.printStackTrace();
}
}
}Check more examples here
Contributions are welcome!