The row in the POI import data table is obviously not empty, but the value obtained by the background is null?

when using POI to import data, it is found that sometimes, or some excel files, the import process will report a null pointer, and later found that the corresponding row of cells are caused by null. The
code is as follows: `public Map < String,Object > readExcel (MultipartFile file) {

    
    Workbook workBook = null;
    InputStream is = file.getInputStream();
    try {
        if(file.getOriginalFilename().endsWith("xls")){
            workBook =new  HSSFWorkbook(is);
        }else if(file.getOriginalFilename().endsWith("xlsx")){
            workBook =new  XSSFWorkBook(is);
            
        }
        
        Sheet sheet1 = workBook.getSheetAt(0);
        /**
         * for
         * excel
         */
        
        Cell cell = sheet1.getRow(2).getCell(0);
        //...
    } catch (Exception e) {
    }
    
}`


Jun.30,2021

where is the null pointer reported? If it is a value, you can try String value = sheet.getCell (colIndex, rowIndex). GetContents () to take the value, the empty take out in excel is the empty string "".

Menu