Is it possible to use same workbook to read and write into an Excel file (.xlsx) ?
I try to use the same workbook to improve performance.
Indeed, opening, closing, opening, closing,... is not very efficient.
So I keep the workbook in a "global variable".
this.FileInputStream = null
this.Workbook = null
public void before() {
this.FileInputStream = new FileInputStream (new File('File.xlsx'))
this.Workbook = new XSSFWorkbook(this.FileInputStream)
}
public void read() {
XSSFSheet sheet = this.Workbook.getSheet(sheetName)
...
}
public void write() {
XSSFSheet sheet = this.Workbook.getSheet(sheetName)
...
FileOutputStream outFile = new FileOutputStream(new File('File.xlsx'))
this.Workbook.write(outFile)
outFile.close()
}
public void after() {
this.Workbook = null
this.FileInputStream.close()
this.FileInputStream = null
}
Error
org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
on line
this.Workbook.write(outFile)
Can you help me to improve this ?
Thank you in advance,
Regards,