facebooktwittermenuarrow-up

GemBox Support Forum

Multiple tables in one bookmark

I need to insert many tables into one bookmark in the document.
If I do it like below, then I thought it would insert one table per loop, but it inserts all cells into one table.
Someone, that knows what I’m doing wrong, or is it not possible to do what I need?

Dim itemsRange As ContentRange = document.Bookmarks("Table").GetContent(False)
While SQLdr.Read()

    Dim table As New Table(document)

    Dim row1 As New TableRow(document)
    table.Rows.Add(row1)

    Dim cell As New TableCell(document)
    row1.Cells.Add(cell)

    Dim paragraph As New Paragraph(document, $"" & value & "")
    cell.Blocks.Add(paragraph)

    itemsRange.End.InsertRange(table.Content)

End While

Hi Thor,

That will create multiple tables and they will be placed one after another.

However, note that Microsoft Word will combine such tables into one when opening a document.
So, what you could do is add an empty paragraph between them to avoid that tables combining.

For example:

Dim separator As New Paragraph(document)
separator.CharacterFormatForParagraphMark.Size = 1
separator.ParagraphFormat.SpaceAfter = 0
separator.ParagraphFormat.SpaceBefore = 0

itemsRange.End.InsertRange(table.Content)
itemsRange.End.InsertRange(separator.Content)

I hope this helps, let me know if you need anything else.

Regards,
Mario

Thanks!!, that solved my issue :slight_smile: