@alexey.noskov I am trying to add the comment for the paragraph I used below step.
- Find the particular heading 1
2.next I am checking the table is there or not - I am checking particular paragraph is there or not. if the particular text is there means I am add the comment for it.
Note: my heading one having the comment that’s why my 1st condition having not satisfying.so i want to ignore the comment for heading 1
Kindly help me asap.
Please find the below mentioned input and expected output.
Expeceted_output_document96.docx (48.6 KB)
Input_word document 123.docx (48.4 KB)
string description = "* Process owner/Service Owner communicates to HR Training Coordinator of any additional roles/colleagues who are required to train on the process document who do not fall under the defined departments/groups.";
string heading = "Training Audience";
var listParagraphs = ruleBaseModel.SourceDocument.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>();
foreach (Paragraph paragraph in listParagraphs)
{
var abc = paragraph.ToString(SaveFormat.Text).Trim();
if (paragraph.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1 &&
abc == heading.Trim())
{
Table table = paragraph.NextSibling as Table;
if (table != null)
{
Node nextNode = table.NextSibling;
while (nextNode != null && nextNode.NodeType != NodeType.Paragraph)
nextNode = nextNode.NextSibling;
Paragraph paragraph1 = (Paragraph)nextNode;
// This paragraph must not be heading 1 or it means there is no content
if (paragraph1.ParagraphFormat.StyleIdentifier != StyleIdentifier.Heading1 &&
!paragraph1.ToString(SaveFormat.Text).Trim().Equals(description, StringComparison.InvariantCultureIgnoreCase)) // ! or Negated or not equals
{
var commenttextTopMarginText = "This description is null";
Comment comment = new Comment(ruleBaseModel.SourceDocument, "mmh", "007", DateTime.Today);
comment.Paragraphs.Add(new Paragraph(ruleBaseModel.SourceDocument));
comment.FirstParagraph.AppendChild(new Run(ruleBaseModel.SourceDocument, commenttextTopMarginText));
CommentRangeStart start = new CommentRangeStart(ruleBaseModel.SourceDocument, comment.Id);
CommentRangeEnd end = new CommentRangeEnd(ruleBaseModel.SourceDocument, comment.Id);
paragraph1.PrependChild(start);
paragraph1.AppendChild(comment);
paragraph1.AppendChild(end);
}
break;
}
}
}