添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge
public class Body : DocumentFormat.OpenXml.Wordprocessing.BodyType
type Body = class
    inherit BodyType
Public Class Body
Inherits BodyType
Inheritance

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  
	

Remarks

[ISO/IEC 29500-1 1st Edition]

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: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

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

� ISO/IEC29500: 2008.

Gets all extended attributes (attributes not defined in the schema) of the current element.

(Inherited from OpenXmlElement)

Gets the last child of the current OpenXmlElement element. Returns null (Nothing in Visual Basic) if there is no such OpenXmlElement element.

(Inherited from OpenXmlCompositeElement)

Sets the markup compatibility attributes. Returns null if no markup compatibility attributes are defined for the current element.

(Inherited from OpenXmlElement)

Gets all the namespace declarations defined in the current element. Returns an empty enumerator if there is no namespace declaration.

(Inherited from OpenXmlElement)

Get the first annotation object of the specified type from the current OpenXmlElement element.

(Inherited from OpenXmlElement)

Get the first annotation object of the specified type from the current OpenXmlElement element.

(Inherited from OpenXmlElement)

Gets a collection of annotations with the specified type for the current OpenXmlElement element.

(Inherited from OpenXmlElement)

Gets a collection of annotations with the specified type for the current OpenXmlElement element.

(Inherited from OpenXmlElement)

Appends each element from a list of elements to the end of the current element's list of child elements.

(Inherited from OpenXmlElement)

Appends each element from an array of elements to the end of the current element's list of child elements.

(Inherited from OpenXmlElement)

Enumerates all of the sibling elements that follow the current element and have the same parent as the current element.

(Inherited from OpenXmlElement)

Enumerates all of the sibling elements that precede the current element and have the same parent as the current element.

(Inherited from OpenXmlElement)

Gets the OpenXmlElement element that immediately follows the current OpenXmlElement element. Returns null (Nothing in Visual Basic) if there is no next OpenXmlElement element.

(Inherited from OpenXmlElement)

Gets the OpenXmlElement element with the specified type that follows the current OpenXmlElement element. Returns null (Nothing in Visual Basic) if there is no next OpenXmlElement.

(Inherited from OpenXmlElement)

Inserts the specified element at the beginning of the current element's list of child nodes.

(Inherited from OpenXmlCompositeElement)

Gets the OpenXmlElement element that immediately precedes the current OpenXmlElement element. Returns null (Nothing in Visual Basic ) if there is no preceding OpenXmlElement element.

(Inherited from OpenXmlElement)

Gets the OpenXmlElement element with the specified type that precedes the current OpenXmlElement. Returns null (Nothing in Visual Basic) if there is no preceding OpenXmlElement element.

(Inherited from OpenXmlElement)

Removes the namespace declaration for the specified prefix. Removes nothing if there is no prefix.

(Inherited from OpenXmlElement)

Replaces one of the current element's child elements with another OpenXmlElement element.

(Inherited from OpenXmlCompositeElement)

Sets an attribute to the specified element. If the attribute is a known attribute, the value of the attribute is set. If the attribute is an extended attribute, the 'openxmlAttribute' is added to the extended attributes list.

(Inherited from OpenXmlElement)

Sets a number of attributes to the element. If an attribute is a known attribute, the value of the attribute is set. If an attribute is an extended attribute, the 'openxmlAttribute' is added to the extended attributes list.

(Inherited from OpenXmlElement)