潜在风格

潜在样式定义是一个“存根”样式定义,指定内置样式的行为(UI显示)属性。

潜在风格系列

使用访问文档的潜在样式集合 latent_styles 属性对 Styles ::

>>> latent_styles = document.styles.latent_styles
>>> latent_styles
<docx.styles.LatentStyles object at 0x1045dd550>

Iteration. LatentStyles should support iteration of contained _LatentStyle objects in document order.

潜在风格访问。 可以使用字典样式表示法按名称访问潜在样式。

len(). LatentStyles supports len(), reporting the number of _LatentStyle objects it contains.

LatentStyles 性质

default_priority

XML语义 . 根据ISO 29500,如果 w:defUIPriority 省略的属性是99。99是在默认单词中明确设置的 styles.xml ,人们通常会发现。

协议 ::

>>> # return None if attribute is omitted
>>> latent_styles.default_priority
None
>>> # but expect is will almost always be explicitly 99
>>> latent_styles.default_priority
99
>>> latent_styles.default_priority = 42
>>> latent_styles.default_priority
42

load_count

XML语义 . 规范中没有说明默认值。不允许分配 None .

协议 ::

>>> latent_styles.load_count
276
>>> latent_styles.load_count = 242
>>> latent_styles.load_count
242

布尔属性

有四个布尔属性都共享相同的协议:

  • default_to_hidden

  • default_to_locked

  • default_to_quick_style

  • default_to_unhide_when_used

XML语义 .默认为 False 如果属性被省略。但是,属性应该总是在更新时显式写入。

协议 ::

>>> latent_styles.default_to_hidden
False
>>> latent_styles.default_to_hidden = True
>>> latent_styles.default_to_hidden
True

XML样本

这个 w:latentStyles 默认Word 2011模板中使用的元素::

<w:latentStyles w:defLockedState="0" w:defUIPriority="99" w:defSemiHidden="1"
                w:defUnhideWhenUsed="1" w:defQFormat="0" w:count="276">

_LatentStyle 性质

>>> latent_style = latent_styles.latent_styles[0]

>>> latent_style.name
'Normal'

>>> latent_style.priority
None
>>> latent_style.priority = 10
>>> latent_style.priority
10

>>> latent_style.locked
None
>>> latent_style.locked = True
>>> latent_style.locked
True

>>> latent_style.quick_style
None
>>> latent_style.quick_style = True
>>> latent_style.quick_style
True

潜在风格行为

  • 样式具有两类属性, behavioralformatting 。行为属性指定样式应出现在用户界面中的位置和时间。属性为潜在样式指定行为属性。 <w:latentStyles> 元素和它的 <w:lsdException> 子元素。这5个行为属性是:

    • 锁定的

    • uiPriority优先级

    • 半隐藏的

    • 心不在焉

    • Q格式

  • 锁定的 . 这个 locked 属性指定样式不应出现在任何列表或库中,并且不能应用于内容。此行为仅在启用“限制格式”时处于活动状态。

    通过以下菜单打开锁定:开发人员选项卡>保护文档>格式限制(仅限Windows)。

  • uiPriority优先级 . 这个 uiPriority 属性充当排序键,用于在用户界面中排序样式名称。“样式”面板和样式库中的列表都对此设置敏感。如果未指定,则其有效值为0。

  • semiHidden 。这个 semiHidden 属性会使该样式从推荐列表中排除。这一概念 semi 在这种情况下,虽然该样式在推荐列表中隐藏,但它仍显示在“所有样式”列表中。如果在第一次应用样式时删除此属性 unhideWhenUsed 属性集 True 也是存在的。

  • unhideWhenUsed 。这个 unhideWhenUsed 属性会导致任何 semiHidden 首次将样式应用于内容时要移除的属性。Word做到了 not 移除 semiHidden 属性,因为文档中存在具有该样式的对象。这个 unhideWhenUsed 属性不会与 semiHidden 在应用该样式时使用。

    这个 semiHiddenunhideWhenUsed 属性组合起来产生 hide-until-used 行为。

    假设。 持续的 unhideWhenUsed 属性 semiHidden 在样式的第一个应用程序上的属性对于在样式继承情况下生成适当的行为是必需的。在这种情况下 semiHidden 属性可以明确设置为 False 重写继承的值。或者允许 semiHidden 要重新设置为的属性 True 稍后,同时保留hide-until-used行为。

  • Q格式 . 这个 qFormat 属性指定样式出现在推荐列表中时是否应显示在样式库中。样式将永远不会出现在库中,除非它也出现在推荐列表中。

  • 潜在样式属性仅对潜在样式有效。一旦定义了样式,定义的属性将专门决定样式行为;不会从其相应的潜在样式定义继承任何属性。

XML样本

<w:latentStyles w:defLockedState="0" w:defUIPriority="99" w:defSemiHidden="1"
                w:defUnhideWhenUsed="1" w:defQFormat="0" w:count="276">
  <w:lsdException w:name="Normal" w:semiHidden="0" w:uiPriority="0"
                  w:unhideWhenUsed="0" w:qFormat="1"/>
  <w:lsdException w:name="heading 1" w:semiHidden="0" w:uiPriority="9"
                  w:unhideWhenUsed="0" w:qFormat="1"/>
  <w:lsdException w:name="caption" w:uiPriority="35" w:qFormat="1"/>
  <w:lsdException w:name="Default Paragraph Font" w:uiPriority="1"/>
  <w:lsdException w:name="Bibliography" w:uiPriority="37"/>
  <w:lsdException w:name="TOC Heading" w:uiPriority="39" w:qFormat="1"/>
</w:latentStyles>

架构摘要

<xsd:complexType name="CT_Styles">
  <xsd:sequence>
    <xsd:element name="docDefaults"  type="CT_DocDefaults"  minOccurs="0"/>
    <xsd:element name="latentStyles" type="CT_LatentStyles" minOccurs="0"/>
    <xsd:element name="style"        type="CT_Style"        minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="CT_LatentStyles">
  <xsd:sequence>
    <xsd:element name="lsdException" type="CT_LsdException" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
  <xsd:attribute name="defLockedState"    type="s:ST_OnOff"/>
  <xsd:attribute name="defUIPriority"     type="ST_DecimalNumber"/>
  <xsd:attribute name="defSemiHidden"     type="s:ST_OnOff"/>
  <xsd:attribute name="defUnhideWhenUsed" type="s:ST_OnOff"/>
  <xsd:attribute name="defQFormat"        type="s:ST_OnOff"/>
  <xsd:attribute name="count"             type="ST_DecimalNumber"/>
</xsd:complexType>

<xsd:complexType name="CT_LsdException">
  <xsd:attribute name="name"           type="s:ST_String"   use="required"/>
  <xsd:attribute name="locked"         type="s:ST_OnOff"/>
  <xsd:attribute name="uiPriority"     type="ST_DecimalNumber"/>
  <xsd:attribute name="semiHidden"     type="s:ST_OnOff"/>
  <xsd:attribute name="unhideWhenUsed" type="s:ST_OnOff"/>
  <xsd:attribute name="qFormat"        type="s:ST_OnOff"/>
</xsd:complexType>

<xsd:complexType name="CT_OnOff">
  <xsd:attribute name="val" type="s:ST_OnOff"/>
</xsd:complexType>

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

<xsd:simpleType name="ST_OnOff">
  <xsd:union memberTypes="xsd:boolean ST_OnOff1"/>
</xsd:simpleType>

<xsd:simpleType name="ST_OnOff1">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="on"/>
    <xsd:enumeration value="off"/>
  </xsd:restriction>
</xsd:simpleType>