NestedTable.vb
''
'' This code is part of GrapeCity Documents for Word samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Word

'' This sample creates a simple table and adds another (nested)
'' table into a cell of the first table.
Public Class NestedTable
    Function CreateDocx() As GcWordDocument
        Dim doc = New GcWordDocument()

        doc.Body.Sections.First.GetRange().Paragraphs.Add("Here is a 5 columns by 3 rows table, with a nested table in cell (2, 2):")
        Dim t = doc.Body.Sections.First.GetRange().Tables.Add(
            {
                New String() {"row 1, col 1", "row 1, col 2", "row 1, col 3", "row 1, col 4", "row 1, col 5"},
                New String() {"row 2, col 1", "row 2, col 2", "row 2, col 3", "row 2, col 4", "row 2, col 5"},
                New String() {"row 3, col 1", "row 3, col 2", "row 3, col 3", "row 3, col 4", "row 3, col 5"}
            }
        )
        '' Create a New table style
        Dim ts1 = doc.Styles.Add("Table Style 1", StyleType.Table)
        '' We can enumerate all table borders, including inside borders:
        For Each border In ts1.Table.Borders
            border.LineStyle = LineStyle.Triple
            border.LineWidth = 0.5F
            border.Color.RGB = Color.Purple
        Next
        '' Assign the style to the table:
        t.Style = ts1

        '' Overwrite inside border's line styles:
        ts1.Table.Borders.InsideHorizontal.LineStyle = LineStyle.Double
        ts1.Table.Borders.InsideVertical.LineStyle = LineStyle.Double

        '' Add some padding:
        ts1.Table.Padding.All = 3

        '' Set up cell (1,1) to visually span two following cells
        Dim cell = t.Rows(1).Cells(1)
        Dim tn = cell.GetRange().Tables.Add()
        cell.GetRange().Paragraphs.First.GetRange().Texts.First.Value = "Cell with nested table."

        tn.Rows.Add("Nested (1,1)", "Nested (1,2)", "Nested (1,3)")
        tn.Rows.Add("Nested (2,1)", "Nested (2,2)", "Nested (2,3)")
        tn.Rows.Add("Nested (3,1)", "Nested (3,2)", "Nested (3,3)")

        '' Done
        Return doc
    End Function
End Class