Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/docx/oxml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
CT_TblGrid,
CT_TblGridCol,
CT_TblLayoutType,
CT_TblLook,
CT_TblPr,
CT_TblPrEx,
CT_TblWidth,
Expand All @@ -173,6 +174,7 @@
register_element_cls("w:tbl", CT_Tbl)
register_element_cls("w:tblGrid", CT_TblGrid)
register_element_cls("w:tblLayout", CT_TblLayoutType)
register_element_cls("w:tblLook", CT_TblLook)
register_element_cls("w:tblPr", CT_TblPr)
register_element_cls("w:tblPrEx", CT_TblPrEx)
register_element_cls("w:tblStyle", CT_String)
Expand Down
18 changes: 18 additions & 0 deletions src/docx/oxml/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ def _tcs_xml(cls, col_count: int, col_width: Length) -> str:
) * col_count


class CT_TblLook(BaseOxmlElement):
"""`w:tblLook` element, child of `w:tblPr`.

Specifies visual formatting of the table
"""

noHBand: int | None = OptionalAttribute( # pyright: ignore[reportAssignmentType]
"w:noHBand", XsdInt, default=1
)
noVBand: int | None = OptionalAttribute( # pyright: ignore[reportAssignmentType]
"w:noVBand", XsdInt, default=1
)


class CT_TblGrid(BaseOxmlElement):
"""`w:tblGrid` element.

Expand Down Expand Up @@ -301,6 +315,7 @@ class CT_TblPr(BaseOxmlElement):
get_or_add_bidiVisual: Callable[[], CT_OnOff]
get_or_add_jc: Callable[[], CT_Jc]
get_or_add_tblLayout: Callable[[], CT_TblLayoutType]
get_or_add_tblLook: Callable[[], CT_TblLook]
_add_tblStyle: Callable[[], CT_String]
_remove_bidiVisual: Callable[[], None]
_remove_jc: Callable[[], None]
Expand Down Expand Up @@ -338,6 +353,9 @@ class CT_TblPr(BaseOxmlElement):
tblLayout: CT_TblLayoutType | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
"w:tblLayout", successors=_tag_seq[13:]
)
tblLook: CT_TblLook | None = ZeroOrOne(
"w:tblLook", successors=_tag_seq[15:]) # pyright: ignore[reportAssignmentType]

del _tag_seq

@property
Expand Down
28 changes: 28 additions & 0 deletions src/docx/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ def autofit(self) -> bool:
def autofit(self, value: bool):
self._tblPr.autofit = value

@property
def banded_columns(self) -> bool:
"""|True| if banded columns formatting is applied to this table.

|False| if banded columns formatting is not applied. Read/write boolean.
"""
tblLook = self._tblPr.tblLook
return not tblLook.noVBand if tblLook is not None else False

@banded_columns.setter
def banded_columns(self, value: bool):
tblLook = self._tblPr.get_or_add_tblLook()
tblLook.noVBand = int(not value)

@property
def banded_rows(self) -> bool:
"""|True| if banded rows formatting is applied to this table.

|False| if banded rows formatting is not applied. Read/write boolean.
"""
tblLook = self._tblPr.tblLook
return not tblLook.noHBand if tblLook is not None else False

@banded_rows.setter
def banded_rows(self, value: bool):
tblLook = self._tblPr.get_or_add_tblLook()
tblLook.noHBand = int(not value)

def cell(self, row_idx: int, col_idx: int) -> _Cell:
"""|_Cell| at `row_idx`, `col_idx` intersection.

Expand Down