Character Style

Word allows a set of run-level properties to be given a name. The set of properties is called a character style. All the settings may be applied to a run in a single action by setting the style of the run.


There are two call protocols related to character style: getting and setting the character style of a run, and specifying a style when creating a run.

Get run style:

>>> run = p.add_run()

< object at 0x1053ab5d0>
'Default Paragraph Font'

Set run style using character style name:

>>> = 'Emphasis'

Set run style using character style object:

>>> = document.styles['Strong']

Assigning None to causes any applied character style to be removed. A run without a character style inherits the default character style of the document:

>>> = None
'Default Paragraph Font'

Specifying the style of a run on creation:

>>> run = p.add_run(style='Strong')

Specimen XML

A baseline regular run:

    <w:t>This is a regular paragraph.</w:t>

Adding Emphasis character style:

      <w:rStyle w:val="Emphasis"/>
    <w:t>This paragraph appears in Emphasis character style.</w:t>

A style that appears in the Word user interface (UI) with one or more spaces in its name, such as “Subtle Emphasis”, will generally have a style ID with those spaces removed. In this example, “Subtle Emphasis” becomes “SubtleEmphasis”:

      <w:rStyle w:val="SubtleEmphasis"/>
    <w:t>a few words in Subtle Emphasis style</w:t>

Schema excerpt

<xsd:complexType name="CT_R">  <!-- flattened for readibility -->
    <xsd:element name="rPr" type="CT_RPr" minOccurs="0"/>
    <xsd:group   ref="EG_RunInnerContent" minOccurs="0" maxOccurs="unbounded"/>
  <xsd:attribute name="rsidRPr" type="ST_LongHexNumber"/>
  <xsd:attribute name="rsidDel" type="ST_LongHexNumber"/>
  <xsd:attribute name="rsidR"   type="ST_LongHexNumber"/>

<xsd:complexType name="CT_RPr">  <!-- denormalized -->
    <xsd:choice minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="rStyle"          type="CT_String"/>
      <xsd:element name="rFonts"          type="CT_Fonts"/>
      <xsd:element name="b"               type="CT_OnOff"/>
      <xsd:element name="bCs"             type="CT_OnOff"/>
      <xsd:element name="i"               type="CT_OnOff"/>
      <xsd:element name="iCs"             type="CT_OnOff"/>
      <xsd:element name="caps"            type="CT_OnOff"/>
      <xsd:element name="smallCaps"       type="CT_OnOff"/>
      <xsd:element name="strike"          type="CT_OnOff"/>
      <xsd:element name="dstrike"         type="CT_OnOff"/>
      <xsd:element name="outline"         type="CT_OnOff"/>
      <xsd:element name="shadow"          type="CT_OnOff"/>
      <xsd:element name="emboss"          type="CT_OnOff"/>
      <xsd:element name="imprint"         type="CT_OnOff"/>
      <xsd:element name="noProof"         type="CT_OnOff"/>
      <xsd:element name="snapToGrid"      type="CT_OnOff"/>
      <xsd:element name="vanish"          type="CT_OnOff"/>
      <xsd:element name="webHidden"       type="CT_OnOff"/>
      <xsd:element name="color"           type="CT_Color"/>
      <xsd:element name="spacing"         type="CT_SignedTwipsMeasure"/>
      <xsd:element name="w"               type="CT_TextScale"/>
      <xsd:element name="kern"            type="CT_HpsMeasure"/>
      <xsd:element name="position"        type="CT_SignedHpsMeasure"/>
      <xsd:element name="sz"              type="CT_HpsMeasure"/>
      <xsd:element name="szCs"            type="CT_HpsMeasure"/>
      <xsd:element name="highlight"       type="CT_Highlight"/>
      <xsd:element name="u"               type="CT_Underline"/>
      <xsd:element name="effect"          type="CT_TextEffect"/>
      <xsd:element name="bdr"             type="CT_Border"/>
      <xsd:element name="shd"             type="CT_Shd"/>
      <xsd:element name="fitText"         type="CT_FitText"/>
      <xsd:element name="vertAlign"       type="CT_VerticalAlignRun"/>
      <xsd:element name="rtl"             type="CT_OnOff"/>
      <xsd:element name="cs"              type="CT_OnOff"/>
      <xsd:element name="em"              type="CT_Em"/>
      <xsd:element name="lang"            type="CT_Language"/>
      <xsd:element name="eastAsianLayout" type="CT_EastAsianLayout"/>
      <xsd:element name="specVanish"      type="CT_OnOff"/>
      <xsd:element name="oMath"           type="CT_OnOff"/>
    <xsd:element name="rPrChange" type="CT_RPrChange" minOccurs="0"/>

<xsd:complexType name="CT_String">
  <xsd:attribute name="val" type="s:ST_String" use="required"/>

<xsd:simpleType name="ST_String">
  <xsd:restriction base="xsd:string"/>