Paragraph class

Office 2013 and later

Defines the Paragraph Class. When the object is serialized out as xml, its qualified name is w:p.

Namespace:  DocumentFormat.OpenXml.Wordprocessing
Assembly:  DocumentFormat.OpenXml (in DocumentFormat.OpenXml.dll)

[ChildElementInfoAttribute(typeof(RunConflictInsertion), FileFormatVersions.None|FileFormatVersions.Office2010|FileFormatVersions.Office2013)]
[ChildElementInfoAttribute(typeof(LimitUpper))]
[ChildElementInfoAttribute(typeof(ParagraphProperties))]
[ChildElementInfoAttribute(typeof(CustomXmlRun))]
[ChildElementInfoAttribute(typeof(SimpleField))]
[ChildElementInfoAttribute(typeof(Hyperlink))]
[ChildElementInfoAttribute(typeof(SdtRun))]
[ChildElementInfoAttribute(typeof(ProofError))]
[ChildElementInfoAttribute(typeof(PermStart))]
[ChildElementInfoAttribute(typeof(PermEnd))]
[ChildElementInfoAttribute(typeof(BookmarkStart))]
[ChildElementInfoAttribute(typeof(BookmarkEnd))]
[ChildElementInfoAttribute(typeof(CommentRangeStart))]
[ChildElementInfoAttribute(typeof(CommentRangeEnd))]
[ChildElementInfoAttribute(typeof(MoveFromRangeStart))]
[ChildElementInfoAttribute(typeof(MoveFromRangeEnd))]
[ChildElementInfoAttribute(typeof(MoveToRangeStart))]
[ChildElementInfoAttribute(typeof(MoveToRangeEnd))]
[ChildElementInfoAttribute(typeof(CustomXmlInsRangeStart))]
[ChildElementInfoAttribute(typeof(CustomXmlInsRangeEnd))]
[ChildElementInfoAttribute(typeof(CustomXmlDelRangeStart))]
[ChildElementInfoAttribute(typeof(CustomXmlDelRangeEnd))]
[ChildElementInfoAttribute(typeof(CustomXmlMoveFromRangeStart))]
[ChildElementInfoAttribute(typeof(CustomXmlMoveFromRangeEnd))]
[ChildElementInfoAttribute(typeof(CustomXmlMoveToRangeStart))]
[ChildElementInfoAttribute(typeof(CustomXmlMoveToRangeEnd))]
[ChildElementInfoAttribute(typeof(CustomXmlConflictInsertionRangeStart), FileFormatVersions.None|FileFormatVersions.Office2010|FileFormatVersions.Office2013)]
[ChildElementInfoAttribute(typeof(CustomXmlConflictInsertionRangeEnd), FileFormatVersions.None|FileFormatVersions.Office2010|FileFormatVersions.Office2013)]
[ChildElementInfoAttribute(typeof(CustomXmlConflictDeletionRangeStart), FileFormatVersions.None|FileFormatVersions.Office2010|FileFormatVersions.Office2013)]
[ChildElementInfoAttribute(typeof(CustomXmlConflictDeletionRangeEnd), FileFormatVersions.None|FileFormatVersions.Office2010|FileFormatVersions.Office2013)]
[ChildElementInfoAttribute(typeof(InsertedRun))]
[ChildElementInfoAttribute(typeof(DeletedRun))]
[ChildElementInfoAttribute(typeof(MoveFromRun))]
[ChildElementInfoAttribute(typeof(MoveToRun))]
[ChildElementInfoAttribute(typeof(ContentPart), FileFormatVersions.Office2010)]
[ChildElementInfoAttribute(typeof(SubDocumentReference))]
[ChildElementInfoAttribute(typeof(Paragraph))]
[ChildElementInfoAttribute(typeof(OfficeMath))]
[ChildElementInfoAttribute(typeof(Accent))]
[ChildElementInfoAttribute(typeof(Bar))]
[ChildElementInfoAttribute(typeof(Box))]
[ChildElementInfoAttribute(typeof(BorderBox))]
[ChildElementInfoAttribute(typeof(Delimiter))]
[ChildElementInfoAttribute(typeof(EquationArray))]
[ChildElementInfoAttribute(typeof(Fraction))]
[ChildElementInfoAttribute(typeof(MathFunction))]
[ChildElementInfoAttribute(typeof(GroupChar))]
[ChildElementInfoAttribute(typeof(LimitLower))]
[ChildElementInfoAttribute(typeof(RunConflictDeletion), FileFormatVersions.None|FileFormatVersions.Office2010|FileFormatVersions.Office2013)]
[ChildElementInfoAttribute(typeof(Matrix))]
[ChildElementInfoAttribute(typeof(Nary))]
[ChildElementInfoAttribute(typeof(Phantom))]
[ChildElementInfoAttribute(typeof(Radical))]
[ChildElementInfoAttribute(typeof(PreSubSuper))]
[ChildElementInfoAttribute(typeof(Subscript))]
[ChildElementInfoAttribute(typeof(SubSuperscript))]
[ChildElementInfoAttribute(typeof(Superscript))]
[ChildElementInfoAttribute(typeof(Run))]
[ChildElementInfoAttribute(typeof(Run))]
[ChildElementInfoAttribute(typeof(BidirectionalOverride), FileFormatVersions.Office2010)]
[ChildElementInfoAttribute(typeof(BidirectionalEmbedding), FileFormatVersions.Office2010)]
public class Paragraph : OpenXmlCompositeElement

[ISO/IEC 29500-1 1st Edition]

p (Paragraph)

This element specifies a paragraph of content in the document.

The contents of a paragraph in a WordprocessingML document shall consist of any combination of the following four kinds of content:

  • Paragraph properties

  • Annotations (bookmarks, comments, revisions)

  • Custom markup

  • Run level content (fields, hyperlinks, runs)

[Example: Consider a basic WordprocessingML document with a single paragraph. This paragraph would be expressed as follows:

<w:document>
  <w:body>
    <w:p>
      <w:r>
        <w:t>Text</w:t>
      </w:r>
      <w:fldSimple w:instr="AUTHOR">
        <w:r>
          <w:t>Author Name</w:t>
        </w:r>
      </w:fldSimple>
    </w:p>
  </w:body>
</w:document>

The p element is the container for all of the content in the paragraph, which in this example includes both a text run and a simple field. end example]

Parent Elements

body (§17.2.2); comment (§17.13.4.2); customXml (§17.5.1.6); docPartBody (§17.12.6); endnote (§17.11.2); footnote (§17.11.10); ftr (§17.10.3); hdr (§17.10.4); sdtContent (§17.5.2.34); tc (§17.4.66)

Child Elements

Subclause

bdo (Bidirectional Override)

§17.3.2.3

bookmarkEnd (Bookmark End)

§17.13.6.1

bookmarkStart (Bookmark Start)

§17.13.6.2

commentRangeEnd (Comment Anchor Range End)

§17.13.4.3

commentRangeStart (Comment Anchor Range Start)

§17.13.4.4

customXml (Inline-Level Custom XML Element)

§17.5.1.3

customXmlDelRangeEnd (Custom XML Markup Deletion End)

§17.13.5.4

customXmlDelRangeStart (Custom XML Markup Deletion Start)

§17.13.5.5

customXmlInsRangeEnd (Custom XML Markup Insertion End)

§17.13.5.6

customXmlInsRangeStart (Custom XML Markup Insertion Start)

§17.13.5.7

customXmlMoveFromRangeEnd (Custom XML Markup Move Source End)

§17.13.5.8

customXmlMoveFromRangeStart (Custom XML Markup Move Source Start)

§17.13.5.9

customXmlMoveToRangeEnd (Custom XML Markup Move Destination Location End)

§17.13.5.10

customXmlMoveToRangeStart (Custom XML Markup Move Destination Location Start)

§17.13.5.11

del (Deleted Run Content)

§17.13.5.14

dir (Bidirectional Embedding Level)

§17.3.2.8

fldSimple (Simple Field)

§17.16.19

hyperlink (Hyperlink)

§17.16.22

ins (Inserted Run Content)

§17.13.5.18

moveFrom (Move Source Run Content)

§17.13.5.22

moveFromRangeEnd (Move Source Location Container - End)

§17.13.5.23

moveFromRangeStart (Move Source Location Container - Start)

§17.13.5.24

moveTo (Move Destination Run Content)

§17.13.5.25

moveToRangeEnd (Move Destination Location Container - End)

§17.13.5.27

moveToRangeStart (Move Destination Location Container - Start)

§17.13.5.28

oMath (Office Math)

§22.1.2.77

oMathPara (Office Math Paragraph)

§22.1.2.78

permEnd (Range Permission End)

§17.13.7.1

permStart (Range Permission Start)

§17.13.7.2

pPr (Paragraph Properties)

§17.3.1.26

proofErr (Proofing Error Anchor)

§17.13.8.1

r (Text Run)

§17.3.2.25

sdt (Inline-Level Structured Document Tag)

§17.5.2.31

smartTag (Inline-Level Smart Tag)

§17.5.1.9

subDoc (Anchor for Subdocument Location)

§17.17.1.1

Attributes

Description

rsidDel (Revision Identifier for Paragraph Deletion)

Specifies a unique identifier used to track the editing session when the paragraph was deleted from the main document.

All rsid* attributes throughout this document with the same value, if present, shall indicate that those regions were modified during the same editing session (time between subsequent save actions).

A producer can choose to increment the revision save ID value to indicate subsequent editing sessions to indicate the order of the modifications relative to other modifications in this document.

The possible values for this attribute are defined by the ST_LongHexNumber simple type (§17.18.50).

rsidP (Revision Identifier for Paragraph Properties)

This attribute specifies a unique identifier used to track the editing session when the paragraph's properties were last modified in this document.

All rsid* attributes throughout this document with the same value, if present, shall indicate that those regions were modified during the same editing session (time between subsequent save actions).

A producer can choose to increment the revision save ID value to indicate subsequent editing sessions to indicate the order of the modifications relative to other modifications in this document.

The possible values for this attribute are defined by the ST_LongHexNumber simple type (§17.18.50).

rsidR (Revision Identifier for Paragraph)

This attribute specifies a unique identifier used to track the editing session when the paragraph was added to the main document.

All rsid* attributes throughout this document with the same value, if present, shall indicate that those regions were modified during the same editing session (time between subsequent save actions).

A producer can choose to increment the revision save ID value to indicate subsequent editing sessions to indicate the order of the modifications relative to other modifications in this document.

The possible values for this attribute are defined by the ST_LongHexNumber simple type (§17.18.50).

rsidRDefault (Default Revision Identifier for Runs)

This attribute specifies a unique identifier used for all runs in this paragraph which do not explicitly declare an rsidR attribute. This attribute allows consumers to optimize the locations where rsid* values are written in this document.

All rsid* attributes throughout this document with the same value, if present, shall indicate that those regions were modified during the same editing session (time between subsequent save actions).

A producer can choose to increment the revision save ID value to indicate subsequent editing sessions to indicate the order of the modifications relative to other modifications in this document.

The possible values for this attribute are defined by the ST_LongHexNumber simple type (§17.18.50).

rsidRPr (Revision Identifier for Paragraph Glyph Formatting)

This attribute specifies a unique identifier used to track the editing session when the glyph character representing the paragraph mark was last modified in the main document.

All rsid* attributes throughout this document with the same value, if present, shall indicate that those regions were modified during the same editing session (time between subsequent save actions).

A producer can choose to increment the revision save ID value to indicate subsequent editing sessions to indicate the order of the modifications relative to other modifications in this document.

The possible values for this attribute are defined by the ST_LongHexNumber simple type (§17.18.50).

[Note: The W3C XML Schema definition of this element’s content model (CT_P) is located in §A.1. end note]

© ISO/IEC29500: 2008.

The following code example opens an existing word-processing file and writes text to it.

using System;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;

namespace ParagraphEx
{
    class Program
    {
        // Open an existing file and add text to it.
        static void Main(string[] args)
        {
           string fileName = @"C:\Users\Public\Documents\ParagraphEx.docx";

           // Open the file for editing.
           using (WordprocessingDocument wordprocessingDocument =
               WordprocessingDocument.Open(fileName, true))
           {
                    // Get document element of the Package.
                    Document document = 
                        wordprocessingDocument.MainDocumentPart.Document;

                    // Add new text to the file. 
                    document.Append(new Body
                        (new Paragraph
                            (new Run
                                (new Text
                                    ("This is the inserted text by the example.")))));
                    Console.WriteLine("All done. Press a key.");
                    Console.ReadKey();
           }
        }
    }
}

Imports System
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing

Module Module1

    ' Open an existing file and add text to it.
    Sub Main()
        Dim fileName As String = "C:\Users\Public\Documents\ParagraphEx.docx"

        ' Open the file for editing.
        Using wordprocessingDocument As WordprocessingDocument = wordprocessingDocument.Open(fileName, True)
            ' Get document element of the Package.
            Dim document As Document = wordprocessingDocument.MainDocumentPart.Document

            ' Add new text to the file. 
            document.Append(New Body _
                            (New Paragraph _
                             (New Run _
                              (New Text _
                               ("This is the inserted text by the example.")))))
            Console.WriteLine("All done. Press a key.")
            Console.ReadKey()
        End Using
    End Sub
End Module

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: