在Libreoffice电子表格的工作表中,我可以访问单元格,但不能访问它的值。我没有发现我的错误,任何反馈都是欢迎的。代码如下:
import java.io.File;
import java.io.IOException;
import org.jopendocument.dom.spreadsheet.MutableCell;
import org.jopendocument.dom.spreadsheet.Sheet;
import org.jopendocument.dom.spreadsheet.SpreadSheet;
public class MyClass {
protected Sheet dataSheet;
protected File dataCalcFile;
public static void main(String[] args) {
MyClass myClassInstance = new MyClass();
myClassInstance.loadData();
}
public void loadData() {
int numRows=0, numColumnas=0;
MutableCell cell=null;
try {
dataCalcFile = new File(""C:\\temp\\Data.ods"");
dataSheet = SpreadSheet.createFromFile(dataCalcFile).getSheet(0);
numRows = dataSheet.getRowCount();
System.out.println("Number of rows: " + numRows);
System.out.println("Cell at 0,0: " + dataSheet.getCellAt(0, 0));
System.out.println("Nullpointer Exception when getting cell value at 0,0: " + dataSheet.getValueAt(0, 0)); // *** THE INFAMOUS ONE ***
} catch (Exception e) {
System.out.println(e);
}
}
}下面是控制台的输出:
Number of rows: 107
Cell at 0,0: <table:table-cell xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" table:style-name="ce1" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:value-type="string" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" calcext:value-type="string"><text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">Carpeta</text:p></table:table-cell>
java.lang.NullPointerException发布于 2020-12-27 22:37:44
刚刚发现:“是的,LO 7切换到ODF1.3。我们正在努力支持它。同时,您可以将格式更改为"1.2 extended”。转到“选项”,然后选择“加载/保存”,然后是“常规”,然后是OpenDocument格式版本。“
它对我很有效,但我很高兴听到我的客户的意见……
发布于 2020-10-21 15:26:14
我发现Libreoffice (7.x)的库jopendocument和新版本的Libreoffice(7.x)jopendocument之间一定有一些不兼容,就像上面的代码一样:
如果使用LibreOffice6.4.3.2编辑电子表格,则
编辑电子表格,
在某些版本中,Calc生成jopendocument不能理解的XML。
https://stackoverflow.com/questions/64423111
复制相似问题