I have a scenario to write data to an excel which contains around 5 sheets.I have written Custom Keyword for writing data to a sheet in excel passing sheet name as parameter to write to a particular sheet.
When writing to a particular sheet and writing in next step to another, i am facing FileNotFoundException. ( The process cannot access the file as it is used by another process.)
public class WriteExcel {
Workbook wbwrite;
String epc_Filepath=GlobalVariable.EPC_Input
String Filepath_write=GlobalVariable.Filepath_Input @Keyword
public void writeData(String sheetName,String value,int row, int column){
File file1 = new File(Filepath_write)
InputStream wis=new FileInputStream(file1)
wbwrite= new XSSFWorkbook(wis)
XSSFSheet shw=wbwrite.getSheet(sheetName)
Cell cell=shw.getRow(row).getCell(column)
cell.setCellType(1)
cell.setCellValue(value)
OutputStream wos= new FileOutputStream(file1)
wbwrite.write(wos)
wos.flush()
wos.close()
wis.close()
}
}
The Excel file contains 3 sheets. The issue is occurring when writing to sheet2 and again in the next step trying to write to sheet1 and sometimes when writing to same sheets.