Shared String Table
The main difference between plain text and rich text is seen in the string table itself. The <si>
element is capable of containing rich text expressions:
<si> <r> <t xml:space="preserve">This </t> </r> <r> <rPr> <b/> <sz val="11"/> <color theme="1"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t xml:space="preserve">string </t> </r> <r> <rPr> <sz val="11"/> <color rgb="FFFF0000"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t>has</t> </r> <r> <rPr> <sz val="11"/> <color theme="1"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t xml:space="preserve"> a </t> </r> <r> <rPr> <i/> <sz val="11"/> <color rgb="FF00B050"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t>variety</t> </r> <r> <rPr> <sz val="11"/> <color theme="1"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t xml:space="preserve"> of </t> </r> <r> <rPr> <u/> <sz val="11"/> <color theme="1"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t>formatting</t> </r> <r> <rPr> <sz val="11"/> <color theme="1"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t xml:space="preserve"> applied</t> </r> </si>
Reading the string from left to right as it appears in the cell, each word represents a change in formatting. This change in formatting corresponds to separate run elements <r>
to separate the text with different formatting. Every word is expressed using a run element <r>
, which expresses the properties of the text <rPr>
and the text itself <t>
.
Since there are no properties associated with the first word "This", the text inherits the default formatting for the cell.
The rich text expression for the second string "string" contains a bold faced font element indicator <b>
in the run properties <rPr>
, therefore this text will have bold face applied. While other text formatting properties are expressed, they are the same as the cell formatting. This additional information is expressed for the sake of clarity and completeness of expression.
The rich text expression for the third string "has" contains a color element indicator <color>
in the run properties <rPr>
. Therefore, the color of the text associated with this set of run properties will be red, according to the color value expressed.
The formatting for the remaining words in this rich text string can be deduced in a similar manner, such that "a" has default formatting applied, "variety" is both italicized and green, "of" has default formatting applied, "formatting" is underlined, and "applied" has default formatting applied.