Add Comments to Each Table Cell in Word Document | C# .NET

Hi,

I need to add comments to each cell programmatically when ever a value change move to current cell and need to append comment, is there a way so we can achieve this please?

@kkumaranil485,

See the document on how to add/manage comments to Excel worksheet cells with examples for your reference. I am not entirely certain about your actual requirements but if you want to implement Excel’s data validations to your desired cells, you may do that using Aspose.Cells APIs, see the document on different data validation techniques.

In case, you still want something different or else, kindly do implement your desired task in MS Excel manually in Excel spreadsheet and save the file, zip the file and attach it here, we will check and help you on how to do it via Aspose.Cells APIs.

Hi,

Thanks for reply, but I need to implement this in word document.

@kkumaranil485,

I am moving your thread to Aspose.Words forum where one of our colleagues from Aspose.Words team will help you soon there.

@kkumaranil485,

Please refer to the following section of documentation:

Also, please compress the following resources into ZIP format and attach the .zip file here for testing:

  • A simplified source Word document
  • Your expected DOCX file showing the desired output. You can create this output file manually by using MS Word.

As soon as you get these pieces of information ready, we will then start further investigation into your particular scenario and provide you code to achieve the same expected output by using Aspose.Words.

Hi Team,

PFA of word documents DocsToSend.zip (25.7 KB)

@kkumaranil485,

There are 6 comments, 2 Formatting, 1 Insertions and 1 Deletions revisions applied to content in Table/Cells in “commentsDesiredOutPutAsposeWord” document.

For example, to comment “Header 1” text of first cell, use the following code:

Document doc = new Document("C:\\Temp\\DocsToSend\\orginaldoc.docx");

Table table = doc.FirstSection.Body.Tables[0];
Paragraph paragraph = table.FirstRow.FirstCell.FirstParagraph;

Comment comment = new Comment(doc, "Awais Hafeez", "AH", DateTime.Today);
comment.Paragraphs.Add(new Paragraph(doc));
comment.FirstParagraph.Runs.Add(new Run(doc, "Changed line spacing of single"));

CommentRangeStart commentRangeStart = new CommentRangeStart(doc, comment.Id);
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(doc, comment.Id);

paragraph.InsertBefore(commentRangeStart, paragraph.FirstChild);
paragraph.InsertAfter(commentRangeEnd, paragraph.LastChild);
commentRangeEnd.ParentNode.InsertAfter(comment, commentRangeEnd);

doc.Save("C:\\Temp\\DocsToSend\\21.9.docx");

To get Insert and Delete Revisions on + sign in last Paragraph, please use the following code:

Document doc = new Document("C:\\Temp\\DocsToSend\\orginaldoc.docx");

doc.StartTrackRevisions("author name");

Run plusSign = doc.FirstSection.Body.LastParagraph.Runs[1];
//plusSign.Font.Underline = Underline.None;
plusSign.Text = "±";

doc.StopTrackRevisions();

doc.Save("C:\\Temp\\DocsToSend\\21.9.docx");

Also, Aspose.Words currently does not record Formatting changes as revisions. Your forum thread has been linked to the appropriate issue (WORDSNET-15792) and you will be notified here as soon as it will get resolved in future. Sorry for the inconvenience.

Hi,

When we are changing a letter from italics to normal can we add that change could you please check and update. same doc contains that issue aswell.

@kkumaranil485,

I am afraid, Aspose.Words currently supports tracking of node insertions and deletions only. Font formatting changes are currently not recorded as revisions.

@awais.hafeez
can we manually add comment while changing the font? And how can we do that?
And can we set comment to entire table at once?

@kkumaranil485,

I think, you can keep track of the Run node (you have changed font formatting of) and then surround that Run node with CommentRangeStart and CommentRangeEnd objects.

Please use the following code to add comment covering the content of entire table.

Document doc = new Document("C:\\Temp\\DocsToSend\\orginaldoc.docx");

Table table = doc.FirstSection.Body.Tables[0];
Paragraph paragraph = table.FirstRow.FirstCell.FirstParagraph;

Comment comment = new Comment(doc, "Awais Hafeez", "AH", DateTime.Today);
comment.Paragraphs.Add(new Paragraph(doc));
comment.FirstParagraph.Runs.Add(new Run(doc, "set comment to entire table at once"));

CommentRangeStart commentRangeStart = new CommentRangeStart(doc, comment.Id);
CommentRangeEnd commentRangeEnd = new CommentRangeEnd(doc, comment.Id);

paragraph.InsertBefore(commentRangeStart, paragraph.FirstChild);
table.LastRow.LastCell.LastParagraph.InsertAfter(commentRangeEnd, table.LastRow.LastCell.LastParagraph.LastChild);

commentRangeEnd.ParentNode.InsertAfter(comment, commentRangeEnd);

doc.Save("C:\\Temp\\DocsToSend\\21.9.docx");

A post was split to a new topic: Append Comments while Find and Replace in Word Document | C# .NET