首页 > 解决方案 > 带有 apache POI 的验证字符串

问题描述

我需要进行验证,我需要知道单元格 c3 是否存在字符串“Numero”

但我得到一个错误:

> private int validaLinha(Row row) { String pedidoExcel = “Numero”;
> 
>     Cell teste = row.getCell(new CellReference("C3").getCol());
> 
>     try{
>         if (teste == null || teste.getCellType() == Cell.CELL_TYPE_BLANK)
>             return 0;
> 
>         if (teste == pedidoExcel)
>             return 1;
> 
>     }catch (Exception e){
>         return -1;
>     }
}

在此处输入图像描述

标签: javaspringapache-poi

解决方案


您需要获取单元格和用户等于的值。 https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/Cell.html

if (pedidoExcel.equals(teste.getStringCellValue()))
             return 1;

推荐阅读