Adding rows to an existing table

Hi,
I need a little help with adding cells to this template. The area in the Education section (under INSTITUTION AND LOCATION ) has 5 rows and I populate them with code like

For Each rd As DataRowView In dtViewEducation
    builder.MoveToCell(0, i + 6, 0, -1)
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Top
    builder.Font.Size = 11
    builder.Font.Bold = False
    builder.Font.Color = System.Drawing.Color.Black
    builder.Font.Name = "Arial"
    builder.Underline = Underline.None
    builder.Write(sInstitution)
    builder.MoveToCell(0, i + 6, 1, -1)
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Top
    builder.Font.Size = 11
    builder.Font.Bold = False
    builder.Font.Color = System.Drawing.Color.Black
    builder.Font.Name = "Arial"
    builder.Underline = Underline.None
    builder.Write(rd.Item("Degree").ToString)
    builder.MoveToCell(0, i + 6, 2, -1)
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Top
    builder.Font.Size = 11
    builder.Font.Bold = False
    builder.Font.Color = System.Drawing.Color.Black
    builder.Font.Name = "Arial"
    builder.Underline = Underline.None
    builder.Write(rd.Item("YearsOfStudy").ToString)
    builder.MoveToCell(0, i + 6, 3, -1)
    builder.CellFormat.VerticalAlignment = Tables.CellVerticalAlignment.Top
    builder.Font.Size = 11
    builder.Font.Bold = False
    builder.Font.Color = System.Drawing.Color.Black
    builder.Font.Name = "Arial"
    builder.Underline = Underline.None
    builder.Write(rd.Item("FieldOfStudy").ToString)
    i += 1
Next

This works fine except if I need to add more than the five records I need a way to add the additional cells
I’ve tried to add using

If i + 6 >= 11 Then
    builder.MoveToCell(0, 10, 0, -1)
    builder.InsertCell()
    builder.Write(sInstitution)
    builder.CellFormat.Borders.Color = Color.Blue
    builder.CellFormat.Width = 25
    builder.CellFormat.WrapText = True
    builder.InsertCell()
    builder.Write(rd.Item("Degree").ToString)
    builder.InsertCell()
    builder.Write(rd.Item("YearsOfStudy").ToString)
    builder.InsertCell()
    builder.Write(rd.Item("FieldOfStudy").ToString)
    builder.EndRow()
End If

But formation is totally a mess and the inner cell don’t seem to wrap within the desired space.
I apprecieate the help.
Also if it is a better practice I don’t mind changing the templete to be only one row in a table and then nest all of the other rows, My only requirement is to keep the cell widths and the border lines.
Thanks for the help

Hi

Thanks for your request. I think in your case, you can use MailMerge with regions to fill your document with data. Please see the following link to learn more:
https://docs.aspose.com/words/net/types-of-mail-merge-operations/
Please let me know if such approach is acceptable for you.
Best regards,

THANKS FOR THE SPEEDY REPLY
I think that approach can work however I’m having a bit of trouble populating the region. I’ve attached the starting document (Biosketch2) that I created and use the following code

Dim MyTable As New DataView(dtEducation)
MyTable.RowFilter = "IsIncluded = 'TRUE' "
MyTable.Sort = "YearsOfStudy"
doc.MailMerge.ExecuteWithRegions(MyTable)
doc.MailMerge.RemoveEmptyParagraphs = True

All I get is the one row of merge fields name just like the original document. Completed document (BioSketch_001)
I know that I mus be doing something simple wrong

Bill

Hi

Thank you for additional information. I cannot reproduce the problem with your document. I use the following code. It seems something wrong with your data.

// Open document.
Document doc = new Document("Biosketch2.doc");
doc.MailMerge.ExecuteWithRegions(GetInfo());
doc.Save("out.doc");
private DataTable GetInfo()
{
    // Create data table
    DataTable table = new DataTable("MyTable");
    table.Columns.Add("Institution");
    table.Columns.Add("Degree");
    table.Columns.Add("YearsOfStudy");
    table.Columns.Add("FieldOfStudy");
    // Add some dummy data.
    table.Rows.Add(new object[]
    {
        "Institution 1",
        "Degree 1",
        "1",
        "FieldOfStudy1"
    });
    table.Rows.Add(new object[]
    {
        "Institution 2",
        "Degree 2",
        "2",
        "FieldOfStudy2"
    });
    table.Rows.Add(new object[]
    {
        "Institution 3",
        "Degree 3",
        "3",
        "FieldOfStudy3"
    });
    table.Rows.Add(new object[]
    {
        "Institution 4",
        "Degree 4",
        "4",
        "FieldOfStudy4"
    });
    table.Rows.Add(new object[]
    {
        "Institution 5",
        "Degree 5",
        "5",
        "FieldOfStudy5"
    });
    table.Rows.Add(new object[]
    {
        "Institution 6",
        "Degree 6",
        "6",
        "FieldOfStudy6"
    });
    return table;
}

Hope this helps.
Best regards,

Thanks- FYI my problem was that my “table name” was getting changed going through the view. I renamed it back at the end before calling the merge and it is now working fine. One last question and I will leave you alone- I promise. How can I get rid of the lines between each row entry and keep the one after the last entry? Do I need to add a blank row in the mailmerge and add my fields there? But then I will have an extra blank row at the end that has the bottom border.
You have been great thanks

Hi Bill,

Thanks for your request. You are right, in this case, you should add empty row at the end of the table. You should also specify zero height of this row, in this case, the end user will not see the row but only its border.
Hope this helps. Please let me know if you need more assistance, I will be glad to help you.
Best regards.

Thank you for all of your help