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