Reputation: 45
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?
Upvotes: 4
Views: 3871
Reputation: 48336
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!
Upvotes: 10