org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save
Asked Answered
L

7

13

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);
      }
}
Leastways answered 6/11, 2013 at 10:56 Comment(1)
The error message is not even good English. I have a bounty on this here if anyone can take a shot #21116689Helper
K
6

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

Kevinkevina answered 24/1, 2014 at 2:15 Comment(0)
C
6

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.

Consultant answered 25/1, 2016 at 15:5 Comment(0)
J
5

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

Jurel answered 13/5, 2019 at 15:12 Comment(2)
what you did to fix this, how you are generating the excel for big data set. Also is this client side error or server side error. Please help me I think I am having same issueShiva
In my case it was due to an HTTP timeout of my request, which closes the output stream. It took me a little to find out because my HTTP request went through a proxy, which was the one that timed out. A possible solution is to avoid sending synchronous requests for big file exports, but instead use a websocket which tells the frontend when the export is done and ready to be requested for download.Lothair
M
1

I had the same issue. When I shortened the output excel filename, it stopped.

Mutz answered 20/1, 2020 at 13:37 Comment(1)
Saved countless hours, that was the case for me.Massie
P
0

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.

Parricide answered 1/12, 2017 at 12:4 Comment(0)
U
0

I had the same problem user refreshing page and sending the request again before the previous request is completed. when creating the name use millisecond in name to avoid name conflict with these updates in code of name creation resolved the above issue.

       String sheetName="projectName"+System.currentTimeMillis() + ".xlsx"
       FileOutputStream fileOut = new FileOutputStream(sheetName);
       workbook.write(fileOut);
       fileOut.close();
Ursuline answered 11/8, 2020 at 16:8 Comment(0)
W
0

The problem arises from not providing the second parameter, which should be append, for the OutputStream. The constructor of FileOutputStream is:

public FileOutputStream(File file, boolean append)

Providing "true" for the append parameter here will fix the issue. Because when append is not set to true, the output stream will overwrite the content of the file.

Wager answered 24/3 at 21:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.