Hi team,
I need to enable all tables border in word document as “outside border”.
please ref to image uploaded.
Thanks,
Harish G.
Hi team,
I need to enable all tables border in word document as “outside border”.
please ref to image uploaded.
Thanks,
Harish G.
@HarishGali Please see our documentation to learn how to apply formatting on table level. You can use code like this to apply outer border of table:
Document doc = new Document("in.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
// Clear any existing borders from the table.
table.ClearBorders();
// Set a green border around the table but not inside.
table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, Color.Green, true);
Thank you for your response, its working fine.
But , the issue is first i need to check the table properties either in “outside border” or not,
if not then i have to set the table properties to “outside border”,
please help me with code to get the table property details.
Thank you.
@HarishGali You check borders on Row and Cell level in Aspose.Words model:
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.IsVisible);
Console.WriteLine("Bottom boder: " + borders.Bottom.IsVisible);
Console.WriteLine("Left boder: " + borders.Left.IsVisible);
Console.WriteLine("Right boder: " + borders.Right.IsVisible);
foreach (Cell c in r.Cells)
{
Console.WriteLine("\t---Cell Borders---");
BorderCollection cellBorders = c.CellFormat.Borders;
Console.WriteLine("\tTop boder: " + cellBorders.Top.IsVisible);
Console.WriteLine("\tBottom boder: " + cellBorders.Bottom.IsVisible);
Console.WriteLine("\tLeft boder: " + cellBorders.Left.IsVisible);
Console.WriteLine("\tRight boder: " + cellBorders.Right.IsVisible);
}
}
Console.WriteLine("==============================");
}
Also, please see our documentation to lean more about applying borders in tables.
It’s working for cells , but not rows,
Is there any option to get the table border properties as we are setting it.
Could you please try to give me a solution in table range if available.
thank you
@HarishGali Could you please attach your input document here for testing? We will check it and provide you more information.