Java org.apache.xmlbeans.impl.values.XmlValueDisconnectedException 写入工作簿两次时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18261152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.apache.xmlbeans.impl.values.XmlValueDisconnectedException when write workbook twice
提问by Nikesh Pathak
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
我正在创建一种从文件中写入和读取工作簿的方法,但是当我第二次调用此方法时。发生错误: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;
}
采纳答案by Sankumarsingh
Agree with Akokskis, writing twice causing problem, but you can try reloading again the workbook after writing, then it will perfectly work. For example
同意 Akokskis 的观点,写两次导致问题,但您可以在写完后再次尝试重新加载工作簿,然后它会完美地工作。例如
FileOutputStream fileOut = new FileOutputStream("Workbook.xlsx");
wb.write(fileOut);
fileOut.close();
wb = new XSSFWorkbook(new FileInputStream("Workbook.xlsx"));