制表位

WordprocessingML允许在段落级别自定义制表位。制表位间距是本系统中段落格式的一个子集,因此将在docx.text.parfmt文件.ParagraphFormatting对象。制表位将作为一个由TabStop对象组成的类似TabStops对象的列表来处理。

TabStop对象有三个属性:对齐、引线和位置。Alignment是WD_TAB_对齐成员,position是Length()对象。

制表位总是按位置顺序排序。对齐默认为WD U TAB_左对齐,且“引线”默认为“WD”选项卡_领导空间.

制表位指定段落中制表符的呈现方式。制表符的插入是使用Run对象完成的。

协议

获取和设置制表位:

>>> tab_stops = paragraph.paragraph_format.tab_stops
>>> tab_stops
<docx.text.parfmt.TabStops object at 0x104ea8c30>

>>> tab_stop = tab_stops.add_tab_stop(Inches(2), WD_TAB_ALIGNMENT.LEFT, WD_TAB_LEADER.DOTS)

# add_tab_stop defaults to WD_TAB_ALIGNMENT.LEFT, WD_TAB_LEADER.SPACES

>>> tab_stop = tab_stops.add_tab_stop(Inches(0.5))
>>> tab_stop.alignment
WD_TAB_ALIGNMENT.LEFT
>>> tab_stop.leader
WD_TAB_LEADER.SPACES

# TabStop properties are read/write

>>> tab_stop.position = Inches(2.5)
>>> tab_stop.alignment = WD_TAB_ALIGNMENT.CENTER
>>> tab_stop.leader = WD_TAB_LEADER.DASHES

# Tab stops are sorted into position order as created or modified

>>> [(t.position, t.alignment) for t in tab_stops]
[(914400, WD_TAB_ALIGNMENT.LEFT), (2286000, WD_TAB_ALIGNMENT.CENTER)]

# A tab stop is deleted using del statement

>>> len(tab_stops)
2
>>> del tab_stops[1]
>>> len(tab_stops)
1

# Restore default tabs

>>> tab_stops.clear()

言语行为

当w:tabs元素为空或不存在时,Word使用默认制表位(通常每半英寸一次)。

Word在最后指定的制表位之后使用默认制表位继续。

制表符必须在XML中按位置顺序排列。如果没有,无序的制表位将出现在标尺和属性对话框中,但不会被Word实际使用。

XML语义

  • “num”和“list”对齐方式都是Word早期版本在悬垂缩进可用之前遗留下来的。两个都不推荐使用。

  • “开始”对齐相当于“左”,“结束”对齐相当于“右”。(通过手动编辑的XML确认。)

  • Word的选项卡栏中不显示“清除”制表位,文档中遵循默认的制表符行为。也就是说,Word完全忽略了tab stop规范,就好像它根本不存在一样。例如,这允许忽略从样式继承的制表位。

  • w:pos属性使用twips而不是EMU。

  • w:tabs元素为空时必须删除。如果存在,它必须至少包含一个w:tab元素。

XML样本

<w:pPr>
  <w:tabs>
    <w:tab w:val="left" w:leader="dot" w:pos="2880"/>
    <w:tab w:val="decimal" w:pos="6480"/>
  </w:tabs>
</w:pPr>

枚举

名字

XML

价值

wdAlignTabBar

酒吧

4

wdAlignTabCenter

中心

1

wdAlignTabDecimal

十进制的

3

wdAlignTabLeft

左边

0

WDAlignTableList

列表

6

wdAlignTabRight

正确的

2

未出现在WdTabAlignment中的其他枚举值

名字

XML

价值

wdAlignTabClear

清楚的

101

wdAlignTabEnd

结束

102

WDALIGNTAB编号

号码

103

wdAlignTabStart

开始

104

名字

XML

价值

WDTableReaderDash

连字符

2

WDTableReaderDots

1

WDTableReaderHeavy

重的

4

WDTableReaderLines

强调

3

wdTabLeaderMiddleDot

米德尔多特

5

WDTableReaderSpaces

没有人

0

MS API协议

MS API定义了 TabStops object 这是一个集合 TabStop objects .

架构摘要

<xsd:complexType name="CT_PPr">  <!-- denormalized -->
  <xsd:sequence>
    <xsd:element name="pStyle"              type="CT_String"           minOccurs="0"/>
    <xsd:element name="keepNext"            type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="keepLines"           type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="pageBreakBefore"     type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="framePr"             type="CT_FramePr"          minOccurs="0"/>
    <xsd:element name="widowControl"        type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="numPr"               type="CT_NumPr"            minOccurs="0"/>
    <xsd:element name="suppressLineNumbers" type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="pBdr"                type="CT_PBdr"             minOccurs="0"/>
    <xsd:element name="shd"                 type="CT_Shd"              minOccurs="0"/>
    <xsd:element name="tabs"                type="CT_Tabs"             minOccurs="0"/>
    <xsd:element name="suppressAutoHyphens" type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="kinsoku"             type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="wordWrap"            type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="overflowPunct"       type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="topLinePunct"        type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="autoSpaceDE"         type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="autoSpaceDN"         type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="bidi"                type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="adjustRightInd"      type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="snapToGrid"          type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="spacing"             type="CT_Spacing"          minOccurs="0"/>
    <xsd:element name="ind"                 type="CT_Ind"              minOccurs="0"/>
    <xsd:element name="contextualSpacing"   type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="mirrorIndents"       type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="suppressOverlap"     type="CT_OnOff"            minOccurs="0"/>
    <xsd:element name="jc"                  type="CT_Jc"               minOccurs="0"/>
    <xsd:element name="textDirection"       type="CT_TextDirection"    minOccurs="0"/>
    <xsd:element name="textAlignment"       type="CT_TextAlignment"    minOccurs="0"/>
    <xsd:element name="textboxTightWrap"    type="CT_TextboxTightWrap" minOccurs="0"/>
    <xsd:element name="outlineLvl"          type="CT_DecimalNumber"    minOccurs="0"/>
    <xsd:element name="divId"               type="CT_DecimalNumber"    minOccurs="0"/>
    <xsd:element name="cnfStyle"            type="CT_Cnf"              minOccurs="0"/>
    <xsd:element name="rPr"                 type="CT_ParaRPr"          minOccurs="0"/>
    <xsd:element name="sectPr"              type="CT_SectPr"           minOccurs="0"/>
    <xsd:element name="pPrChange"           type="CT_PPrChange"        minOccurs="0"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="CT_Tabs">
  <xsd:sequence>
    <xsd:element name="tab" type="CT_TabStop" maxOccurs="unbounded"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="CT_TabStop">
  <xsd:attribute name="val"    type="ST_TabJc"              use="required"/>
  <xsd:attribute name="leader" type="ST_TabTlc"             use="optional"/>
  <xsd:attribute name="pos"    type="ST_SignedTwipsMeasure" use="required"/>
</xsd:complexType>

<xsd:simpleType name="ST_TabJc">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="clear"/>
    <xsd:enumeration value="start"/>
    <xsd:enumeration value="center"/>
    <xsd:enumeration value="end"/>
    <xsd:enumeration value="decimal"/>
    <xsd:enumeration value="bar"/>
    <xsd:enumeration value="num"/>
    <xsd:enumeration value="left"/>
    <xsd:enumeration value="right"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="ST_TabTlc">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="none"/>
    <xsd:enumeration value="dot"/>
    <xsd:enumeration value="hyphen"/>
    <xsd:enumeration value="underscore"/>
    <xsd:enumeration value="heavy"/>
    <xsd:enumeration value="middleDot"/>
  </xsd:restriction>
</xsd:simpleType>