繁体   English   中英

无法从Excel单元格获取数值

[英]cannot get a numerical value from the excel cell

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模板中检查列是数字还是文本。当且仅当列的类型为number时,您才能获取数值。因此更改模板excel并尝试

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM