0

I use Apache POI to upload and read the file. This is my code:

    @PostMapping("/upload")
    public void addPersonne(@RequestParam("file") MultipartFile file) throws IOException{
        ZipSecureFile.setMinInflateRatio(0);
        FileInputStream f =  (FileInputStream) file.getInputStream();
        XSSFWorkbook workbook = new XSSFWorkbook(f); 
        XSSFSheet sheet = workbook.getSheetAt(0);        
        for (Row row : sheet) {
            DataFormatter df = new DataFormatter();
            Personne per = new Personne();
            per.setNumero(df.formatCellValue(row.getCell(0)));            
            persorepo.save(per);  
        }               
    }

I get an error because the object that I get is of type cell not int. Please what should I do to convert cell to int

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
  • 1
    Check if it is actually a number or not, and if it is, fetch the cell numeric value? – Gagravarr Apr 20 '20 at 11:59
  • `DataFormatter.formatCellValue` always gets a `String`. If you need other types, you need using the alternative way showed in https://poi.apache.org/components/spreadsheet/quick-guide.html#CellContents. – Axel Richter Apr 20 '20 at 13:15

0 Answers0