|
8 | 8 |
|
9 | 9 | from . import parse_xml |
10 | 10 | from .ns import nsdecls |
11 | | -from .simpletypes import ST_TwipsMeasure |
| 11 | +from .simpletypes import ST_TblLayoutType, ST_TwipsMeasure |
12 | 12 | from .xmlchemy import ( |
13 | 13 | BaseOxmlElement, OneAndOnlyOne, OneOrMore, OptionalAttribute, ZeroOrOne, |
14 | 14 | ZeroOrMore |
@@ -70,12 +70,40 @@ class CT_TblGridCol(BaseOxmlElement): |
70 | 70 | w = OptionalAttribute('w:w', ST_TwipsMeasure) |
71 | 71 |
|
72 | 72 |
|
| 73 | +class CT_TblLayoutType(BaseOxmlElement): |
| 74 | + """ |
| 75 | + ``<w:tblLayout>`` element, specifying whether column widths are fixed or |
| 76 | + can be automatically adjusted based on content. |
| 77 | + """ |
| 78 | + type = OptionalAttribute('w:type', ST_TblLayoutType) |
| 79 | + |
| 80 | + |
73 | 81 | class CT_TblPr(BaseOxmlElement): |
74 | 82 | """ |
75 | 83 | ``<w:tblPr>`` element, child of ``<w:tbl>``, holds child elements that |
76 | 84 | define table properties such as style and borders. |
77 | 85 | """ |
78 | | - tblStyle = ZeroOrOne('w:tblStyle') |
| 86 | + tblStyle = ZeroOrOne('w:tblStyle', successors=( |
| 87 | + 'w:tblpPr', 'w:tblOverlap', 'w:bidiVisual', 'w:tblStyleRowBandSize', |
| 88 | + 'w:tblStyleColBandSize', 'w:tblW', 'w:jc', 'w:tblCellSpacing', |
| 89 | + 'w:tblInd', 'w:tblBorders', 'w:shd', 'w:tblLayout', 'w:tblCellMar', |
| 90 | + 'w:tblLook', 'w:tblCaption', 'w:tblDescription', 'w:tblPrChange' |
| 91 | + )) |
| 92 | + tblLayout = ZeroOrOne('w:tblLayout', successors=( |
| 93 | + 'w:tblLayout', 'w:tblCellMar', 'w:tblLook', 'w:tblCaption', |
| 94 | + 'w:tblDescription', 'w:tblPrChange' |
| 95 | + )) |
| 96 | + |
| 97 | + @property |
| 98 | + def autofit(self): |
| 99 | + """ |
| 100 | + Return |False| if there is a ``<w:tblLayout>`` child with ``w:type`` |
| 101 | + attribute set to ``'fixed'``. Otherwise return |True|. |
| 102 | + """ |
| 103 | + tblLayout = self.tblLayout |
| 104 | + if tblLayout is None: |
| 105 | + return True |
| 106 | + return False if tblLayout.type == 'fixed' else True |
79 | 107 |
|
80 | 108 | @property |
81 | 109 | def style(self): |
|
0 commit comments