目录
理解word中的样式:
什么是word中的样式:
当word中的元素有统一的格式时,文档变得更好处理。为了获得统一性,专业的文档设计人员设计了样式表单来定义文档元素类型,并且每个确定每个元素的格式。例如,正文段落格式被设置为Times Roman 9号字,行高11pt等。当这些格式被应用到文档的元素上时,就获得了一个一致且整洁的外观。
word中的一个样式是可以一次性应用到文档元素对象上的格式的集合。word 有段落样式、字体样式、表格样式、还有序号定义样式。这些分别被应用到一个段落、一段字体、一个表格、一个列表中。
样式的好处就是一次定义,多次使用。节省时间、精力,更重要的是,它允许通过通过更改定义来更改你应用改样式的所有地方。
为什么我的样式没有显示出来?
待更新
术语
样式定义:
文档中的style显式地定义了一个样式的属性:
<w:style>
定义样式:
在文档中显示地定义样式,和潜在样式相对,潜在样式不显式定义。
内置样式:
word中有276中预设样式,例如"Heading 1"。一个内置样式既可以是定义的也可以是潜在的。一个还没有定义的内置样式是潜在样式。定义的样式和潜在的样式都可能在Word的样式板中和样式库作为选项出现。
自定义样式:
也被看作用户自定义样式,任何在Word 文档中定义的样式都不是内置样式。自定义的样式不可能是潜在样式。
潜在样式:
在某个文档中没有定义的内置样式是在该文档中的潜在样式。潜在样式能否作为一选项出现在Word UI板取决于该文档中的LatentStyles对象。
推荐样式列表:
当在word中下拉框中选择"recommeded"时,在样式工具箱或者空间板上出现的一些列样式。如下图所示:
样式库(style gallery):
在Word UI的功能区中显示的示例样式的选择,可以通过单击其中一种来应用。
识别样式
一个样式有三个身份属性: name, style_id, type。
1. 每个name属性都是固定的,独一无二的标识符,可以用来获取该属性。
2. style_id 属性部用于将内容对象(如段落)键入其样式。但是,此值是由Word自动生成的,不能保证在保存过程中保持不变。通常,仅通过从本地化样式名称中删除空格来形成style-id ,但是也有例外。python-docx的用户
通常应该避免使用style_id,除非他们对所涉及的内部结构有信心。
3. type属性时创建时确定的,一旦确定无法更改。
内置样式
Word有近300个内置样式,例如Normal, Heading 1, List Bullet. 样式的定义在styles.xml文件中(是.docx解压缩后的一个文件)。但是内置样式定义是存储在Word软件中而非styles.xml文件中,只有当这些内置样式被使用后,才会被写入styles.xml文件。
内置样式只有在使用之后才写入.docx包中,这导致了对潜在样式定义的需求,如下所述。
样式的行为
除了收集一组格式设置属性外,样式还具有五个指定其行为的属性。此行为相对简单,基本上等于样式在Word或LibreOffice UI中出现的时间和位置。推荐样式表是理解样式行为的关键概念。在Word的样式窗格中,用户可以选择要查看的样式列表。其中之一被称为“推荐”,被称为“推荐列表”。这五个行为属性都会影响此列表和样式库中样式外观的某些方面。简而言之,如果样式的hidden
属性为False
(默认),则该样式会出现在推荐列表中。如果未隐藏样式,并且其 quick_style
属性为True
,则样式也会显示在样式库中。如果隐藏样式的unhide_when_used
属性是True
,则在首次使用时,其隐藏属性将置为False
。样式列表和样式库中的样式是按priority
顺序排序的,然后按字母顺序排列优先级相同的样式。如果样式的locked
属性为True,
并且为文档打开了格式限制,则该样式将不会出现在任何列表或样式库中,并且无法应用于内容。
潜在样式
需要指定内置样式的UI行为,但却没有在styles.xml 文件中定义,这引起了对潜在样式定义的需求。潜在样式定义基本上是存根样式定义,除了样式名称外,它最多还具有五个行为属性。通过为每个行为属性定义默认值,可以节省更多空间,因此仅需要定义与默认值不同的那些值,并且与所有默认值匹配的样式都不需要潜在样式的定义。
styles.xml 中的 w:latentStyles 和 w:lsdException 元素定义了潜在样式。
潜在样式定义仅对于内置样式是必需的,因为当styles.xml中没有样式定义时,只有内置样式可以显示在UI中。
样式继承
样式可以继承其他样式的属性,这与级联样式表(CSS)的工作原理有些相似。继承是使用base_style
属性指定的 。通过将一种样式基于另一种样式,可以形成任意深度的继承层次。没有base_style的样式将从文档默认值继承属性。
默认模板中的段落样式
- Normal
- Body Text
- Body Text 2
- Body Text 3
- Caption
- Heading 1
- Heading 2
- Heading 3
- Heading 4
- Heading 5
- Heading 6
- Heading 7
- Heading 8
- Heading 9
- Intense Quote
- List
- List 2
- List 3
- List Bullet
- List Bullet 2
- List Bullet 3
- List Continue
- List Continue 2
- List Continue 3
- List Number
- List Number 2
- List Number 3
- List Paragraph
- Macro Text
- No Spacing
- Quote
- Subtitle
- TOCHeading
- Title
默认模板中的字体样式
- Body Text Char
- Body Text 2 Char
- Body Text 3 Char
- Book Title
- Default Paragraph Font
- Emphasis
- Heading 1 Char
- Heading 2 Char
- Heading 3 Char
- Heading 4 Char
- Heading 5 Char
- Heading 6 Char
- Heading 7 Char
- Heading 8 Char
- Heading 9 Char
- Intense Emphasis
- Intense Quote Char
- Intense Reference
- Macro Text Char
- Quote Char
- Strong
- Subtitle Char
- Subtle Emphasis
- Subtle Reference
- Title Char
默认模板中的表格样式
- Table Normal
- Colorful Grid
- Colorful Grid Accent 1
- Colorful Grid Accent 2
- Colorful Grid Accent 3
- Colorful Grid Accent 4
- Colorful Grid Accent 5
- Colorful Grid Accent 6
- Colorful List
- Colorful List Accent 1
- Colorful List Accent 2
- Colorful List Accent 3
- Colorful List Accent 4
- Colorful List Accent 5
- Colorful List Accent 6
- Colorful Shading
- Colorful Shading Accent 1
- Colorful Shading Accent 2
- Colorful Shading Accent 3
- Colorful Shading Accent 4
- Colorful Shading Accent 5
- Colorful Shading Accent 6
- Dark List
- Dark List Accent 1
- Dark List Accent 2
- Dark List Accent 3
- Dark List Accent 4
- Dark List Accent 5
- Dark List Accent 6
- Light Grid
- Light Grid Accent 1
- Light Grid Accent 2
- Light Grid Accent 3
- Light Grid Accent 4
- Light Grid Accent 5
- Light Grid Accent 6
- Light List
- Light List Accent 1
- Light List Accent 2
- Light List Accent 3
- Light List Accent 4
- Light List Accent 5
- Light List Accent 6
- Light Shading
- Light Shading Accent 1
- Light Shading Accent 2
- Light Shading Accent 3
- Light Shading Accent 4
- Light Shading Accent 5
- Light Shading Accent 6
- Medium Grid 1
- Medium Grid 1 Accent 1
- Medium Grid 1 Accent 2
- Medium Grid 1 Accent 3
- Medium Grid 1 Accent 4
- Medium Grid 1 Accent 5
- Medium Grid 1 Accent 6
- Medium Grid 2
- Medium Grid 2 Accent 1
- Medium Grid 2 Accent 2
- Medium Grid 2 Accent 3
- Medium Grid 2 Accent 4
- Medium Grid 2 Accent 5
- Medium Grid 2 Accent 6
- Medium Grid 3
- Medium Grid 3 Accent 1
- Medium Grid 3 Accent 2
- Medium Grid 3 Accent 3
- Medium Grid 3 Accent 4
- Medium Grid 3 Accent 5
- Medium Grid 3 Accent 6
- Medium List 1
- Medium List 1 Accent 1
- Medium List 1 Accent 2
- Medium List 1 Accent 3
- Medium List 1 Accent 4
- Medium List 1 Accent 5
- Medium List 1 Accent 6
- Medium List 2
- Medium List 2 Accent 1
- Medium List 2 Accent 2
- Medium List 2 Accent 3
- Medium List 2 Accent 4
- Medium List 2 Accent 5
- Medium List 2 Accent 6
- Medium Shading 1
- Medium Shading 1 Accent 1
- Medium Shading 1 Accent 2
- Medium Shading 1 Accent 3
- Medium Shading 1 Accent 4
- Medium Shading 1 Accent 5
- Medium Shading 1 Accent 6
- Medium Shading 2
- Medium Shading 2 Accent 1
- Medium Shading 2 Accent 2
- Medium Shading 2 Accent 3
- Medium Shading 2 Accent 4
- Medium Shading 2 Accent 5
- Medium Shading 2 Accent 6
- Table Grid