How to apply a Word Quick Style in C# - not just simple formatting but the entire style?
This works for me.
Word.Application _wordApp = new Word.Application();
Word.Document oDoc = _wordApp.Documents.Add();
_wordApp.Visible = true;
_wordApp.Selection.TypeText("Heading");
oDoc.Paragraphs[1].set_Style(Word.WdBuiltinStyle.wdStyleHeading2);
When you say
paragraph.Range.Text = text + paragraph.Range.Text;
You are getting more paragraphs than you imagined. I reckon you need:
paragraph.Range.Text = text;
Try:
Paragraph paragraph = _document.Content.Paragraphs.Add();
paragraph.Range.Text = text;
if (styleName != null)
{
paragraph.set_Style(_document.Styles[styleName]);
}
paragraph.Range.InsertParagraphAfter();