Columns.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

'' Shows how to create a document with multi-column layout.
Public Class Columns
    Public Function CreateDocx() As GcWordDocument

        Dim Inch As Single = 72
        Dim doc = New GcWordDocument()

        Dim sec1 = doc.Body.Sections.First

        sec1.PageSetup.TextColumns.Add()

        Dim pars1 = sec1.GetRange().Paragraphs
        pars1.Add("Section 1, Paragraph 1: " + LoremIpsumPar())
        pars1.Add("Section 1, Paragraph 2: " + LoremIpsumPar())
        pars1.Add("Section 1, Paragraph 3: " + LoremIpsumPar())

        Dim sec2 = doc.Body.Paragraphs.Last.AddSectionBreak()
        sec2.PageSetup.Margin.Left = Inch / 2
        sec2.PageSetup.Margin.Right = Inch / 2
        sec2.PageSetup.Margin.Top = Inch / 2
        sec2.PageSetup.Margin.Bottom = Inch / 2

        '' For the 2nd section, change page orientation:
        sec2.PageSetup.Size.Orientation = PageOrientation.Landscape

        '' Add 3 manually laid out columns:
        '' - First is 2" wide
        '' - 2nd and 3rd equally sharing the remaining space
        Dim pw = sec2.PageSetup.ClientWidth
        Dim space = sec2.PageSetup.TextColumns(0).SpaceAfter
        Dim c0w = Inch * 2
        Dim cw = (pw - c0w - space * 2) / 2
        sec2.PageSetup.TextColumns(0).Width = Inch * 2
        sec2.PageSetup.TextColumns.Add(cw)
        sec2.PageSetup.TextColumns.Add(cw)

        Dim pars2 = sec2.GetRange().Paragraphs
        pars2.Add("Section 2, Paragraph 1 followed by a column break.")
        pars2.Last.GetRange().Runs.Last.GetRange().Texts.AddBreak(BreakType.Column)

        pars2.Add("Section 2, Paragraph 2: " + LoremIpsumPar())
        pars2.Add("Section 2, Paragraph 3: " + LoremIpsumPar())

        '' Done:
        Return doc
    End Function
End Class