Styles ====== .. toctree:: :titlesonly: styles style paragraph-style character-style latent-styles Word supports the definition of `styles` to allow a group of formatting properties to be easily and consistently applied to a paragraph, run, table, or numbering scheme, all at once. The mechanism is similar to how Cascading Style Sheets (CSS) works with HTML. Styles are defined in the ``styles.xml`` package part and are keyed to a paragraph, run, or table using the `styleId` string. Style visual behavior --------------------- * **Sort order.** Built-in styles appear in order of the effective value of their `uiPriority` attribute. By default, a custom style will not receive a `uiPriority` attribute, causing its effective value to default to 0. This will generlly place custom styles at the top of the sort order. A set of styles having the same `uiPriority` value will be sub-sorted in alphabetical order. If a `uiPriority` attribute is defined for a custom style, that style is interleaved with the built-in styles, according to their `uiPriority` value. The `uiPriority` attribute takes a signed integer, and accepts negative numbers. Note that Word does not allow the use of negative integers via its UI; rather it allows the `uiPriority` number of built-in types to be increased to produce the desired sorting behavior. * **Identification.** A style is identified by its name, not its styleId attribute. The styleId is used only for internal linking of an object like a paragraph to a style. The styleId may be changed by the application, and in fact is routinely changed by Word on each save to be a transformation of the name. *Hypothesis.* Word calculates the `styleId` by removing all spaces from the style name. * **List membership.** There are four style list options in the styles panel: + *Recommended.* The recommended list contains all latent and defined styles that have `semiHidden` == |False|. + *Styles in Use.* The styles-in-use list contains all styles that have been applied to content in the document (implying they are defined) that also have `semiHidden` == |False|. + *In Current Document.* The in-current-document list contains all defined styles in the document having `semiHidden` == |False|. + *All Styles.* The all-styles list contains all latent and defined styles in the document. * **Definition of built-in style.** When a built-in style is added to a document (upon first use), the value of each of the `locked`, `uiPriority` and `qFormat` attributes from its latent style definition (the `latentStyles` attributes overridden by those of any `lsdException` element) is used to override the corresponding value in the inserted style definition from their built-in defaults. * Each built-in style has default attributes that can be revealed by setting the `latentStyles/@count` attribute to 0 and inspecting the style in the style manager. This may include default behavioral properties. * Anomaly. Style "No Spacing" does not appear in the recommended list even though its behavioral attributes indicate it should. (Google indicates it may be a legacy style from Word 2003). * Word has 267 built-in styles, listed here: http://www.thedoctools.com/downloads/DocTools_List_Of_Built-in_Style_English_Danish_German_French.pdf Note that at least one other sources has the number at 276 rather than 267. * **Appearance in the Style Gallery.** A style appears in the style gallery when: `semiHidden` == |False| and `qFormat` == |True| Glossary -------- built-in style One of a set of standard styles known to Word, such as "Heading 1". Built-in styles are presented in Word's style panel whether or not they are actually defined in the styles part. latent style A built-in style having no definition in a particular document is known as a *latent style* in that document. style definition A ```` element in the styles part that explicitly defines the attributes of a style. recommended style list A list of styles that appears in the styles toolbox or panel when "Recommended" is selected from the "List:" dropdown box. Word behavior ------------- If no style having an assigned style id is defined in the styles part, the style application has no effect. Word does not add a formatting definition (```` element) for a built-in style until it is used. Once present in the styles part, Word does not remove a built-in style definition if it is no longer applied to any content. The definition of each of the styles ever used in a document are accumulated in its ``styles.xml``. Related MS API *(partial)* -------------------------- * Document.Styles * Styles.Add, .Item, .Count, access by name, e.g. Styles("Foobar") * Style.BaseStyle * Style.Builtin * Style.Delete() * Style.Description * Style.Font * Style.Linked * Style.LinkStyle * Style.LinkToListTemplate() * Style.ListLevelNumber * Style.ListTemplate * Style.Locked * Style.NameLocal * Style.NameParagraphStyle * Style.NoSpaceBetweenParagraphsOfSameStyle * Style.ParagraphFormat * Style.Priority * Style.QuickStyle * Style.Shading * Style.Table(Style) * Style.Type * Style.UnhideWhenUsed * Style.Visibility Enumerations ------------ * WdBuiltinStyle Example XML ----------- .. highlight:: xml :: Schema excerpt -------------- ::