File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Exception on invoking write() method twice on XSSFWorkbook instance. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Exception on invoking write() method twice on XSSFWorkbook instance." Watch "Exception on invoking write() method twice on XSSFWorkbook instance." New topic
Author

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

Renjith Panikar
Greenhorn

Joined: Nov 06, 2012
Posts: 28

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
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  68
Please post an SSCCE (<- this is a link) that demonstrates the problem.
Renjith Panikar
Greenhorn

Joined: Nov 06, 2012
Posts: 28



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

Joined: Nov 06, 2012
Posts: 28

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception on invoking write() method twice on XSSFWorkbook instance.