How to check tables have borders

REGa.docx (81.9 KB)

@alexey.noskov hi sir , in attached file REGa table 1 dont have borders .
I need to check tables have borders or not if have tables borders of left top right bottom i need to show a messege “Table have borders”, for that how can i get table borders how can i check tables borders.

@srinu12 Actually in your table all borders are set and invisible borders are simply white:


So in your case you should consider white borders as invisible. You can use code like this to check the borders:

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

// Get all tables
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
foreach (Table t in tables)
{
    foreach (Row r in t.Rows)
    {
        Console.WriteLine("---Row Borders---");
        BorderCollection borders = r.RowFormat.Borders;
        Console.WriteLine("Top boder: " + borders.Top.Color);
        Console.WriteLine("Bottom boder: " + borders.Bottom.Color);
        Console.WriteLine("Left boder: " + borders.Left.Color);
        Console.WriteLine("Right boder: " + borders.Right.Color);

        foreach (Cell c in r.Cells)
        {
            Console.WriteLine("\t---Cell Borders---");
            BorderCollection cellBorders = c.CellFormat.Borders;
            Console.WriteLine("\tTop boder: " + cellBorders.Top.Color);
            Console.WriteLine("\tBottom boder: " + cellBorders.Bottom.Color);
            Console.WriteLine("\tLeft boder: " + cellBorders.Left.Color);
            Console.WriteLine("\tRight boder: " + cellBorders.Right.Color);
        }
    }

    Console.WriteLine("==============================");
}

Also, please see our documentation to lean more about applying borders in tables.