org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException:无法保存

use*_*041 7 file-io export-to-excel excel-2010

我正面对 org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save:an error occurs while saving the package : The part /docProps/app.xml fail to be saved in the stream with marshaller <br/> org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@7c81475b

在每个测试场景执行完成后尝试将每个测试场景结果(PASS或FAIL)写入Excel工作表(.xlsx)时出现异常.为此目的,我写了以下两个不同的模块.

请告诉我问题在哪里以及如何解决它..

//Method for writing results into Report
 public void putResultstoReport(String values[])
 {
      int j=NoofTimesExecuted;
      NoofTimesExecuted++;
      XSSFRow row = sheet.createRow(j);
      for(int i=0;i<values.length;i++)
      {
           XSSFCell cell = row.createCell(i);
           cell.setCellValue(values[i]);
      }
      try {
           System.out.println("Times:"+NoofTimesExecuted);
           wb.write(fileOut);
      }
      //fileOut.flush();
      //fileOut.close();
      }
      catch(Exception e) {
           System.out.println("Exception at closing opened Report :"+e);
      }

//Method for Creating the Excelt Report
 public void createReport()
 {
      String FileLocation = getProperty("WorkSpace")+"//SCH_Registration//OutPut//TestResults.xlsx";
      try {
           fileOut = new FileOutputStream(FileLocation);
           String sheetName = "TestResults"; //name of sheet
           wb = new XSSFWorkbook();
           sheet = wb.createSheet(sheetName);
           fileOut.flush();
           fileOut.close();
      }
      catch(Exception e)
      {
           System.out.println("Exception at Create Report file:"+e);
      }
}
Run Code Online (Sandbox Code Playgroud)

小智 5

我今天遇到了这个问题并且已经解决了。

问题出在 putResultstoReport()

你不能wb.write(fileOut);在你的周期中。

解析度:

先打电话putResultstoReport();然后wb.write(fileOut);


Jac*_*ack 5

我也有这个错误。

我发现我的错误是由于多次打开同一文件/工作簿引起的。

因此,我建议确保在尝试关闭之前只打开一次。


Rya*_*yan 5

如果发生超时,就会发生这种情况。我有适用于小型数据集的代码,并在使用大型数据集时引发此错误。