写入工作簿两次时org.apache.xmlbeans.impl.values.XmlValueDisconnectedException

时间:2013-08-15 20:24:28

标签: java apache-poi

我正在创建一种从文件中编写和读取工作簿的方法     当我第二次称这种方法。     错误发生: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;
}

2 个答案:

答案 0 :(得分:4)

同意Akokskis,写两次导致问题,但你可以尝试在写完后重新加载工作簿,然后它将完美地工作。例如

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

答案 1 :(得分:0)

两次写入相同的XSSFWorkbook会产生错误 - 它是known bug