jExcel缺少单元格内容

时间:2014-01-09 22:21:48

标签: java excel jexcelapi

我正确读取了excel文件。例如我的单元格内容在excel文件中是0,987654321。当我用jExcel api读取它时,我只读取几个单元格的字符。例如0,987。

这是我的阅读excel代码部分:

 Cell A = sheet.getCell(1, 1);
 String stringA = A.getContents().toString();

如何解决这个问题。我想要所有细胞内容。

2 个答案:

答案 0 :(得分:1)

getContents()是将单元格内容作为字符串获取的基本例程。通过将单元格转换为适当的类型(在测试它是预期的类型之后),您可以访问包含的原始数值,如下所示

if (A.getType() == CellType.NUMBER) {
    NumberCell nc = (NumberCell) A;
    double doubleA = nc.getValue();
    // this is a double containing the exact numeric value that was stored 
    // in the spreadsheet
}

这里的关键信息是:您可以通过转换到适当的Cell子类型来访问任何类型的单元格 所有这些以及更多内容在jexcelapi tutorial

中进行了解释

答案 1 :(得分:0)

简而言之:

if (A.getType() == CellType.NUMBER) {
    double doubleA = ((NumberCell) sheet.getCell(1, 1)).getValue();
}
相关问题