Columns.cs
- //
- // This code is part of Document Solutions for Word demos.
- // Copyright (c) MESCIUS inc. All rights reserved.
- //
- using System;
- using System.IO;
- using System.Drawing;
- using GrapeCity.Documents.Word;
-
- namespace DsWordWeb.Demos
- {
- // Shows how to create a document with multi-column layout.
- public class Columns
- {
- public GcWordDocument CreateDocx()
- {
- const float In = 72;
- GcWordDocument doc = new GcWordDocument();
-
- var sec1 = doc.Body.Sections.First;
-
- sec1.PageSetup.TextColumns.Add();
-
- var pars1 = sec1.GetRange().Paragraphs;
- pars1.Add("Section 1, Paragraph 1: " + Util.LoremIpsumPar());
- pars1.Add("Section 1, Paragraph 2: " + Util.LoremIpsumPar());
- pars1.Add("Section 1, Paragraph 3: " + Util.LoremIpsumPar());
-
- var sec2 = doc.Body.Paragraphs.Last.AddSectionBreak();
- sec2.PageSetup.Margin.Left = sec2.PageSetup.Margin.Right =
- sec2.PageSetup.Margin.Top = sec2.PageSetup.Margin.Bottom = In / 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
- float pw = sec2.PageSetup.ClientWidth;
- float space = sec2.PageSetup.TextColumns[0].SpaceAfter;
- float c0w = In * 2;
- float cw = (pw - c0w - space * 2) / 2;
- sec2.PageSetup.TextColumns[0].Width = In * 2;
- sec2.PageSetup.TextColumns.Add(cw);
- sec2.PageSetup.TextColumns.Add(cw);
-
- var 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: " + Util.LoremIpsumPar());
- pars2.Add("Section 2, Paragraph 3: " + Util.LoremIpsumPar());
-
- // Done:
- return doc;
- }
- }
- }
-