Free Support Forum - aspose.com

Set table border for the last row


#1

Hi,

I am using Linq Reporting Engine and also a template file to generate some pdfs. The .dotx template file contains some tables of which rows are created and filled dynamically based on the input data.
Everything works great, but I have an issue in setting the border for the last row of the table (sometimes, the last row of the table is an inner row from the table, that doesn’t have any border; when it happens to be the last row, it should have border).
border.png (3.9 KB)
Can you please indicate, what should be approach to fix this issue?
I tried this, but it didn’t work:

       Document doc = new Document(template);
        // Quick typed access to the first child Section node of the Document
        Section section = doc.FirstSection;
        // Quick typed access to the Body child node of the Section.
        Body body = section.Body;> 
        // Quick typed access to all Table child nodes contained in the Body.
        TableCollection tables = body.Tables;
        foreach (Table table in tables.OfType<Table>())
        {
            // Quick typed access to the last row of the table.
            table.LastRow.RowFormat.Borders.Color=Color.Blue;
        }

thanks in advance!


#2

@taia

Thanks for your inquiry. Please use the Cell.CellFormat.Borders property as shown below to achieve your requirement.

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

TableCollection tables = doc.FirstSection.Body.Tables;
foreach (Table table in tables.OfType<Table>())
{
    // Quick typed access to the last row of the table.
    table.LastRow.RowFormat.Borders.Color = Color.Blue;
    foreach (Cell cell in table.LastRow.Cells)
    {
        cell.CellFormat.Borders.LineStyle = LineStyle.Single;
    }
}
doc.Save(MyDir + "19.1.docx");

#3

Hi, thank you for your help, but this approach doesn’t solve my issue. Is there maybe a way to label the object from the template and to use those label name inside code to identify the table elements? Can I identify a certain row by a name, and after that maybe I can set its border/style?


#4

Hi :smile: I fixed my issue, thanks!


#5

@taia

Thanks for your feedback. It is nice to hear from you that you have solved your issue. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.