Modify an existing spreadsheet

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

 // 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.
 sheet.getCellAt("F24").setValue(3);
 // Or better yet use a named range
 // (relative to the first cell of the range, wherever it might be).
 sheet.getSpreadSheet().getTableModel("Products").setValueAt(154);
 // Save to file and open it.
 File outputFile = new File("fillingTest.ods");
 OOUtils.open(sheet.getSpreadSheet().saveAs(outputFile));
Java2html

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

 

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