Change paragraph style in Word document

Hello team,
I have a word document and I want to change the style of the first paragraph. When I try to remove the bold there is no change.

Noticed that when I change the paragraph.ParagraphFormat.Style.Font.Bold flag to true, the whole document becomes bold.

Code:

public static void EditStyle()
{
    Document doc = new Document(@"C:\...\NewFolder\sample.docx");

    Paragraph paragraph = doc.Sections[0].Body.FirstParagraph;
    paragraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
    paragraph.ParagraphFormat.Style.Font.Bold = false;

    doc.Save(@"C:\...\NewFolder\out.docx");
} 

Input file:
sample.docx (24.0 KB)

@maant paragraph.ParagraphFormat.Style.Font.Bold = false; changes the font formatting of the style applied to the paragraph. Since Normal style is applied to the first paragraph and the same style is applied to other paragraphs, the chnages also affects the other paragraphs too. To get the expected output explicit font formatting should be applied to the Run nodes in the paragraph:

Document doc = new Document(@"C:\Temp\sample.docx");

Paragraph paragraph = doc.FirstSection.Body.FirstParagraph;
paragraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
foreach(Run r in paragraph.Runs)
    r.Font.Bold = false;

doc.Save(@"C:\Temp\out.docx");

It works thank you :slight_smile:

1 Like