Working with runs (Open XML SDK)

Office 2013 and later

Last modified: April 11, 2013

Applies to: Office 2013 | Open XML

In this article
Runs in WordprocessingML
Run Class
Open XML SDK Code Example

This topic discusses the Open XML SDK 2.5 Run class and how it relates to the Open XML File Format WordprocessingML schema.

The following text from the ISO/IEC 29500 specification introduces the Open XML WordprocessingML run element.

The next level of the document hierarchy [after the paragraph] is the run, which defines a region of text with a common set of properties. A run is represented by an r element, which allows the producer to combine breaks, styles, or formatting properties, applying the same information to all the parts of the run.

Just as a paragraph can have properties, so too can a run. All of the elements inside an r element have their properties controlled by a corresponding optional rPr run properties element, which must be the first child of the r element. In turn, the rPr element is a container for a set of property elements that are applied to the rest of the children of the r element. The elements inside the rPr container element allow the consumer to control whether the text in the following t elements is bold, underlined, or visible, for example. Some examples of run properties are bold, border, character style, color, font, font size, italic, kerning, disable spelling/grammar check, shading, small caps, strikethrough, text direction, and underline.

© ISO/IEC29500: 2008.

The following table lists the most common Open XML SDK classes used when working with runs.

XML element

Open XML SDK 2.0 Class

p

Paragraph

rPr

RunProperties

t

Text

The Open XML SDK 2.5Run class represents the run (<r>) element defined in the Open XML File Format schema for WordprocessingML documents as discussed above. Use a Run object to manipulate an individual <r> element in a WordprocessingML document.

RunProperties Class

In WordprocessingML, the properties for a run element are specified using the run properties (<rPr>) element. Some examples of run properties are bold, border, character style, color, font, font size, italic, kerning, disable spelling/grammar check, shading, small caps, strikethrough, text direction, and underline. Use a RunProperties object to set the properties for a run in a WordprocessingML document.

Text Object

With the <r> element, the text (<t>) element is the container for the text that makes up the document content. The OXML SDK Text class represents the <t> element. Use a Text object to place text in a Wordprocessing document.

The following code adds text to the main document surface of the specified WordprocessingML document. A Run object demarcates a region of text within the paragraph and then a RunProperties object is used to apply bold formatting to the run.

No code example is currently available or this language may not be supported.

When this code is run, the following XML is written to the WordprocessingML document specified in the preceding code.

<w:p>
  <w:r>
    <w:rPr>
      <w:b />
    </w:rPr>
    <w:t>String from WriteToWordDoc method.</w:t>
  </w:r>
</w:p>

Contribute to this article

Want to edit or suggest changes to this content? You can edit and submit changes to this article using GitHub.

Show: