Search code examples
novacode-docx

How to change line spacing in DocX (docx.codeplex.com)


I have a Paragraph object from the C# library DocX and am trying in vain to set the LineSpacing property but it has no effect?

internal static Paragraph StandardFormat(this Paragraph p)
{
    p = p.FontSize(12);

    p.LineSpacing = 1.5f;

    return p;
}

Solution

  • I don't know what the LineSpacing property is for but that was a red herring. The fix was to use the SetLineSpacing method:

    internal static Paragraph StandardFormat(this Paragraph p)
    {
        p = p.FontSize(12);
    
        p.SetLineSpacing(LineSpacingType.Line, 1.5f);
    
        return p;
    }