Description
Represents a paragraph in the Word document. Technically, a paragraph is a block of text that ends with a carriage return.
C#
public class Paragraph : Element
vb.net
Public Class Paragraph Inherits Element
Remarks
To create a new paragraph, use Element.InsertParagraphBefore() or Element.InsertParagraphAfter(). Each of these methods take a single argument of type NamedStyle. This argument can be null. If it is null, the Normal style is used. This method can be called from the Document object becauseDocument inherits from the Element class.
Examples
C#
//--- Insert a paragraph at the end of a new document and add some sample text
WordApplication app = new WordApplication();
Document doc = app.Create();
Paragraph paragraph = doc.InsertParagraphAfter(null);
paragraph.InsertTextAfter("This is a new paragraph.");
//--- Get the first paragraph of an existing document
WordApplication app = new WordApplication();
Document doc = app.Open(@"C:\sample.doc");
Paragraph firstParagraph = doc.Elements(Element.Type.Paragraph)[0];
vb.net
'--- Insert a paragraph at the end of a new document and add some sample text
Dim app As New WordApplication()
Dim doc As Document = app.Create()
Dim parargraph As Paragraph = doc.InsertParagraphAfter(Nothing)
paragraph.InsertTextAfter("This is a new paragraph.")
'--- Get the first paragraph of an existing document
Dim app As New WordApplication()
Dim doc As Document = app.Open("C:\sample.doc")
Dim blocks() As BlockElements = doc.BlockElements
Dim firstParagraph As Paragraph = doc.Elements(Element.Type.Paragraph)(0)
Properties
Name |
Description |
|---|---|
| Sets or returns a ParagraphFormatting object that represents the formatting for this paragraph (positioning, line spacing, etc). | |
| Returns or sets an NamedStyle object that represents the Style of this paragraph. |
