I am working on a java application that reads a file template.ods, and fills it in with an array of Objects using JopenDocument.
Based on the JopenDocument documentation, I should get the TableModel from the Sheet, and then use the method setValueAt(value, rowIndex, columnIndex) to modify it, but once I do that, an IndexOutofBoundsException is triggered, Here is my method:
Main.class
public File generateODSFileWithTemplate(String fileName, Object[][] rows, File template) throws FileNotFoundException {
final Sheet sheet = SpreadSheet.createFromFile(template).getSheet(0);
sheet.getSpreadSheet().getTableModel("data").setValueAt("Hello from Main", 3, 1);
File outFile = new File(fileName);
sheet.getSpreadSheet().saveAs(outFile);
return outFile;
}
template.ods
If I add a value in the first row using :
sheet.getSpreadSheet().getTableModel("data").setValueAt("Hello from Main", 0, 0);
It works, and the column value gets updated.
I am wondering what I am doing wrong to get this exception ?
Is there a way to pass the array direcly to the TableModel just like DefaultTableModel to insert the data.
I am using OpenOffice to create the template.ods