Adding comment to the heading 1 below the table

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;
        }
    }
}

@Raju123 To achieve this you should simply insert CommentRangeStart node at the beginning of your table and CommentRangeEnd at the end. Foe example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");

// Get table, for demonstration purposes get the first one.
// In your case it will be the table that matches your conditions.
Table table = doc.FirstSection.Body.Tables[0];

// Create comment and comment range.
Comment comment = new Comment(doc, "James Bond", "007", DateTime.Now);
comment.AppendChild(new Paragraph(doc));
comment.FirstParagraph.AppendChild(new Run(doc, "This is my cool comment."));
CommentRangeStart start = new CommentRangeStart(doc, comment.Id);
CommentRangeEnd end = new CommentRangeEnd(doc, comment.Id);

// Put comment range start at the beginning of the table and comment range end at the end.
table.FirstRow.FirstCell.FirstParagraph.PrependChild(start);
table.LastRow.LastCell.LastParagraph.AppendChild(comment);
table.LastRow.LastCell.LastParagraph.AppendChild(end);

doc.Save(@"C:\Temp\out.docx");

Please see our documentation to learn more about working with comments:
https://docs.aspose.com/words/net/working-with-comments/