Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Please post an SSCCE (<- this is a link) that demonstrates the problem.
+Pie Number of slices to send: Send


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.

+Pie Number of slices to send: Send
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.
moose poop looks like football shaped elk poop. About the size of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3037 times.
Similar Threads
Out of Memory Error - Java Heap Space while writing to Excel
Reading a .xlsx excel file using XSSF
How to read .xlsx sheet from Client Side using poi 3.5
Opening an Excel file
file Writing problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:39:13.