var app = new Microsoft.Office.Interop.Word.Application(); var doc = app.Documents.Add(); var paragraph = doc.Content.Paragraphs.Add(); paragraph.Range.Text = "This is a new paragraph";
var app = new Microsoft.Office.Interop.Word.Application(); var doc = app.Documents.Add(); var paragraph = doc.Content.Paragraphs.Add(); paragraph.Range.Text = "This is a new paragraph with formatting."; paragraph.Range.Font.Size = 12; paragraph.Range.Font.Name = "Calibri"; paragraph.Range.Font.Bold = 1; paragraph.Range.ParagraphFormat.SpaceAfter = 10;In this example, we again create a new instance of the Word application and add a new document. We add a new paragraph and set some formatting properties for the text, such as the font size, font name, and bold. We also set the spacing after the paragraph to 10 points. Overall, the AddParagraph method is a useful tool for creating and formatting paragraphs in Word documents using C#.