make program writ in excel code example

Example: writing 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 saveThe 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