A pure Java library for OASIS Open Document files manipulation

Modify an existing spreadsheet

This section introduces you to some of the features of the library to manipulate existing spreadsheets.

With jOpenDocument you can modify an existing file like this one :


 // Load the file.
 File file = new File("template/invoice.ods");
 final Sheet sheet = SpreadSheet.createFromFile(file).getSheet(0);
 // Change date.
 sheet.getCellAt("I10").setValue(new Date());
 // Change strings.
 sheet.setValueAt("Filling test"11);
 sheet.getCellAt("B27").setValue("On site support");
 // Change number.
 // Or better yet use a named range
 // (relative to the first cell of the range, wherever it might be).
 // Save to file and open it.
 File outputFile = new File("fillingTest.ods");;

To load a file, use SpreadSheet.createFromFile() which gives a you the complete spreadsheet. Then you need to access the first sheet. To address a cell you can either do it by index (easy to use in a loop), or you can use its name. As you can see, several types of value are supported.

If you want to know more, look at the package org.jopendocument.dom.spreadsheet