Compartir a través de


Run Class

Phonetic Guide Text Run.When the object is serialized out as xml, its qualified name is w:r.

Inheritance Hierarchy

System.Object
  DocumentFormat.OpenXml.OpenXmlElement
    DocumentFormat.OpenXml.OpenXmlCompositeElement
      DocumentFormat.OpenXml.Wordprocessing.Run

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

Syntax

'Declaration
<ChildElementInfoAttribute(GetType(FieldCode))> _
<ChildElementInfoAttribute(GetType(FootnoteReferenceMark))> _
<ChildElementInfoAttribute(GetType(EndnoteReferenceMark))> _
<ChildElementInfoAttribute(GetType(LastRenderedPageBreak))> _
<ChildElementInfoAttribute(GetType(Break))> _
<ChildElementInfoAttribute(GetType(Text))> _
<ChildElementInfoAttribute(GetType(DeletedText))> _
<ChildElementInfoAttribute(GetType(DeletedFieldCode))> _
<ChildElementInfoAttribute(GetType(NoBreakHyphen))> _
<ChildElementInfoAttribute(GetType(SoftHyphen))> _
<ChildElementInfoAttribute(GetType(DayShort))> _
<ChildElementInfoAttribute(GetType(MonthShort))> _
<ChildElementInfoAttribute(GetType(YearShort))> _
<ChildElementInfoAttribute(GetType(DayLong))> _
<ChildElementInfoAttribute(GetType(MonthLong))> _
<ChildElementInfoAttribute(GetType(YearLong))> _
<ChildElementInfoAttribute(GetType(AnnotationReferenceMark))> _
<ChildElementInfoAttribute(GetType(EmbeddedObject))> _
<ChildElementInfoAttribute(GetType(PositionalTab))> _
<ChildElementInfoAttribute(GetType(SeparatorMark))> _
<ChildElementInfoAttribute(GetType(ContinuationSeparatorMark))> _
<ChildElementInfoAttribute(GetType(SymbolChar))> _
<ChildElementInfoAttribute(GetType(PageNumber))> _
<ChildElementInfoAttribute(GetType(CarriageReturn))> _
<ChildElementInfoAttribute(GetType(TabChar))> _
<ChildElementInfoAttribute(GetType(RunProperties))> _
<ChildElementInfoAttribute(GetType(Picture))> _
<ChildElementInfoAttribute(GetType(FieldChar))> _
<ChildElementInfoAttribute(GetType(Ruby))> _
<ChildElementInfoAttribute(GetType(FootnoteReference))> _
<ChildElementInfoAttribute(GetType(EndnoteReference))> _
<ChildElementInfoAttribute(GetType(CommentReference))> _
<ChildElementInfoAttribute(GetType(Drawing))> _
Public Class Run _
    Inherits OpenXmlCompositeElement
'Usage
Dim instance As Run
[ChildElementInfoAttribute(typeof(FieldCode))]
[ChildElementInfoAttribute(typeof(FootnoteReferenceMark))]
[ChildElementInfoAttribute(typeof(EndnoteReferenceMark))]
[ChildElementInfoAttribute(typeof(LastRenderedPageBreak))]
[ChildElementInfoAttribute(typeof(Break))]
[ChildElementInfoAttribute(typeof(Text))]
[ChildElementInfoAttribute(typeof(DeletedText))]
[ChildElementInfoAttribute(typeof(DeletedFieldCode))]
[ChildElementInfoAttribute(typeof(NoBreakHyphen))]
[ChildElementInfoAttribute(typeof(SoftHyphen))]
[ChildElementInfoAttribute(typeof(DayShort))]
[ChildElementInfoAttribute(typeof(MonthShort))]
[ChildElementInfoAttribute(typeof(YearShort))]
[ChildElementInfoAttribute(typeof(DayLong))]
[ChildElementInfoAttribute(typeof(MonthLong))]
[ChildElementInfoAttribute(typeof(YearLong))]
[ChildElementInfoAttribute(typeof(AnnotationReferenceMark))]
[ChildElementInfoAttribute(typeof(EmbeddedObject))]
[ChildElementInfoAttribute(typeof(PositionalTab))]
[ChildElementInfoAttribute(typeof(SeparatorMark))]
[ChildElementInfoAttribute(typeof(ContinuationSeparatorMark))]
[ChildElementInfoAttribute(typeof(SymbolChar))]
[ChildElementInfoAttribute(typeof(PageNumber))]
[ChildElementInfoAttribute(typeof(CarriageReturn))]
[ChildElementInfoAttribute(typeof(TabChar))]
[ChildElementInfoAttribute(typeof(RunProperties))]
[ChildElementInfoAttribute(typeof(Picture))]
[ChildElementInfoAttribute(typeof(FieldChar))]
[ChildElementInfoAttribute(typeof(Ruby))]
[ChildElementInfoAttribute(typeof(FootnoteReference))]
[ChildElementInfoAttribute(typeof(EndnoteReference))]
[ChildElementInfoAttribute(typeof(CommentReference))]
[ChildElementInfoAttribute(typeof(Drawing))]
public class Run : OpenXmlCompositeElement

Remarks

The following table lists the possible child types:

  • RunProperties <w:rPr>

  • Break <w:br>

  • Text <w:t>

  • DeletedText <w:delText>

  • FieldCode <w:instrText>

  • DeletedFieldCode <w:delInstrText>

  • NoBreakHyphen <w:noBreakHyphen>

  • SoftHyphen <w:softHyphen>

  • DayShort <w:dayShort>

  • MonthShort <w:monthShort>

  • YearShort <w:yearShort>

  • DayLong <w:dayLong>

  • MonthLong <w:monthLong>

  • YearLong <w:yearLong>

  • AnnotationReferenceMark <w:annotationRef>

  • FootnoteReferenceMark <w:footnoteRef>

  • EndnoteReferenceMark <w:endnoteRef>

  • SeparatorMark <w:separator>

  • ContinuationSeparatorMark <w:continuationSeparator>

  • SymbolChar <w:sym>

  • PageNumber <w:pgNum>

  • CarriageReturn <w:cr>

  • TabChar <w:tab>

  • EmbeddedObject <w:object>

  • Picture <w:pict>

  • FieldChar <w:fldChar>

  • Ruby <w:ruby>

  • FootnoteReference <w:footnoteReference>

  • EndnoteReference <w:endnoteReference>

  • CommentReference <w:commentReference>

  • Drawing <w:drawing>

  • PositionalTab <w:ptab>

  • LastRenderedPageBreak <w:lastRenderedPageBreak>

[ISO/IEC 29500-1 1st Edition]

17.3.2.25 r (Text Run)

This element specifies a run of content in the parent field, hyperlink, custom XML element, structured document tag, smart tag, or paragraph.

The contents of a run in a WordprocessingML document shall consist of any combination of run content.

[Example: Consider a basic WordprocessingML paragraph with a pair of runs. This run 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 r element is the container for all of the content in the run, which in this example includes both a run in the paragraph and a run within a simple field. end example]

Parent Elements

bdo (§17.3.2.3); customXml (§17.5.1.3); del (§17.13.5.14); dir (§17.3.2.8); fldSimple (§17.16.19); hyperlink (§17.16.22); ins (§17.13.5.18); moveFrom (§17.13.5.22); moveTo (§17.13.5.25); p (§17.3.1.22); rt (§17.3.3.24); rubyBase (§17.3.3.27); sdtContent (§17.5.2.36); smartTag (§17.5.1.9)

Child Elements

Subclause

annotationRef (Comment Information Block)

§17.13.4.1

br (Break)

§17.3.3.1

commentReference (Comment Content Reference Mark)

§17.13.4.5

contentPart (Content Part)

§17.3.3.2

continuationSeparator (Continuation Separator Mark)

§17.11.1

cr (Carriage Return)

§17.3.3.4

dayLong (Date Block - Long Day Format)

§17.3.3.5

dayShort (Date Block - Short Day Format)

§17.3.3.6

delInstrText (Deleted Field Code)

§17.16.13

delText (Deleted Text)

§17.3.3.7

drawing (DrawingML Object)

§17.3.3.9

endnoteRef (Endnote Reference Mark)

§17.11.6

endnoteReference (Endnote Reference)

§17.11.7

fldChar (Complex Field Character)

§17.16.18

footnoteRef (Footnote Reference Mark)

§17.11.13

footnoteReference (Footnote Reference)

§17.11.14

instrText (Field Code)

§17.16.23

lastRenderedPageBreak (Position of Last Calculated Page Break)

§17.3.3.13

monthLong (Date Block - Long Month Format)

§17.3.3.15

monthShort (Date Block - Short Month Format)

§17.3.3.16

noBreakHyphen (Non Breaking Hyphen Character)

§17.3.3.18

object (Embedded Object)

§17.3.3.19

pgNum (Page Number Block)

§17.3.3.22

ptab (Absolute Position Tab Character)

§17.3.3.23

rPr (Run Properties)

§17.3.2.28

ruby (Phonetic Guide)

§17.3.3.25

separator (Footnote/Endnote Separator Mark)

§17.11.23

softHyphen (Optional Hyphen Character)

§17.3.3.29

sym (Symbol Character)

§17.3.3.30

t (Text)

§17.3.3.31

tab (Tab Character)

§17.3.3.32

yearLong (Date Block - Long Year Format)

§17.3.3.33

yearShort (Date Block - Short Year Format)

§17.3.3.34

Attributes

Description

rsidDel (Revision Identifier for Run Deletion)

Specifies a unique identifier used to track the editing session when the run 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).

rsidR (Revision Identifier for Run)

Specifies a unique identifier used to track the editing session when the run 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).

rsidRPr (Revision Identifier for Run Properties)

Specifies a unique identifier used to track the editing session when the run properties were 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_R) is located in §A.1. end note]

© ISO/IEC29500: 2008.

Examples

The following example creates a word processing document and writes the text, “Hello, World!” into it.

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

namespace RunEx
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a document by path, and write some text in it.
            string fileName = @"C:\Users\Public\Documents\RunEx.docx";
            string txt = "Hello, world!";

            // Create the Word document. 
            WordprocessingDocument wordprocessingDocument =
                WordprocessingDocument.Create(fileName, 
                    WordprocessingDocumentType.Document);

            // Create a MainDocumentPart instance.
            MainDocumentPart mainDocumentPart = 
                wordprocessingDocument.AddMainDocumentPart();
            mainDocumentPart.Document = new Document();

            // Create a Document instance.
            Document document = mainDocumentPart.Document;

            // Create a Body instance.
            Body body = document.AppendChild(new Body());

            // Create a Paragraph instance.
            Paragraph para = body.AppendChild(new Paragraph());

            // Create a Run instance.
            Run run = para.AppendChild(new Run());

            // Add Text to the Run element.
            run.AppendChild(new Text(txt));

            // Close the document handle
            wordprocessingDocument.Close();

            Console.WriteLine("The document has been created. Press any key.");
            Console.ReadKey();
        }
    }   
}
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing

Module Module1
    Sub Main(ByVal args As String())
        ' Create a document by path, and write some text in it.
        Dim fileName As String = "C:\Users\Public\Documents\RunEx.docx"
        Dim txt As String = "Hello, world!"

        ' Create the Word document. 
        Dim wordprocessingDocument As WordprocessingDocument = _
            wordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)

        ' Create a MainDocumentPart instance.
        Dim mainDocumentPart As MainDocumentPart = _
        wordprocessingDocument.AddMainDocumentPart()
        mainDocumentPart.Document = New Document()

        ' Create a Document instance.
        Dim document As Document = mainDocumentPart.Document

        ' Create a Body instance.
        Dim body As Body = document.AppendChild(New Body())

        ' Create a Paragraph instance.
        Dim para As Paragraph = body.AppendChild(New Paragraph())

        ' Create a Run instance.
        Dim run As Run = para.AppendChild(New Run())

        ' Add Text to the Run element.
        run.AppendChild(New Text(txt))

        ' Close the document handle
        wordprocessingDocument.Close()

        Console.WriteLine("The document has been created. Press any 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

Run Members

DocumentFormat.OpenXml.Wordprocessing Namespace