xmlopenxmldocx

Purpose of w:rPr versus w:pPr in OOXML (DOCX)?


I'm confused about Office Open XML architecture: w:rPr tag doesn't seem to be working when inside of a w:pPr tag.

<w:p w:rsidR="00573C57" w:rsidRPr="004A77F9" w:rsidRDefault="00573C57" w:rsidP="006F57C5">
    <w:pPr>
        <w:rPr>
            <w:b />
            <w:sz w:val="36" />
            <w:szCs w:val="36" />
        </w:rPr>
    </w:pPr>
    <w:r w:rsidRPr="004A77F9">
        <w:rPr>
            <w:b />
            <w:sz w:val="36" />
            <w:szCs w:val="36" />
        </w:rPr>
        <w:t xml:space="preserve"> BUSINESS</w:t>
    </w:r>
    <w:r w:rsidRPr="004A77F9">
        <w:t xml:space="preserve"> PLAN FILE</w:t>
    </w:r>
</w:p>

First w:r tag has a w:rPr tag which including bold (w:b) and font-size (w:sz) so section style taking bold and font-size style when docx outputting.

Last w:r tag hasn't w:rPr tag so this section has no style when docx outputting.

Then why w:pPr tag has w:rPr style when totally useless?


Solution

  • OOXML character properties can be applied at the paragraph (w:p/w:pPr) or run (w:r/w:rPr) levels. Properties at the run level override those at the paragraph level.

    In your particular example, there are currently no (general, but see note #2 below) paragraph-level properties and one run-level property, which is responsible for BUSINESS being bold.

    Notes:

    1. There's no guarantee that character properties will be normalized to a minimal representation for any given effect.

    2. When a w:rPr element appears within a w:pPr,

      <w:pPr>
          <w:rPr>
              <w:b />
              <w:sz w:val="36" />
              <w:szCs w:val="36" />
          </w:rPr>
      </w:pPr>
      

      it applies only to the paragraph glyph (¶). (Yes, it's a rather esoteric feature.) If you want to format the paragraph glyph, add properties there; if you do not particularly care about the paragraph glyph, you can remove the w:pPr/w:rPr wrapper and allow its properties to apply at the paragraph level:

      <w:pPr>
          <w:b />
          <w:sz w:val="36" />
          <w:szCs w:val="36" />
      </w:pPr>