Free Support Forum - aspose.com

Can't reset border

Borders.zip (47.0 KB)
attached is my project.
expected.docx is what I’m expecting to see.
got.docx is what I got.

I am storing table borders, adding some rows, clearing the borders, then restoring the borders from what was saved.
however, the borders are not restoring.

(tracked it down to the border clear. if you comment that out, it works fine).

@conniem,

Thanks for your inquiry. Please use the following modified code to get the desired output. Hope this helps you.

static void testborders(Document aDocument, int tIndex)
{
    Table aTable = (Table)aDocument.GetChild(NodeType.Table, tIndex, true);
    Row aRow;
    BorderCollection borders = aTable.FirstRow.RowFormat.Borders;
    aRow = AppendRow(aDocument, aTable, 3);
    aRow = AppendRow(aDocument, aTable, 3);
    aRow = AppendRow(aDocument, aTable, 3);
            
    DeleteRow(aTable, 0);
    aTable.ClearBorders();
    foreach (Row row in aTable)
    {
        row.RowFormat.Borders.ClearFormatting();
    }
             
    aTable.SetBorder(BorderType.Left, borders.Left.LineStyle, borders.Left.LineWidth, borders.Left.Color, true);
    aTable.SetBorder(BorderType.Right, borders.Right.LineStyle, borders.Right.LineWidth, borders.Right.Color, true);
    aTable.SetBorder(BorderType.Bottom, borders.Bottom.LineStyle, borders.Bottom.LineWidth, borders.Bottom.Color, true);
    aTable.SetBorder(BorderType.Top, borders.Top.LineStyle, borders.Top.LineWidth, borders.Top.Color, true);
}