Home > Back-end >  Validation string with apache POI
Validation string with apache POI

Time:10-14

i need to do a validation, i need to know if the cell c3 there is the String "Numero"

but i get one error:

> 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;
>     }
}

enter image description here

CodePudding user response:

You need to get the value of the cell and user equals. https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/Cell.html

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

CodePudding user response:

Now i cant add this method in the validation form, i get an error:

 public int validaLinha(Row row) {
            String pedidoExcel = "Numero";
            Cell colunaNumero = row.getCell(new CellReference("C3").getCol());
    
    
                if (colunaNumero == null) {
                    return 0;
    
                }else
                 if (pedidoExcel.equals(colunaNumero.getStringCellValue()))
                    return 1;
            return 2; }

Validation Form:

private void validarForm(CartaoForm cartaoForm, BindingResult result) {
        
        int testando;
        
        testando = validaLinha(row);
                if (testando == 0){
            
            result.rejectValue("arquivo", "arquivo.vazio");
        }

enter image description here

  • Related