This project has moved. For the latest updates, please go here.

Add DocDefaults (default document paragraph spacing)

Nov 17, 2011 at 11:00 AM

Hi, i've been trying to add some default properties to a word document but with no success.

The purpose is to define the default document paragraph spacing.

Here's the code:

DocDefaults docDefaults1 = new DocDefaults


SpacingBetweenLines spacingBetweenLines2 = new SpacingBetweenLines() { After = "0", Line = "240", LineRule = LineSpacingRuleValues

.Exact };





Nov 17, 2011 at 2:59 PM
Edited Nov 17, 2011 at 3:00 PM

Ok, i found a way to set a paragraph spacing style:


                    Paragraph paragraph = (Paragraph)paragraphs[i];                    
                    //set paragraph spacing
                    paragraph.ParagraphProperties = new ParagraphProperties(new SpacingBetweenLines() { After = "0" });


Dec 12, 2011 at 10:33 AM
Edited Dec 12, 2011 at 10:34 AM

Hi. The code above does not work. It applyes the SpacingBetweenLines but, any other styles like text alignement inside paragraph get lost somehow.

The only way i got it to work is by iterating all paragraphs right before the "mainPart.Document.Save();" declaration:

                foreach (Paragraph p in paragraphs)
                    p.InsertAt(new ParagraphProperties(new SpacingBetweenLines() { After = "0" }), 0);

This is the only way i found to set the SpacingBtetweenLines. If anyone has a better ideia, please post it!!!