A 2D block of `a:tc` cell elements in a table. This object assumes the structure of the underlying table does not change during its lifetime. Structural changes in this context would be insertion or removal of rows or columns. The client is expected to create, use, and then abandon an
| 447 | |
| 448 | |
| 449 | class TcRange(object): |
| 450 | """A 2D block of `a:tc` cell elements in a table. |
| 451 | |
| 452 | This object assumes the structure of the underlying table does not change during its lifetime. |
| 453 | Structural changes in this context would be insertion or removal of rows or columns. |
| 454 | |
| 455 | The client is expected to create, use, and then abandon an instance in the context of a single |
| 456 | user operation that is known to have no structural side-effects of this type. |
| 457 | """ |
| 458 | |
| 459 | def __init__(self, tc: CT_TableCell, other_tc: CT_TableCell): |
| 460 | self._tc = tc |
| 461 | self._other_tc = other_tc |
| 462 | |
| 463 | @classmethod |
| 464 | def from_merge_origin(cls, tc: CT_TableCell): |
| 465 | """Return instance created from merge-origin tc element.""" |
| 466 | other_tc = tc.tbl.tc( |
| 467 | tc.row_idx + tc.rowSpan - 1, # ---other_row_idx |
| 468 | tc.col_idx + tc.gridSpan - 1, # ---other_col_idx |
| 469 | ) |
| 470 | return cls(tc, other_tc) |
| 471 | |
| 472 | @lazyproperty |
| 473 | def contains_merged_cell(self) -> bool: |
| 474 | """True if one or more cells in range are part of a merged cell.""" |
| 475 | for tc in self.iter_tcs(): |
| 476 | if tc.gridSpan > 1: |
| 477 | return True |
| 478 | if tc.rowSpan > 1: |
| 479 | return True |
| 480 | if tc.hMerge: |
| 481 | return True |
| 482 | if tc.vMerge: |
| 483 | return True |
| 484 | return False |
| 485 | |
| 486 | @lazyproperty |
| 487 | def dimensions(self) -> tuple[int, int]: |
| 488 | """(row_count, col_count) pair describing size of range.""" |
| 489 | _, _, width, height = self._extents |
| 490 | return height, width |
| 491 | |
| 492 | @lazyproperty |
| 493 | def in_same_table(self): |
| 494 | """True if both cells provided to constructor are in same table.""" |
| 495 | if self._tc.tbl is self._other_tc.tbl: |
| 496 | return True |
| 497 | return False |
| 498 | |
| 499 | def iter_except_left_col_tcs(self): |
| 500 | """Generate each `a:tc` element not in leftmost column of range.""" |
| 501 | for tr in self._tbl.tr_lst[self._top : self._bottom]: |
| 502 | for tc in tr.tc_lst[self._left + 1 : self._right]: |
| 503 | yield tc |
| 504 | |
| 505 | def iter_except_top_row_tcs(self): |
| 506 | """Generate each `a:tc` element in non-first rows of range.""" |
no outgoing calls
searching dependent graphs…