How to remove additional blank rows in footer row

string sourcepath = "D:\\3.2.P.5.4 Batch Analyses 2.doc";
            Document doc = new Document(sourcepath);
            List<Node> tableslst = doc.GetChildNodes(NodeType.Table, true).Where(x => x.NextSibling != null && x.NextSibling.NodeType == NodeType.Paragraph).ToList();
            foreach (Table tbl in tableslst)
            {
                Paragraph pr = (Paragraph)tbl.NextSibling;
 if (!pr.IsInCell && !pr.Range.Text.StartsWith("\f") && (pr.ParagraphFormat.StyleName.ToUpper().Contains("FOOTNOTE") || pr.Range.Text.Trim() == "" || (pr.Runs.Count > 0 && pr.Runs[0].Font.Size < 12)))
                {
                    Paragraph prc = new Paragraph(doc);
                    if (pr.NextSibling != null && pr.NextSibling.NodeType == NodeType.Paragraph)
                    {
                        prc = (Paragraph)pr.NextSibling;
                        if (pr.Range.Text.Trim() == "")
                        {

                            //if (pr.LastChild != null)
                                pr.Remove();
                        }





                    }

                }

            }

                doc.Save("Footnote.docx");
            }
        }
    }

@Syedfahad

Following code example shows how to remove the blank rows from the first table of document. Hope this helps you.

If you still face problem, please ZIP and attach your input and expected output Word documents here for testing. We will investigate the issue and provide you more information on it.

Document doc = new Document(MyDir + "input.docx");             
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
foreach (Row row in table.Rows)
{
    if (row.ToString(SaveFormat.Text).Trim().Length == 0)
        row.Remove();
}

doc.Save(MyDir + "21.10.docx");

Still it is not working

Here I’am attaching zip file.check it
Code.zip (17.1 KB)

@Syedfahad

We have not found any empty table row in the attached document. Could you please share some more detail about your requirement along with expected output Word document?

End of the table there is empty footer rows.In the end of table the text “not more than 6 %” is present.before this text there is additional empty rows are present.could you please delete or remove this empty rows?Code.zip (17.1 KB)

@Syedfahad

There are empty paragraphs after the table. These are not table rows. Please check the attached image for detail. Empty Paragraphs.png (26.8 KB)

We suggest you please read the following article about document object model of Aspose.Words.
Aspose.Words Document Object Model (DOM)

You can remove the empty paragraphs after first table of document using following code example.

Document doc = new Document(MyDir + "3.2.P.5.4 Batch Analyses 2.doc");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
while (table.NextSibling != null)
{
    if (table.NextSibling.NodeType == NodeType.Paragraph && table.NextSibling.ToString(SaveFormat.Text).Trim().Length == 0)
    {
        table.NextSibling.Remove();
    }
    else
        break;
}
doc.Save(MyDir + "21.10.docx");

Okay…thank you…it worked perfectly

@Syedfahad

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Could you please explain what’s this method ToString(SaveFormat.Text).Trim().Length == 0 actually do?

@Syedfahad

The Node.ToString(SaveFormat.Text) method exports the content of the node into a string in the text format. If you want to get the text of Node e.g. Paragraph, you can use this method.

Okay.Thank you

Actually my document consist of two tables in two pages…it is not reading 2nd table…i want to delete empty paragraph after 2nd table.Could you please help me out?

I want to delete empty lines before “Not more than 6 %” after 2nd table

I’am attaching document the for your reference
Code.zip (19.3 KB)

I want to delete empty paragraphs/lines after random tables.please give me solution ASAP

@Syedfahad

You can use the same approach to delete the empty paragraphs after table. Please use CompositeNode.GetChildNodes method as shown below to get all tables of document. Following code example shows how to remove empty paragraphs after each table of document.

Document doc = new Document(MyDir + "3.2.P.5.4 Batch Analyses 2.doc");

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
    while (table.NextSibling != null)
    {
        if (table.NextSibling.NodeType == NodeType.Paragraph && table.NextSibling.ToString(SaveFormat.Text).Trim().Length == 0)
        {
            table.NextSibling.Remove();
        }
        else
            break;
    }
}
                
doc.Save(MyDir + "21.11.docx");

Okay…Thank you so much Tahir

Hello Tahir,

Code is working perfect but after some tables there are some blank rows.so the other tables are connecting with previous table.could you please give me a solution so that the other table should not connect with previous table nd blank lines/paragraph sholud be deleted.

I’am attching the reference doucment please refer it
Connect.PNG (26.3 KB)

In this Document from table 6 to table 10 are connected.
Please give me a solution ASAP

@Syedfahad Tables in MS Word must be separated by a paragraph. If two tables are are following each other, they are concatenated. You can make such paragraphs hidden Like shown in the following code:

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
    Node currentNode = table.NextSibling;
    while (currentNode != null)
    {
        if (currentNode.NodeType == NodeType.Paragraph && currentNode.ToString(SaveFormat.Text).Trim().Length == 0)
        {
            Paragraph emptyPara = (Paragraph)currentNode;
            Node nextNode = emptyPara.NextSibling;

            if (nextNode != null && nextNode.NodeType == NodeType.Table)
                emptyPara.ParagraphBreakFont.Hidden = true;
            else
                emptyPara.Remove();

            currentNode = nextNode;
        }
        else
        {
            break;
        }
    }
}

But note hidden content is shown in MS Word when Show/Hide (Ctrl+*) option is enabled.

okay thank you.code is working perfect.
But what if i have figures after table empty rows
Could you please provide me code so that figure should not be connected with previous table

@Syedfahad You can use condition like the following to check whether paragraph contains shapes and change the behavior of your code accordingly:

if(emptyPara.GetChildNodes(NodeType.Shape, true).Count > 0)

Okay.Thank you so much