Columns.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.IO
  6. Imports System.Drawing
  7. Imports GrapeCity.Documents.Word
  8.  
  9. '' Shows how to create a document with multi-column layout.
  10. Public Class Columns
  11. Public Function CreateDocx() As GcWordDocument
  12.  
  13. Dim Inch As Single = 72
  14. Dim doc = New GcWordDocument()
  15.  
  16. Dim sec1 = doc.Body.Sections.First
  17.  
  18. sec1.PageSetup.TextColumns.Add()
  19.  
  20. Dim pars1 = sec1.GetRange().Paragraphs
  21. pars1.Add("Section 1, Paragraph 1: " + LoremIpsumPar())
  22. pars1.Add("Section 1, Paragraph 2: " + LoremIpsumPar())
  23. pars1.Add("Section 1, Paragraph 3: " + LoremIpsumPar())
  24.  
  25. Dim sec2 = doc.Body.Paragraphs.Last.AddSectionBreak()
  26. sec2.PageSetup.Margin.Left = Inch / 2
  27. sec2.PageSetup.Margin.Right = Inch / 2
  28. sec2.PageSetup.Margin.Top = Inch / 2
  29. sec2.PageSetup.Margin.Bottom = Inch / 2
  30.  
  31. '' For the 2nd section, change page orientation:
  32. sec2.PageSetup.Size.Orientation = PageOrientation.Landscape
  33.  
  34. '' Add 3 manually laid out columns:
  35. '' - First is 2" wide
  36. '' - 2nd and 3rd equally sharing the remaining space
  37. Dim pw = sec2.PageSetup.ClientWidth
  38. Dim space = sec2.PageSetup.TextColumns(0).SpaceAfter
  39. Dim c0w = Inch * 2
  40. Dim cw = (pw - c0w - space * 2) / 2
  41. sec2.PageSetup.TextColumns(0).Width = Inch * 2
  42. sec2.PageSetup.TextColumns.Add(cw)
  43. sec2.PageSetup.TextColumns.Add(cw)
  44.  
  45. Dim pars2 = sec2.GetRange().Paragraphs
  46. pars2.Add("Section 2, Paragraph 1 followed by a column break.")
  47. pars2.Last.GetRange().Runs.Last.GetRange().Texts.AddBreak(BreakType.Column)
  48.  
  49. pars2.Add("Section 2, Paragraph 2: " + LoremIpsumPar())
  50. pars2.Add("Section 2, Paragraph 3: " + LoremIpsumPar())
  51.  
  52. '' Done:
  53. Return doc
  54. End Function
  55. End Class
  56.