GridSpan.vb
- ''
- '' This code is part of Document Solutions for Word demos.
- '' Copyright (c) MESCIUS inc. All rights reserved.
- ''
- Imports System.Drawing
- Imports GrapeCity.Documents.Word
-
- '' This sample creates a simple table and uses GridSpan
- '' to visually extend a cell to 2 adjacent cells.
- Public Class GridSpan
- Function CreateDocx() As GcWordDocument
- Dim doc = New GcWordDocument()
-
- '' Add a table:
- doc.Body.Paragraphs.Add(
- "Here is a 5 columns by 3 rows table, with three middle cells in row 2 merged:")
- Dim tableData = {
- ({"row 1, col 1", "row 1, col 2", "row 1, col 3", "row 1, col 4", "row 1, col 5"}),
- ({"row 2, col 1", "row 2, col 2", "row 2, col 3", "row 2, col 4", "row 2, col 5"}),
- ({"row 3, col 1", "row 3, col 2", "row 3, col 3", "row 3, col 4", "row 3, col 5"})
- }
- Dim t = doc.Body.Tables.Add(tableData)
-
- '' 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
- '' 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
-
- '' Assign the style to the table:
- t.Style = ts1
-
- '' Set up cell (1,1) to visually span two following cells
- Dim cell = t.Rows(1).Cells(1)
- cell.Format.GridSpan = 3
- '' Remove the 2 following cells (unless we want to create a jagged table):
- t.Rows(1).Cells(3).Delete()
- t.Rows(1).Cells(2).Delete()
-
- t.Rows(1).Cells(1).GetRange().Paragraphs.First.Delete()
- t.Rows(1).Cells(1).GetRange().Paragraphs.Add("Cell in col 2 merged with cells in cols 3 & 4")
-
- '' Done:
- Return doc
- End Function
- End Class
-