How can I access spreadsheets in the open document format (.ods) with Java?
Asked Answered
C

3

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?

Correy answered 19/1, 2009 at 7:20 Comment(0)
I
14

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

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

Induct answered 19/1, 2009 at 8:1 Comment(0)
E
2

jOpenDocument is all you need.

Extrasystole answered 10/2, 2010 at 17:34 Comment(0)
S
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;
}
Scotty answered 1/9, 2023 at 17:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.