public Object[][] dataProviderMethod() throws IOException {
try {
file = new FileInputStream(new File("/Users/nanthakumar/Documents/workspace/Myna_Admin/src/com/myna/testdata/login.xls"));
workbook = new HSSFWorkbook(file);
sheet = workbook.getSheetAt(0);
row = sheet.getLastRowNum() + 1;
col = sheet.getRow(0).getLastCellNum();
data = new String[row][col];
for (i = 0; i < row; i++) {
rowvalue = sheet.getRow(i);
for (j = 0; j < col; j++) {
cellValue = rowvalue.getCell(j);
data[i][j] = cellValue.getStringCellValue();
System.out.println("The value is ----->" + data[i][j]);
}
workbook.close();
file.close();
}
} catch (FileNotFoundException nana) {
nana.printStackTrace();
}
return data;
}
这是我的代码,我尝试添加 getnumericalCellvalue()
而不是 getStringCellValue()
但这对我不起作用。
最佳答案
首先你要在模板excel中检查列是数字还是文本。当且仅当列是数字类型时你才能得到数值。所以改变模板excel并尝试
关于java - 无法从 excel 单元格中获取数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37810067/