org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save

陌路散爱 提交于 2019-11-28 03:47:55

问题


I'm facing 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

Exception when try to write the each test scenario result(PASS or FAIL) into Excel sheet(.xlsx) after the each test scenario execution completion. I write the following two different modules for this purpose.

Please tell me where is the problem and how to resolve it..

//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);
      }
}

回答1:


I also had this error.

I found my mistake was caused because I was opening the same file / workbook multiple times.

So I would recommend to make sure you are opening just once before attempting to close as well.




回答2:


I had this problem today and fixed it already.

The problem is in putResultstoReport()

You can't wb.write(fileOut); in your cycle.

resolution:

first call putResultstoReport(); then wb.write(fileOut);




回答3:


This can happen if a timeout occurs. I have code that works for a small dataset and throws this error with huge dataset.




回答4:


I had similar Issue. Finally I got the reason and that was version for the below jar file was getting overrided.

  org.apache.xmlgraphics:batik-dom

Hence, I added below dependency and now it is working fine.

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>batik-dom</artifactId>
    <version>1.8</version>
</dependency>

This jar contains dependency for xalan. To generate the report xalan is required.



来源:https://stackoverflow.com/questions/19810214/org-apache-poi-openxml4j-exceptions-openxml4jruntimeexception-fail-to-save

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!