Free Support Forum - aspose.com

Add border to last row in table using VB.NET

I’m building a table programmatically with
builder.StartTable()

    builder.CellFormat.ClearFormatting()

    builder.RowFormat.Alignment = Tables.RowAlignment.Left
    builder.InsertCell()
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Center
    '   builder.CellFormat.Orientation. = Tables.CellVerticalAlignment.Center
    builder.CellFormat.Width = 257
    builder.CellFormat.LeftPadding = 0
    builder.CellFormat.WrapText = True

    builder.CellFormat.Borders(BorderType.Right).LineWidth = 0.5
    builder.CellFormat.Borders(BorderType.Right).LineStyle = LineStyle.Single
    builder.CellFormat.Borders(BorderType.Top).LineStyle = LineStyle.Single
    builder.CellFormat.Borders(BorderType.Bottom).LineStyle = LineStyle.Single

    builder.Write("INSTITUTION AND LOCATION")


    builder.InsertCell()
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
    builder.InsertHtml("DEGREE<br><i>(if <br> applicable)</i>")
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Center

    builder.CellFormat.Width = 75 ' tableWidth - 11
    builder.CellFormat.LeftPadding = 0
    builder.CellFormat.WrapText = True


    builder.InsertCell()
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
    builder.InsertHtml("Completion <br> Date<br> MM/YYYY")
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Center

    builder.CellFormat.Width = 74 ' tableWidth - 11
    builder.CellFormat.LeftPadding = 0
    builder.CellFormat.WrapText = True

    builder.InsertCell()
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
    builder.Write("FIELD OF STUDY")
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Center

    builder.CellFormat.Width = 130 ' tableWidth - 11
    builder.CellFormat.LeftPadding = 0
    builder.CellFormat.WrapText = True
    builder.CellFormat.Borders(BorderType.Right).LineStyle = LineStyle.None

    builder.EndRow()

then looping a dataset to add additional rows

For Each rd As DataRowView In dtViewEducation
Add row data with formatting
builder.CellFormat.Borders(BorderType.Right).LineWidth = 0.5
builder.CellFormat.Borders(BorderType.Right).LineStyle = LineStyle.Single
builder.CellFormat.Borders(BorderType.Bottom).LineStyle = LineStyle.None
builder.CellFormat.Borders(BorderType.Top).LineStyle = LineStyle.None
Next

What I would like to do is to set the bottom border to a single line for the last row only. I found a couple of links but most go to page out of date.

@Bill,

Please see sample-documents.zip (18.4 KB) and try running the following code:

Document doc = new Document(MyDir + @"in.docx");

Table tab = doc.FirstSection.Body.Tables[0];
Row row = tab.LastRow;

foreach (Cell cell in row)
{
    cell.CellFormat.Borders[BorderType.Left].LineStyle = LineStyle.Single;
    cell.CellFormat.Borders[BorderType.Top].LineStyle = LineStyle.Single;
    cell.CellFormat.Borders[BorderType.Right].LineStyle = LineStyle.Single;
    cell.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;
}

doc.Save(MyDir + @"18.4.docx");