Manipular planilhas (calc.ods) do OpenOffice

0 respostas
E

Olá pessoal,

Estou tentando alterar dados (escrever) em uma planilha (calc) ODS do OpenOffice através do java. Consigo criar uma planilha nova, escrever, abrir, etc, mas se a planilha já existir e eu precisar alterar algum dado não estou conseguindo. Estou utilizando o código abaixo que consegui no site do Openproject mas está dando o erro descrito abaixo.

Alguém sabe como solucionar o problema ou teria outro código para escrever em uma planilha existente?

Abaixo está o código que estou utilizando:

public static void main(String[] args) throws FileNotFoundException, java.io.IOException {

// Load the file.

File file = new File(D:/Softwares/openoffice/teste.ods);

final Sheet sheet = SpreadSheet.createFromFile(file).getSheet(0);

// Change strings.

sheet.setValueAt(teste2, 1, 1);

sheet.getCellAt(B27).setValue(On site support);

// Change date.

sheet.getCellAt(I10).setValue(new Date());

// Change number.

sheet.getCellAt(F24).setValue(3);

// Save to file and open it.

File outputFile = new File(D:/Softwares/openoffice/teste2.ods);

OOUtils.open(sheet.getSpreadSheet().saveAs(outputFile));

}

ao compilar é apresentado o erro abaixo:

Exception in thread main java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

at java.util.ArrayList.RangeCheck(ArrayList.java:547)

at java.util.ArrayList.get(ArrayList.java:322)

at org.jopendocument.dom.spreadsheet.Sheet.getRow(Sheet.java:23

at org.jopendocument.dom.spreadsheet.Sheet.getImmutableCellAt(Sheet.java:204)

at org.jopendocument.dom.spreadsheet.Sheet.getValueAt(Sheet.java:21

at org.jopendocument.dom.spreadsheet.Sheet.setValueAt(Sheet.java:197)

at pacoteteste.DocViewer.main(DocViewer.java:71)

Java Result: 1

Abraços,

Criado 28 de maio de 2008
Respostas 0
Participantes 1