Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.apache.xmlbeans.impl.values.XmlValueDisconnectedException when write workbook twice [duplicate]

i'm create a method to write and read work book from file but when i call this method second time. error occure : 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;
}
like image 296
Nikesh Pathak Avatar asked Aug 15 '13 20:08

Nikesh Pathak


2 Answers

Agree with Akokskis, writing twice causing problem, but you can try reloading again the workbook after writing, then it will perfectly work. For example

    FileOutputStream fileOut = new FileOutputStream("Workbook.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb = new XSSFWorkbook(new FileInputStream("Workbook.xlsx"));
like image 101
Sankumarsingh Avatar answered Oct 26 '22 17:10

Sankumarsingh


Writing twice to the same XSSFWorkbook can produce that error - it's a known bug.

like image 26
akokskis Avatar answered Oct 26 '22 17:10

akokskis