Compartir a través de


Body Class

Document Body.When the object is serialized out as xml, its qualified name is w:body.

Inheritance Hierarchy

System.Object
  DocumentFormat.OpenXml.OpenXmlElement
    DocumentFormat.OpenXml.OpenXmlCompositeElement
      DocumentFormat.OpenXml.Wordprocessing.BodyType
        DocumentFormat.OpenXml.Wordprocessing.Body

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

Syntax

'Declaration
Public Class Body _
    Inherits BodyType
'Usage
Dim instance As Body
public class Body : BodyType

Remarks

The following table lists the possible child types:

  • AltChunk <w:altChunk>

  • CustomXmlBlock <w:customXml>

  • SdtBlock <w:sdt>

  • Paragraph <w:p>

  • Table <w:tbl>

  • ProofError <w:proofErr>

  • PermStart <w:permStart>

  • PermEnd <w:permEnd>

  • BookmarkStart <w:bookmarkStart>

  • BookmarkEnd <w:bookmarkEnd>

  • CommentRangeStart <w:commentRangeStart>

  • CommentRangeEnd <w:commentRangeEnd>

  • MoveFromRangeStart <w:moveFromRangeStart>

  • MoveFromRangeEnd <w:moveFromRangeEnd>

  • MoveToRangeStart <w:moveToRangeStart>

  • MoveToRangeEnd <w:moveToRangeEnd>

  • CustomXmlInsRangeStart <w:customXmlInsRangeStart>

  • CustomXmlInsRangeEnd <w:customXmlInsRangeEnd>

  • CustomXmlDelRangeStart <w:customXmlDelRangeStart>

  • CustomXmlDelRangeEnd <w:customXmlDelRangeEnd>

  • CustomXmlMoveFromRangeStart <w:customXmlMoveFromRangeStart>

  • CustomXmlMoveFromRangeEnd <w:customXmlMoveFromRangeEnd>

  • CustomXmlMoveToRangeStart <w:customXmlMoveToRangeStart>

  • CustomXmlMoveToRangeEnd <w:customXmlMoveToRangeEnd>

  • DocumentFormat.OpenXml.Office2010.Word.CustomXmlConflictInsertionRangeStart <w14:customXmlConflictInsRangeStart>

  • DocumentFormat.OpenXml.Office2010.Word.CustomXmlConflictInsertionRangeEnd <w14:customXmlConflictInsRangeEnd>

  • DocumentFormat.OpenXml.Office2010.Word.CustomXmlConflictDeletionRangeStart <w14:customXmlConflictDelRangeStart>

  • DocumentFormat.OpenXml.Office2010.Word.CustomXmlConflictDeletionRangeEnd <w14:customXmlConflictDelRangeEnd>

  • InsertedRun <w:ins>

  • DeletedRun <w:del>

  • MoveFromRun <w:moveFrom>

  • MoveToRun <w:moveTo>

  • ContentPart <w:contentPart>

  • DocumentFormat.OpenXml.Office2010.Word.RunConflictInsertion <w14:conflictIns>

  • DocumentFormat.OpenXml.Office2010.Word.RunConflictDeletion <w14:conflictDel>

  • SectionProperties <w:sectPr>

[ISO/IEC 29500-1 1st Edition]

17.2.2 body (Document Body)

This element specifies the contents of the body of the document - the main document editing surface.

The document body contains what is referred to as block-level markup - markup which can exist as a sibling element to paragraphs in a WordprocessingML document.

[Example: Consider a document with a single paragraph in the main document story. This document would require the following WordprocessingML in its main document part:

<w:document>
  <w:body>
    <w:p/>
  </w:body>
</w:document>

The fact that the paragraph is inside the body element makes it part of the main document story. end example]

Parent Elements

document (§17.2.3)

Child Elements

Subclause

altChunk (Anchor for Imported External Content)

§17.17.2.1

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 (Block-Level Custom XML Element)

§17.5.1.6

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

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

p (Paragraph)

§17.3.1.22

permEnd (Range Permission End)

§17.13.7.1

permStart (Range Permission Start)

§17.13.7.2

proofErr (Proofing Error Anchor)

§17.13.8.1

sdt (Block-Level Structured Document Tag)

§17.5.2.29

sectPr (Document Final Section Properties)

§17.6.17

tbl (Table)

§17.4.38

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

© ISO/IEC29500: 2008.

Examples

The following code example creates a word-processing document by package and writes some text into it.

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

namespace BodyEx
{
    class Program
    {
        // Create a document by package, and write some text in it.
        static void Main(string[] args)
        {
            string fileName = @"C:\users\public\documents\BodyEx.zip";

            // Create a word document by package. 
            Package package = Package.Open(fileName);
            WordprocessingDocument wordprocessingDocument = 
                WordprocessingDocument.Create(package, WordprocessingDocumentType.Template);

            // Make some changes to the document.
            MainDocumentPart mainDocumentPart = wordprocessingDocument.AddMainDocumentPart();
            mainDocumentPart.Document = new Document();
            Document document = mainDocumentPart.Document;
            Body body = document.AppendChild(new Body());
            Paragraph para = body.AppendChild(new Paragraph());
            Run run = para.AppendChild(new Run());
            run.AppendChild(new Text("Created text in body."));

            // Close the document and the package.
            wordprocessingDocument.Close();
            package.Close();

            Console.WriteLine("The package has been created.\nPress a key.");
            Console.ReadKey();
        }
    }
}
Imports System.IO.Packaging
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing

Module Module1
Sub Main(args As String())
        Dim fileName As String = "C:\users\public\documents\BodyEx.zip"

        ' Create a word document by package. 
        Dim package As Package = package.Open(fileName)
        Dim wordprocessingDocument As WordprocessingDocument = _
            wordprocessingDocument.Create(package, WordprocessingDocumentType.Template)

        ' Make some changes to the document.
        Dim mainDocumentPart As MainDocumentPart = _
            wordprocessingDocument.AddMainDocumentPart()
        mainDocumentPart.Document = New Document()
        Dim document As Document = mainDocumentPart.Document
        Dim body As Body = document.AppendChild(New Body())
        Dim para As Paragraph = body.AppendChild(New Paragraph())
        Dim run As Run = para.AppendChild(New Run())
        run.AppendChild(New Text("Created text in body."))

        ' Close the document and the package.
        wordprocessingDocument.Close()
        package.Close()

        Console.WriteLine("The package has been created." & vbLf & "Press a key.")
        Console.ReadKey()
    End Sub
End Module

Thread Safety

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

See Also

Reference

Body Members

DocumentFormat.OpenXml.Wordprocessing Namespace