docx_parser_converter.docx_parsers.tables.table_properties_parser module

class docx_parser_converter.docx_parsers.tables.table_properties_parser.TablePropertiesParser[source]

Bases: object

A parser for extracting table properties from an XML element.

static extract_border(border_element: Element | None) BorderProperties | None[source]

Extracts border properties from the given XML element.

Parameters:

border_element (Optional[etree.Element]) – The border XML element.

Returns:

The parsed border properties, or None if not found.

Return type:

Optional[BorderProperties]

Example

The following is an example of a border element:

<w:top w:val="single" w:sz="4" w:space="0" w:color="000000"/>
static extract_justification(element: Element) str | None[source]

Extracts table justification from the given XML element.

Parameters:

element (etree.Element) – The XML element.

Returns:

The justification, or None if not found.

Return type:

Optional[str]

Example

The following is an example of a table justification element:

<w:jc w:val="center"/>
static extract_margin_value(margin_element: Element, side: str) float | None[source]

Extracts a specific margin value from the given XML element.

Parameters:
  • margin_element (etree.Element) – The margin XML element.

  • side (str) – The side of the margin (e.g., “top”, “left”).

Returns:

The margin value in points, or None if not found.

Return type:

Optional[float]

static extract_shading(shd_element: Element | None) ShadingProperties | None[source]

Extracts shading properties from the given XML element.

Parameters:

shd_element (Optional[etree.Element]) – The shading XML element.

Returns:

The parsed shading properties, or None if not found.

Return type:

Optional[ShadingProperties]

Example

The following is an example of a shading element:

<w:shd w:val="clear" w:color="auto" w:fill="FFFF00"/>
static extract_table_cell_borders(borders_element: Element | None) TableCellBorders | None[source]

Extracts table cell border properties from the given XML element.

Parameters:

borders_element (Optional[etree.Element]) – The borders XML element.

Returns:

The parsed table cell border properties, or None if not found.

Return type:

Optional[TableCellBorders]

Example

The following is an example of table cell borders:

<w:tblBorders>
    <w:top w:val="single" w:sz="4" w:space="0" w:color="000000"/>
    <w:left w:val="single" w:sz="4" w:space="0" w:color="000000"/>
    <w:bottom w:val="single" w:sz="4" w:space="0" w:color="000000"/>
    <w:right w:val="single" w:sz="4" w:space="0" w:color="000000"/>
    <w:insideH w:val="single" w:sz="4" w:space="0" w:color="000000"/>
    <w:insideV w:val="single" w:sz="4" w:space="0" w:color="000000"/>
</w:tblBorders>
static extract_table_cell_margins(element: Element) MarginProperties | None[source]

Extracts table cell margins from the given XML element.

Parameters:

element (etree.Element) – The XML element.

Returns:

The parsed table cell margins, or None if not found.

Return type:

Optional[MarginProperties]

Example

The following is an example of table cell margins:

<w:tblCellMar>
    <w:top w:w="100" w:type="dxa"/>
    <w:left w:w="100" w:type="dxa"/>
    <w:bottom w:w="100" w:type="dxa"/>
    <w:right w:w="100" w:type="dxa"/>
</w:tblCellMar>
static extract_table_indent(element: Element) TableIndent | None[source]

Extracts table indent properties from the given XML element.

Parameters:

element (etree.Element) – The XML element.

Returns:

The parsed table indent properties, or None if not found.

Return type:

Optional[TableIndent]

Example

The following is an example of a table indent element:

<w:tblInd w:w="200" w:type="dxa"/>
static extract_table_layout(element: Element) str | None[source]

Extracts table layout from the given XML element.

Parameters:

element (etree.Element) – The XML element.

Returns:

The table layout, or None if not found.

Return type:

Optional[str]

Example

The following is an example of a table layout element:

<w:tblLayout w:type="fixed"/>
static extract_table_look(element: Element) TableLook | None[source]

Extracts table look properties from the given XML element.

Parameters:

element (etree.Element) – The XML element.

Returns:

The parsed table look properties, or None if not found.

Return type:

Optional[TableLook]

Example

The following is an example of a table look element:

<w:tblLook w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="0"/>
static extract_table_style(element: Element) str | None[source]

Extracts table style from the given XML element.

Parameters:

element (etree.Element) – The XML element.

Returns:

The table style, or None if not found.

Return type:

Optional[str]

Example

The following is an example of a table style element:

<w:tblStyle w:val="TableGrid"/>
static extract_table_width(element: Element) TableWidth | None[source]

Extracts table width properties from the given XML element.

Parameters:

element (etree.Element) – The XML element.

Returns:

The parsed table width properties, or None if not found.

Return type:

Optional[TableWidth]

Example

The following is an example of a table width element:

<w:tblW w:w="5000" w:type="dxa"/>
static parse(tblPr_element: Element) TableProperties[source]

Parses table properties from the given XML element.

Parameters:

tblPr_element (etree.Element) – The table properties XML element.

Returns:

The parsed table properties.

Return type:

TableProperties

Example

The following is an example of table properties in a table element:

<w:tblPr>
    <w:tblStyle w:val="TableGrid"/>
    <w:tblW w:w="5000" w:type="dxa"/>
    <w:tblInd w:w="200" w:type="dxa"/>
    <w:tblBorders>
        <w:top w:val="single" w:sz="4" w:space="0" w:color="000000"/>
        <w:left w:val="single" w:sz="4" w:space="0" w:color="000000"/>
        <w:bottom w:val="single" w:sz="4" w:space="0" w:color="000000"/>
        <w:right w:val="single" w:sz="4" w:space="0" w:color="000000"/>
        <w:insideH w:val="single" w:sz="4" w:space="0" w:color="000000"/>
        <w:insideV w:val="single" w:sz="4" w:space="0" w:color="000000"/>
    </w:tblBorders>
    <w:shd w:val="clear" w:color="auto" w:fill="FFFF00"/>
    <w:tblCellMar>
        <w:top w:w="100" w:type="dxa"/>
        <w:left w:w="100" w:type="dxa"/>
        <w:bottom w:w="100" w:type="dxa"/>
        <w:right w:w="100" w:type="dxa"/>
    </w:tblCellMar>
    <w:tblLook w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="0"/>
</w:tblPr>