Hi Team,
I am trying to search particular heading 1 text. heading 1 below the table for each cell I am comparing with the particular texts if the cell text is not matched anyone then we need to add the comment for that whole table. Kindly help me asap.
Please find the below mentioned input and expected output.
Expected_output33 (1).docx (19.2 KB)
Input_word_document32.docx (15.1 KB)
public static void cell1(Document doc)
{
string heading = "Heading 1";
string content1 = "Department, Groups Root Account";
string content2 = "Department, Groups Sub Account";
string content3 = "LMS Training Relevance";
string content4 = "Applicable Sections to Read & Understand";
string content5 = "Applicable Sections to Perform Process";
string content6 = "Training Recurrence";
var listParagraphs = doc.GetChildNodes(NodeType.Table, true).Cast<Table>();
Table table = doc.FirstSection.Body.Tables[0];
Cell cell = table.FirstRow.Cells[0];
Cell cell1 = table.FirstRow.Cells[1];
Cell cell2 = table.FirstRow.Cells[2];
Cell cell3 = table.FirstRow.Cells[3];
Cell cell4 = table.FirstRow.Cells[4];
Cell cell5 = table.FirstRow.Cells[5];
Table headingReference = null;
foreach (Table paragraph in listParagraphs)
{
// Last iteration we found the heading
if (cell != null)
{
string cellValue = cell.ToString(SaveFormat.Text).Trim();
if (cellValue.ToLower() != content1.ToLower())
{
var commenttextTopMarginText = "This table is wrong";
Comment comment = new Comment(doc, "pp", "007", DateTime.Today);
comment.Paragraphs.Add(new Paragraph(doc));
comment.FirstParagraph.AppendChild(new Run(doc, commenttextTopMarginText));
CommentRangeStart start = new CommentRangeStart(doc, comment.Id);
CommentRangeEnd end = new CommentRangeEnd(doc, comment.Id);
paragraph.PrependChild(start);
paragraph.AppendChild(comment);
paragraph.AppendChild(end);
}
//we break always after the heading was found
break;
}
if (paragraph.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1 &&
paragraph.ToString(SaveFormat.Text).Trim().Equals(heading, StringComparison.InvariantCultureIgnoreCase))
{
headingReference = paragraph;
continue;
}
}
}