I'm using Apache POI methods to create and fill XWPFDocument object in my project, smth like this
public XWPFDocument test() {
 XWPFDocument doc = new XWPFDocument();
 ...
 return doc;
}
but thre's a problem, for my case XWPFDocument should be serialized. Is there any way to serialize it?
Promoting a comment to an answer...
The way to serialise a XWPFDocument (or in fact any POI UserModel document) is via the write(OutputStream) method
If you need to serialise to a byte array, you'd do something like:
XWPFDocument doc = new XWPFDocument();
...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.write(baos);
return baos.toByteArray();
Assuming you want to serialise into something like a database or persistence framework, just get the OutputStream from that and write into it directly!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With