首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IndexOutOfBoundException在尝试使用jOpenDocument获取.ods单元时

IndexOutOfBoundException在尝试使用jOpenDocument获取.ods单元时
EN

Stack Overflow用户
提问于 2015-05-29 18:04:47
回答 2查看 706关注 0票数 3

我的编码面临着一个小小的挑战。

代码语言:javascript
复制
File file = new File("template.ods");
Sheet sheet;
try {
    // load file
    sheet = SpreadSheet.createFromFile(file).getSheet("Certificate");
    System.out.println(file);
    System.out.println(sheet.getCellAt("A1").isEmpty());
    sheet.setValueAt("A1", 1, 1);;
    System.out.println(sheet.getCellAt(1, 1).getTextValue());
    sheet.getCellAt(2, 2).setValue("B2");
    sheet.getCellAt(3, 3).setValue("C3");
    sheet.getCellAt(4, 4).setValue("D4");
    // Save to file and open it.
    File outputFile = new File("fillingTest.ods");
    OOUtils.open(sheet.getSpreadSheet().saveAs(outputFile));

} catch (Exception e) {
    e.printStackTrace();
}

我正在了解jOpenDocument-Library。我想用一些示例值填充现有的(template.ods)。当运行上述代码时,控制台显示如下:

template.ods 真org.jopendocument.dom.spreadsheet.Table.getRow(Unknown :索引: 1,大小:1在java.util.ArrayList.rangeCheck(未知源)在java.util.ArrayList.get(未知源)在org.jopendocument.dom.spreadsheet.Table.getValueAt(Unknown源(在org.jopendocument.dom.spreadsheet.Table.getValueAt(Unknown源)在org.jopendocument.dom.spreadsheet.Table.setValueAt(Unknown源)(在jOpenDocument.createDocument.main(createDocument.java:48) )

"template.ods“和"true”表示应用程序从目录检索文件,并"true“表示它可以读取单元格,该单元格是空的。

但是我不知道哪个数组会抛出异常,为什么它会说“未知源”。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-29 19:49:08

行数组抛出异常。在设置单元格内容之前,尝试使用sheet.setRowCount()添加更多行。

票数 1
EN

Stack Overflow用户

发布于 2015-12-23 10:56:55

您可以使用ensureRowCount,我认为这更合适:

代码语言:javascript
复制
sheet.ensureRowCount(row);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30536235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档