Add Column to Word in WPF

Adding column(s) in Word is a way to set page layout, which separates the whole document or selected sections into two or more columns. You can also set the column width and the spacing between columns to have the satisfied layout. This article is aimed at introducing how to add a column to Word in WPF using Spire.Doc for WPF.

Create a new project by choosing WPF Application in Visual Studio, add a button in MainWindow. Add Spire.Doc.Wpf.dll as reference to your project, then double click the button to write code.

Step 1: Initialize a new instance of Document class and load a sample Word file.

Document document = new Document();
document.LoadFromFile("sample.docx");

Step 2: Add a column to section one, set the two parameters in AddColumn() method, which stand for the width of columns and the spacing between columns.

document.Sections[0].AddColumn(200f, 20f);

Step 3: Save and launch the file.

document.SaveToFile("result.docx");
System.Diagnostics.Process.Start("result.docx");

Output:

Add Column to Word in WPF

Entire Code:

using Spire.Doc;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {

            Document document = new Document();
            document.LoadFromFile("sample.docx");

            document.Sections[0].AddColumn(200f, 20f);

            document.SaveToFile("result.docx");
            System.Diagnostics.Process.Start("result.docx");
        }


    }
}