2014-01-09 129 views
-1

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

这里是我的读取Excel部分代码:

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

我怎样才能解决这个问题的疑难问题想单元的所有内容。

回答

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

+0

解释谢谢,它为我工作 –