I didn’t tested your example, but I think you should also close the file?
file.close();
I found an example:
@Keyword
def void writeToExcel(String text ){
FileInputStream file = new FileInputStream (new File("D:\\Testdata.xlsx"))
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
Cell searchText = sheet.getRow(1).getCell(1);
searchText.setCellValue(text);
file.close();
FileOutputStream outFile =new FileOutputStream(new File("D:\\Testdata.xlsx"));
workbook.write(outFile);
outFile.close();
}
Source: Write into excel at runtime during test execution - #6 by nhi
Theres also an example for your usecase: