Org.apache.xmlbeans.impl.values.XmlValueDisconnectedException when writing a book twice

I create a method for writing and reading a workbook from a file, but when I call this method a second time. Error: org.apache.xmlbeans.impl.values.XmlValueDisconnectedException

public XSSFWorkbook GetUpdatedResult(XSSFWorkbook vmworkbookhelper) throws Exception { this.vmWorkbookHelper2 = vmworkbookhelper; String tempName = UUID.randomUUID().toString()+".xlsx"; File tempFile = new File(tempName); fileOut = new FileOutputStream(tempFile); this.vmWorkbookHelper2.write(fileOut); fileOut.close(); vmworkbookhelper = new XSSFWorkbook(tempFile); if(tempFile.exists()) tempFile.delete(); return vmworkbookhelper; } 
+7
java apache-poi
source share
2 answers

Agree with Akokskis, write twice, causing problems, but you can try reloading the book after writing, then it will do just fine. for example

  FileOutputStream fileOut = new FileOutputStream("Workbook.xlsx"); wb.write(fileOut); fileOut.close(); wb = new XSSFWorkbook(new FileInputStream("Workbook.xlsx")); 
+2
source share

Writing twice the same XSSFWorkbook may result in this error - this is a known error .

0
source share

All Articles