11

I want to read, write and create Spreadsheets in the Open Document Format with Java. And I want the resulting Java-program running on a computer without OpenOffice.org or other ODS-capable programs installed. Exists a library to access this format?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mnementh
  • 50,487
  • 48
  • 148
  • 202

3 Answers3

14

Take a look at jOpenDocument: http://www.jopendocument.org/documentation.html

Especially: http://www.jopendocument.org/start_spreadsheet_3.html

xyz
  • 1,242
  • 9
  • 13
2

jOpenDocument is all you need.

user270491
  • 19
  • 1
0

First import library

  <dependency>
        <groupId>com.github.miachm.sods</groupId>
        <artifactId>SODS</artifactId>
        <version>1.6.2</version>
    </dependency>

then this is an example on how to read the first column of the first sheet

public static List<String> readColumnA(String filePath) {
    List<String> movieList = new ArrayList<>();
    try {
        SpreadSheet spread = new SpreadSheet(new File(filePath));
        //     System.out.println("Number of sheets: " + spread.getNumSheets());
        Sheet sheet = spread.getSheets().get(0);
        //     System.out.println("In sheet " + sheet.getName());
        Range movies = sheet.getDataRange();
        Object[][] movieColumn = movies.getValues();
        for (int i = 0; i < sheet.getMaxRows(); i++) {
            movieList.add(movieColumn[i][0].toString());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return movieList;
}
Adrian Jimenez
  • 979
  • 9
  • 23