How to: Create a Three-Column Layout with Uniform Columns

  • 2 minutes to read

These columns can be created using the methods provided by the SectionColumns interface, accessible vby the Section.Columns property of the document section. First, create the required column layout. The SectionColumns.CreateUniformColumns method allows you to create a specified number of columns on a page with the required spacing. Then, the layout is applied to the document content using the SectionColumns.SetColumns method.

The following code illustrates how the above technique can be used to create three columns with 0.2 inches of distance between them. They will have the same width, calculated automatically according to the current page layout.

This code snippet uses the Document.Sections property to get access to the section in the document and calls the SectionColumns.CreateUniformColumns method to create a multicolumn layout with the current Section.Page section settings. Subsequently the column width is modified and the resulting layout is applied to the section using the SectionColumns.SetColumns method.

document.LoadDocument("Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Get the first section in a document.
Section firstSection = document.Sections[0];
// Create equal width column layout.
SectionColumnCollection sectionColumnsLayout =
    firstSection.Columns.CreateUniformColumns(firstSection.Page, 0.2f, 3);
// Set different column width.
sectionColumnsLayout[0].Width = 3f;
sectionColumnsLayout[1].Width = 2f;
sectionColumnsLayout[2].Width = 1f;
// Apply layout to the document.