`w:tc` table cell element.
| 419 | |
| 420 | |
| 421 | class CT_Tc(BaseOxmlElement): |
| 422 | """`w:tc` table cell element.""" |
| 423 | |
| 424 | add_p: Callable[[], CT_P] |
| 425 | get_or_add_tcPr: Callable[[], CT_TcPr] |
| 426 | p_lst: list[CT_P] |
| 427 | tbl_lst: list[CT_Tbl] |
| 428 | _insert_tbl: Callable[[CT_Tbl], CT_Tbl] |
| 429 | _new_p: Callable[[], CT_P] |
| 430 | |
| 431 | # -- tcPr has many successors, `._insert_tcPr()` is overridden below -- |
| 432 | tcPr: CT_TcPr | None = ZeroOrOne("w:tcPr") # pyright: ignore[reportAssignmentType] |
| 433 | p = OneOrMore("w:p") |
| 434 | tbl = OneOrMore("w:tbl") |
| 435 | |
| 436 | @property |
| 437 | def bottom(self) -> int: |
| 438 | """The row index that marks the bottom extent of the vertical span of this cell. |
| 439 | |
| 440 | This is one greater than the index of the bottom-most row of the span, similar |
| 441 | to how a slice of the cell's rows would be specified. |
| 442 | """ |
| 443 | if self.vMerge is not None: |
| 444 | tc_below = self._tc_below |
| 445 | if tc_below is not None and tc_below.vMerge == ST_Merge.CONTINUE: |
| 446 | return tc_below.bottom |
| 447 | return self._tr_idx + 1 |
| 448 | |
| 449 | def clear_content(self): |
| 450 | """Remove all content elements, preserving `w:tcPr` element if present. |
| 451 | |
| 452 | Note that this leaves the `w:tc` element in an invalid state because it doesn't |
| 453 | contain at least one block-level element. It's up to the caller to add a |
| 454 | `w:p`child element as the last content element. |
| 455 | """ |
| 456 | # -- remove all cell inner-content except a `w:tcPr` when present. -- |
| 457 | for e in self.xpath("./*[not(self::w:tcPr)]"): |
| 458 | self.remove(e) |
| 459 | |
| 460 | @property |
| 461 | def grid_offset(self) -> int: |
| 462 | """Starting offset of `tc` in the layout-grid columns of its table. |
| 463 | |
| 464 | A cell in the leftmost grid-column has offset 0. |
| 465 | """ |
| 466 | grid_before = self._tr.grid_before |
| 467 | preceding_tc_grid_spans = sum( |
| 468 | tc.grid_span for tc in self.xpath("./preceding-sibling::w:tc") |
| 469 | ) |
| 470 | return grid_before + preceding_tc_grid_spans |
| 471 | |
| 472 | @property |
| 473 | def grid_span(self) -> int: |
| 474 | """The integer number of columns this cell spans. |
| 475 | |
| 476 | Determined by ./w:tcPr/w:gridSpan/@val, it defaults to 1. |
| 477 | """ |
| 478 | tcPr = self.tcPr |