• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception on invoking write() method twice on XSSFWorkbook instance.

 
Renjith Panikar
Greenhorn
Posts: 28
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could see the same topic being covered at several places, but i dint get a clear picture from those.

Issue is,

I have a download link in JSp page to download excel file. I have this file in HTTPSession.
To pop up save excel box, i invoked write(OutputStream) on XSSFWorkbook instance.
But when i click on the link for the second time, this exception occoured.

Request processing failed; nested exception is org.apache.xmlbeans.impl.values.XmlValueDisconnectedException

it will be really helpful if some one can help me to resolve it.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post an SSCCE (<- this is a link) that demonstrates the problem.
 
Renjith Panikar
Greenhorn
Posts: 28
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


First time when the user clicks the link, a pop up will come asking the user to save/open the file.
User will click on the download link again, if he close the file by mistake.
This time, it will not give a pop up and an exception "Request processing failed;
nested exception is org.apache.xmlbeans.impl.values.XmlValueDisconnectedException " can be
seen on console. This exception occours when we invoke .write(OutputStream) on
same Workbook instance for the second time. Hpe this give a clear picture.

 
Renjith Panikar
Greenhorn
Posts: 28
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RESOLVED

This is what i did to resolve it.
Instead of keeping the Workbook in session, I took getBytes() from MultipartFile (File uploaded) and kept it in session.
Validation errors are also uploaded to session.
Now I have both Original file and errors in session.
I will create a new XSSFWorkbook instance from the following code.
Workbook workbook = null;
try{
workbook = new XSSFWorkbook(new ByteArrayInputStream(multipartFileBytes));
}catch(OfficeXmlFileException exception){
workbook = new HSSFWorkbook(new ByteArrayInputStream(multipartFileBytes));
}
Now, workbook.write(OutputStream) will be invoked on different instances of Workbook on each request.

Let me know if you see any issues in this approach.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic