how to save spreadsheet in excel code example

Example: how to write and save on excel

The first creation part is same then go to a cell where you want to write.

Row row = sheet.getRow(0)
Cell cell = row.getCell(2)

Let's imagine you have values in index 0 and index 1.
Now you want to create a cell on index 2. First, check if it is null to 
avoid problems.

if(cell==null){
   cell = row.createCell(2);
}
cell.setValue("Germany");

in order to save:
FileOutputStream fileOutputStream = 
           new FileOutputStream("src/test/resources/Countries.xlsx");

workbook.write(fileOutputStream); ==> write the changes to the file and save

Tags:

Misc Example