public void scriviNewId() throws IOException { String FILE_NAME = "C:\\Users\\java\\Desktop\\x.xlsx"; InputStream inp = new FileInputStream(FILE_NAME); Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); //Vai a leggere la nuova colonna Cliente cliente = new Cliente(); cliente.fillVeicoloId(); for (int i = 0; i < cliente.getVeicoloId().size(); i++) { Row row = sheet.createRow(i + 1); //Inizia alla riga 1 System.out.println("Scrivi: " + cliente.getVeicoloId().get(i)); // Specific cell number Cell cell = row.createCell(5); // putting value at specific position cell.setCellValue(cliente.getVeicoloId().get(i)); //row.createCell(5).setCellValue(cliente.getVeicoloId().get(i)); // Colonna 34 } FileOutputStream fileOut = new FileOutputStream(FILE_NAME); wb.write(fileOut); fileOut.close(); }
Why does it overwrite other columns?