小编crs*_*ps2的帖子

当使用Apache-POI库获取单元格内容时,我得到"无法从文本单元格中获取数值",反之亦然.我如何解决它?

我意识到这个问题有点令人困惑,但我不知道怎么说它.无论如何,这是原始代码:

private void readFile(String excelFileName) throws FileNotFoundException, IOException {
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(excelFileName));
    if (workbook.getNumberOfSheets() > 1){
        System.out.println("Please make sure there is only one sheet in the excel workbook.");
    }
    XSSFSheet sheet = workbook.getSheetAt(0);
    int numOfPhysRows = sheet.getPhysicalNumberOfRows();
    XSSFRow row;
    XSSFCell num;
    for(int y = 1;y < numOfPhysRows;y++){    //start at the 2nd row since 1st should be category names
        row = sheet.getRow(y);
        poNum = row.getCell(1);
        item = new Item(Integer.parseInt(poNum.getStringCellValue());
        itemList.add(item);
        y++;
    }
}

private int poiConvertFromStringtoInt(XSSFCell cell){
    int …
Run Code Online (Sandbox Code Playgroud)

java xlsx apache-poi illegalstateexception

22
推荐指数
3
解决办法
8万
查看次数

标签 统计

apache-poi ×1

illegalstateexception ×1

java ×1

xlsx ×1