How to set Spacing of Paragraphs in word document

Paragraph is a very important element in word document. It is powerful and has many properties. Spire.Doc, a .NET component specially designed for developers enables you to manipulate paragraphs easily and flexibly.

There are documents on our website introducing how to set Alignment, Indent and Bullets. And this article introduces you how to set Spacing of paragraphs in word document.

Step 1: Create a word document.

Document document = new Document();
Section section = document.AddSection();

Step 2: Add the first paragraph to the document.

Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("Thank you for requesting a trial version of Spire.Doc. The component will work normally except for an evaluation warning message. Once you purchase a license file, the evaluation warning will disappeare.");

Step 3: Set the Line spacing of the first paragraph.

paragraph.Format.LineSpacing = 20;

Step 4: Set the Spacing Before of the first paragraph.

paragraph.Format.BeforeSpacing = 30;

Step 5: Set the Spacing After of the first paragraph

paragraph.Format.AfterSpacing = 15;

Step 6: Save the document.

document.SaveToFile("result.doc", FileFormat.Doc);

Full code:

using Spire.Doc;
using Spire.Doc.Documents;
namespace Spacing
{
 class Program
    {
     
      static void Main(string[] args)
        {
            Document document = new Document();
            Section section = document.AddSection();

            //add the first paragraph
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Thank you for requesting a trial version of Spire.Doc. The component will work normally except for an evaluation warning message. Once you purchase a license file, the evaluation warning will disappeare.");
            paragraph.Format.FirstLineIndent = 20;

            //set the Line spacing
            paragraph.Format.LineSpacing = 20;

            //set the Spacing Before
            paragraph.Format.BeforeSpacing = 30;

            //set the Spacing After
            paragraph.Format.AfterSpacing = 15;

            //add the second paragraph
            Paragraph paragraph2 = section.AddParagraph();
            paragraph2.AppendText("Spire.Doc (Pack) is a compilation of Spire.Doc for .NET, Spire.Doc for Silverlight and Spire.Doc for WPF. It is a professional and powerful Word component which enables you to generate, load, write, edit and save Word document on .NET, Silverlight and WPF. With Spire.Doc, you can create a large range of applications.");
            paragraph2.Format.FirstLineIndent = 20;

            //set the Line spacing
            paragraph2.Format.LineSpacing = 25;

            //save the document
            document.SaveToFile("result.doc", FileFormat.Doc);

            System.Diagnostics.Process.Start("result.doc");


        }
    }
}

Screenshot:

Set Spacing of Paragraphs in word document