GridSpan.vb
  1. ''
  2. '' This code is part of Document Solutions for Word demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.Drawing
  6. Imports GrapeCity.Documents.Word
  7.  
  8. '' This sample creates a simple table and uses GridSpan
  9. '' to visually extend a cell to 2 adjacent cells.
  10. Public Class GridSpan
  11. Function CreateDocx() As GcWordDocument
  12. Dim doc = New GcWordDocument()
  13.  
  14. '' Add a table:
  15. doc.Body.Paragraphs.Add(
  16. "Here is a 5 columns by 3 rows table, with three middle cells in row 2 merged:")
  17. Dim tableData = {
  18. ({"row 1, col 1", "row 1, col 2", "row 1, col 3", "row 1, col 4", "row 1, col 5"}),
  19. ({"row 2, col 1", "row 2, col 2", "row 2, col 3", "row 2, col 4", "row 2, col 5"}),
  20. ({"row 3, col 1", "row 3, col 2", "row 3, col 3", "row 3, col 4", "row 3, col 5"})
  21. }
  22. Dim t = doc.Body.Tables.Add(tableData)
  23.  
  24. '' Create a New table style:
  25. Dim ts1 = doc.Styles.Add("Table Style 1", StyleType.Table)
  26. '' We can enumerate all table borders, including inside borders:
  27. For Each border In ts1.Table.Borders
  28.  
  29. border.LineStyle = LineStyle.Triple
  30. border.LineWidth = 0.5F
  31. border.Color.RGB = Color.Purple
  32. Next
  33. '' Overwrite inside border's line styles:
  34. ts1.Table.Borders.InsideHorizontal.LineStyle = LineStyle.Double
  35. ts1.Table.Borders.InsideVertical.LineStyle = LineStyle.Double
  36. '' Add some padding:
  37. ts1.Table.Padding.All = 3
  38.  
  39. '' Assign the style to the table:
  40. t.Style = ts1
  41.  
  42. '' Set up cell (1,1) to visually span two following cells
  43. Dim cell = t.Rows(1).Cells(1)
  44. cell.Format.GridSpan = 3
  45. '' Remove the 2 following cells (unless we want to create a jagged table):
  46. t.Rows(1).Cells(3).Delete()
  47. t.Rows(1).Cells(2).Delete()
  48.  
  49. t.Rows(1).Cells(1).GetRange().Paragraphs.First.Delete()
  50. t.Rows(1).Cells(1).GetRange().Paragraphs.Add("Cell in col 2 merged with cells in cols 3 & 4")
  51.  
  52. '' Done:
  53. Return doc
  54. End Function
  55. End Class
  56.