|
| 1 | + |
| 2 | +Table Properties |
| 3 | +================ |
| 4 | + |
| 5 | + |
| 6 | +Autofit |
| 7 | +------- |
| 8 | + |
| 9 | +Word has two algorithms for laying out a table, *fixed-width* or *autofit*. |
| 10 | +The default is autofit. Word will adjust column widths in an autofit table |
| 11 | +based on cell contents. A fixed-width table retains its column widths |
| 12 | +regardless of the contents. Either algorithm will adjust column widths |
| 13 | +proportionately when total table width exceeds page width. |
| 14 | + |
| 15 | +The read/write :attr:`Table.allow_autofit` property specifies which algorithm |
| 16 | +is used:: |
| 17 | + |
| 18 | + >>> table = document.add_table(rows=2, cols=2) |
| 19 | + >>> table.allow_autofit |
| 20 | + True |
| 21 | + >>> table.allow_autofit = False |
| 22 | + >>> table.allow_autofit |
| 23 | + False |
| 24 | + |
| 25 | + |
| 26 | +Specimen XML |
| 27 | +------------ |
| 28 | + |
| 29 | +.. highlight:: xml |
| 30 | + |
| 31 | +The following XML is generated by Word when inserting a 2x2 table:: |
| 32 | + |
| 33 | + <w:tbl> |
| 34 | + <w:tblPr> |
| 35 | + <w:tblStyle w:val="TableGrid"/> |
| 36 | + <w:tblW w:type="auto" w:w="0"/> |
| 37 | + <w:tblLook w:firstColumn="1" w:firstRow="1" w:lastColumn="0" |
| 38 | + w:lastRow="0" w:noHBand="0" w:noVBand="1" w:val="04A0"/> |
| 39 | + </w:tblPr> |
| 40 | + <w:tblGrid> |
| 41 | + <w:gridCol w:w="4788"/> |
| 42 | + <w:gridCol w:w="4788"/> |
| 43 | + </w:tblGrid> |
| 44 | + <w:tr> |
| 45 | + <w:tc/> |
| 46 | + <w:tcPr> |
| 47 | + <w:tcW w:type="dxa" w:w="4788"/> |
| 48 | + </w:tcPr> |
| 49 | + <w:p/> |
| 50 | + </w:tc> |
| 51 | + <w:tc> |
| 52 | + <w:tcPr> |
| 53 | + <w:tcW w:type="dxa" w:w="4788"/> |
| 54 | + </w:tcPr> |
| 55 | + <w:p/> |
| 56 | + </w:tc> |
| 57 | + </w:tr> |
| 58 | + <w:tr> |
| 59 | + <w:tc> |
| 60 | + <w:tcPr> |
| 61 | + <w:tcW w:type="dxa" w:w="4788"/> |
| 62 | + </w:tcPr> |
| 63 | + <w:p/> |
| 64 | + </w:tc> |
| 65 | + <w:tc> |
| 66 | + <w:tcPr> |
| 67 | + <w:tcW w:type="dxa" w:w="4788"/> |
| 68 | + </w:tcPr> |
| 69 | + <w:p/> |
| 70 | + </w:tc> |
| 71 | + </w:tr> |
| 72 | + </w:tbl> |
| 73 | + |
| 74 | + |
| 75 | +Layout behavior |
| 76 | +--------------- |
| 77 | + |
| 78 | +Auto-layout causes actual column widths to be both unpredictable and |
| 79 | +unstable. Changes to the content can make the table layout shift. |
| 80 | + |
| 81 | + |
| 82 | +Semantics of CT_TblWidth element |
| 83 | +-------------------------------- |
| 84 | + |
| 85 | +e.g. ``tcW``:: |
| 86 | + |
| 87 | + <w:tcW w:w="42.4mm"/> |
| 88 | + |
| 89 | + <w:tcW w:w="1800" w:type="dxa"/> |
| 90 | + |
| 91 | + <w:tcW w:w="20%" w:type="pct"/> |
| 92 | + |
| 93 | + <w:tcW w:w="0" w:type="auto"/> |
| 94 | + |
| 95 | + <w:tcW w:type="nil"/> |
| 96 | + |
| 97 | + |
| 98 | + ST_MeasurementOrPercent |
| 99 | + | |
| 100 | + +-- ST_DecimalNumberOrPercent |
| 101 | + | | |
| 102 | + | +-- ST_UnqualifiedPercentage |
| 103 | + | | | |
| 104 | + | | +-- XsdInteger e.g. '1440' |
| 105 | + | | |
| 106 | + | +-- ST_Percentage e.g. '-07.43%' |
| 107 | + | |
| 108 | + +-- ST_UniversalMeasure e.g. '-04.34mm' |
| 109 | + |
| 110 | + |
| 111 | +Schema Definitions |
| 112 | +------------------ |
| 113 | + |
| 114 | +.. highlight:: xml |
| 115 | + |
| 116 | +:: |
| 117 | + |
| 118 | + <xsd:complexType name="CT_Tbl"> <!-- denormalized --> |
| 119 | + <xsd:sequence> |
| 120 | + <xsd:group ref="EG_RangeMarkupElements" minOccurs="0" maxOccurs="unbounded"/> |
| 121 | + <xsd:element name="tblPr" type="CT_TblPr"/> |
| 122 | + <xsd:element name="tblGrid" type="CT_TblGrid"/> |
| 123 | + <xsd:choice minOccurs="0" maxOccurs="unbounded"> |
| 124 | + <xsd:element name="tr" type="CT_Row"/> |
| 125 | + <xsd:element name="customXml" type="CT_CustomXmlRow"/> |
| 126 | + <xsd:element name="sdt" type="CT_SdtRow"/> |
| 127 | + <xsd:group ref="EG_RunLevelElts" minOccurs="0" maxOccurs="unbounded"/> |
| 128 | + </xsd:choice> |
| 129 | + </xsd:sequence> |
| 130 | + </xsd:complexType> |
| 131 | + |
| 132 | + <xsd:complexType name="CT_TblPr"> <!-- denormalized --> |
| 133 | + <xsd:sequence> |
| 134 | + <xsd:element name="tblStyle" type="CT_String" minOccurs="0"/> |
| 135 | + <xsd:element name="tblpPr" type="CT_TblPPr" minOccurs="0"/> |
| 136 | + <xsd:element name="tblOverlap" type="CT_TblOverlap" minOccurs="0"/> |
| 137 | + <xsd:element name="bidiVisual" type="CT_OnOff" minOccurs="0"/> |
| 138 | + <xsd:element name="tblStyleRowBandSize" type="CT_DecimalNumber" minOccurs="0"/> |
| 139 | + <xsd:element name="tblStyleColBandSize" type="CT_DecimalNumber" minOccurs="0"/> |
| 140 | + <xsd:element name="tblW" type="CT_TblWidth" minOccurs="0"/> |
| 141 | + <xsd:element name="jc" type="CT_JcTable" minOccurs="0"/> |
| 142 | + <xsd:element name="tblCellSpacing" type="CT_TblWidth" minOccurs="0"/> |
| 143 | + <xsd:element name="tblInd" type="CT_TblWidth" minOccurs="0"/> |
| 144 | + <xsd:element name="tblBorders" type="CT_TblBorders" minOccurs="0"/> |
| 145 | + <xsd:element name="shd" type="CT_Shd" minOccurs="0"/> |
| 146 | + <xsd:element name="tblLayout" type="CT_TblLayoutType" minOccurs="0"/> |
| 147 | + <xsd:element name="tblCellMar" type="CT_TblCellMar" minOccurs="0"/> |
| 148 | + <xsd:element name="tblLook" type="CT_TblLook" minOccurs="0"/> |
| 149 | + <xsd:element name="tblCaption" type="CT_String" minOccurs="0"/> |
| 150 | + <xsd:element name="tblDescription" type="CT_String" minOccurs="0"/> |
| 151 | + <xsd:element name="tblPrChange" type="CT_TblPrChange" minOccurs="0"/> |
| 152 | + </xsd:sequence> |
| 153 | + |
| 154 | + <!-- table width ------------------------------------- --> |
| 155 | + |
| 156 | + <xsd:complexType name="CT_TblWidth"> |
| 157 | + <xsd:attribute name="w" type="ST_MeasurementOrPercent"/> |
| 158 | + <xsd:attribute name="type" type="ST_TblWidth"/> |
| 159 | + </xsd:complexType> |
| 160 | + |
| 161 | + <xsd:simpleType name="ST_MeasurementOrPercent"> |
| 162 | + <xsd:union memberTypes="ST_DecimalNumberOrPercent s:ST_UniversalMeasure"/> |
| 163 | + </xsd:simpleType> |
| 164 | + |
| 165 | + <xsd:simpleType name="ST_DecimalNumberOrPercent"> |
| 166 | + <xsd:union memberTypes="ST_UnqualifiedPercentage s:ST_Percentage"/> |
| 167 | + </xsd:simpleType> |
| 168 | + |
| 169 | + <xsd:simpleType name="ST_UniversalMeasure"> |
| 170 | + <xsd:restriction base="xsd:string"> |
| 171 | + <xsd:pattern value="-?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)"/> |
| 172 | + </xsd:restriction> |
| 173 | + </xsd:simpleType> |
| 174 | + |
| 175 | + <xsd:simpleType name="ST_UnqualifiedPercentage"> |
| 176 | + <xsd:restriction base="xsd:integer"/> |
| 177 | + </xsd:simpleType> |
| 178 | + |
| 179 | + <xsd:simpleType name="ST_Percentage"> |
| 180 | + <xsd:restriction base="xsd:string"> |
| 181 | + <xsd:pattern value="-?[0-9]+(\.[0-9]+)?%"/> |
| 182 | + </xsd:restriction> |
| 183 | + </xsd:simpleType> |
| 184 | + |
| 185 | + <xsd:simpleType name="ST_TblWidth"> |
| 186 | + <xsd:restriction base="xsd:string"> |
| 187 | + <xsd:enumeration value="nil"/> |
| 188 | + <xsd:enumeration value="pct"/> |
| 189 | + <xsd:enumeration value="dxa"/> |
| 190 | + <xsd:enumeration value="auto"/> |
| 191 | + </xsd:restriction> |
| 192 | + </xsd:simpleType> |
| 193 | + |
| 194 | + <!-- table layout ------------------------------------ --> |
| 195 | + |
| 196 | + <xsd:complexType name="CT_TblLayoutType"> |
| 197 | + <xsd:attribute name="type" type="ST_TblLayoutType"/> |
| 198 | + </xsd:complexType> |
| 199 | + |
| 200 | + <xsd:simpleType name="ST_TblLayoutType"> |
| 201 | + <xsd:restriction base="xsd:string"> |
| 202 | + <xsd:enumeration value="fixed"/> |
| 203 | + <xsd:enumeration value="autofit"/> |
| 204 | + </xsd:restriction> |
| 205 | + </xsd:simpleType> |
| 206 | + |
| 207 | + <!-- table look -------------------------------------- --> |
| 208 | + |
| 209 | + <xsd:complexType name="CT_TblLook"> |
| 210 | + <xsd:attribute name="firstRow" type="s:ST_OnOff"/> |
| 211 | + <xsd:attribute name="lastRow" type="s:ST_OnOff"/> |
| 212 | + <xsd:attribute name="firstColumn" type="s:ST_OnOff"/> |
| 213 | + <xsd:attribute name="lastColumn" type="s:ST_OnOff"/> |
| 214 | + <xsd:attribute name="noHBand" type="s:ST_OnOff"/> |
| 215 | + <xsd:attribute name="noVBand" type="s:ST_OnOff"/> |
| 216 | + <xsd:attribute name="val" type="ST_ShortHexNumber"/> |
| 217 | + </xsd:complexType> |
0 commit comments