-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docx comment support #1006
Add docx comment support #1006
Conversation
Thank you for your contribution. I notice that there is no real code change but formatting changes and remove namespaces in the following files Can you revert any changes about formatting so that it's easy for me to focus on reviewing the real code changes. Btw, which version of POI do you reference? |
Thank you for your quick reply! I ported real code changes from latest version POI 5.2.3. Already the style changes has been collected into first one commit so you can see remain commits to review real changes. (To be honest, those changes has been done by Visual Studio auto-formatting on save, so keeping styles unchanging is hard to do in my development environment. If it's really required in this project, I'll edit commits.) |
Port XWPFComment / XWPFComments code and related testcases from POI 5.2.3.
@tonyqus OK, I completely removed style changes in each commits. Now this PR contains real code changes only. Good? |
LGTM |
Thanks! |
I tried to create a comment sample. But I cannot make it work.
I cannot see the comments in Word even if I turn "Show comments" on Did I miss something? |
It's necessary to handle underlying CT_x objects to emit comments to docx. using (XWPFDocument doc = new XWPFDocument())
{
var comments = doc.CreateComments();
var comment1 = comments.CreateComment("0");
comment1.Author = "Tony";
comment1.Initials = "S";
comment1.Date = DateTime.Now.ToShortDateString();
var comment2 = comments.CreateComment("1");
comment2.Author = "May";
var para = comment2.CreateParagraph();
para.CreateRun().SetText("Hello World");
var paragraph1 = doc.CreateParagraph();
paragraph1.CreateRun().SetText("This is ");
paragraph1.GetCTP().AddNewCommentRangeStart().id = comment1.Id;
paragraph1.CreateRun().SetText("1st comment");
paragraph1.GetCTP().AddNewCommentRangeEnd().id = comment1.Id;
paragraph1.CreateRun().SetText(" text.");
paragraph1.GetCTP().AddNewR().AddNewCommentReference().id = comment1.Id;
var paragraph2 = doc.CreateParagraph();
paragraph2.CreateRun().SetText("This is ");
paragraph2.GetCTP().AddNewCommentRangeStart().id = comment2.Id;
paragraph2.CreateRun().SetText("2nd comment");
paragraph2.GetCTP().AddNewCommentRangeEnd().id = comment2.Id;
paragraph2.CreateRun().SetText(" text.");
paragraph2.GetCTP().AddNewR().AddNewCommentReference().id = comment2.Id;
using (FileStream sw = File.Create("comments.docx"))
{
doc.Write(sw);
}
} |
This is my first contribution to NPOI. I'm not sure about any contributing process that I should follow, please give me advice.
When I've tried to modify comments in docx file, the feature was not yet implemented. Porting code from POI was not so difficult.