我使用jxl库从excel导入数据。我有一个单元格,其值为:8.628282828。当我调试如下图时:
我看到它的类型:NumberRecord,值是正确的:8.628282828。但是当我获取单元格的内容时:
InputStream is = new ByteArrayInputStream(data);
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setEncoding("CP1252");
Workbook w;
w = Workbook.getWorkbook(is, wbSettings);
Sheet sheet = w.getSheet(0);
for (int i = 1; i < sheet.getRows(); i++) {
sheet.getCell(5,i).getContents();
}
这是8.628 我怎样才能准确获得该单元格的值?
最佳答案
将其转换为 NumberCell
并获取 double
形式的值:
double value = ((NumberCell) sheet.getCell(5,i)).getValue();
作为 Cell.getContents()
的文档状态:
Quick and dirty function to return the contents of this cell as a string. For more complex manipulation of the contents, it is necessary to cast this interface to correct subinterface
关于java - 导入文件excel数量不够,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31913481/