I'm trying to add a comment to a MS Word document by apache poi api.
I have done part of the work by using:
CTMarkupRange commentStart = paragraph.getCTP().addNewCommentRangeStart();
commentStart.setId(BigInteger.ZERO);
XWPFRun run = paragraph.createRun();
run.setText("text");
CTMarkupRange commentEnd = paragraph.getCTP().addNewCommentRangeEnd();
commentEnd.setId(BigInteger.ZERO);
CTR ctr = paragraph.getCTP().addNewR();
CTMarkup ctMarkup = ctr.addNewCommentReference();
ctMarkup.setId(BigInteger.ZERO);
But I don't know how to link it to a real comment and I find nothing about it in api-document.
Do anyone know how to solve it?
In a Office OpenXML Word document (
XWPF
) comments are in a specialCommentsDocument
/word/comments.xml
in the *.docx ZIP archive. So at first we would need access to this document. But until now theXWPFdocument
will only read that package part while creating. There is neither write access nor a possibility to create that package part.So we must at first provide such a possibility to create the package part
/word/comments.xml
in the *.docx ZIP archive and to get write access to it.In the following example the method
MyXWPFCommentsDocument createCommentsDocument(XWPFDocument document)
creates the package part/word/comments.xml
and the relations to it. The classMyXWPFCommentsDocument
is a wrapper class for that package part having write access to it.This works for
apache poi 3.17
. Sinceapache poi 4.0.0
theooxml
part is separated. So there must be: