`` `` element.
| 47 | |
| 48 | |
| 49 | class CT_Row(BaseOxmlElement): |
| 50 | """``<w:tr>`` element.""" |
| 51 | |
| 52 | add_tc: Callable[[], CT_Tc] |
| 53 | get_or_add_trPr: Callable[[], CT_TrPr] |
| 54 | _add_trPr: Callable[[], CT_TrPr] |
| 55 | |
| 56 | tc_lst: list[CT_Tc] |
| 57 | # -- custom inserter below -- |
| 58 | tblPrEx: CT_TblPrEx | None = ZeroOrOne("w:tblPrEx") # pyright: ignore[reportAssignmentType] |
| 59 | # -- custom inserter below -- |
| 60 | trPr: CT_TrPr | None = ZeroOrOne("w:trPr") # pyright: ignore[reportAssignmentType] |
| 61 | tc = ZeroOrMore("w:tc") |
| 62 | |
| 63 | @property |
| 64 | def grid_after(self) -> int: |
| 65 | """The number of unpopulated layout-grid cells at the end of this row.""" |
| 66 | trPr = self.trPr |
| 67 | if trPr is None: |
| 68 | return 0 |
| 69 | return trPr.grid_after |
| 70 | |
| 71 | @property |
| 72 | def grid_before(self) -> int: |
| 73 | """The number of unpopulated layout-grid cells at the start of this row.""" |
| 74 | trPr = self.trPr |
| 75 | if trPr is None: |
| 76 | return 0 |
| 77 | return trPr.grid_before |
| 78 | |
| 79 | def tc_at_grid_offset(self, grid_offset: int) -> CT_Tc: |
| 80 | """The `tc` element in this tr at exact `grid offset`. |
| 81 | |
| 82 | Raises ValueError when this `w:tr` contains no `w:tc` with exact starting `grid_offset`. |
| 83 | """ |
| 84 | # -- account for omitted cells at the start of the row -- |
| 85 | remaining_offset = grid_offset - self.grid_before |
| 86 | |
| 87 | for tc in self.tc_lst: |
| 88 | # -- We've gone past grid_offset without finding a tc, no sense searching further. -- |
| 89 | if remaining_offset < 0: |
| 90 | break |
| 91 | # -- We've arrived at grid_offset, this is the `w:tc` we're looking for. -- |
| 92 | if remaining_offset == 0: |
| 93 | return tc |
| 94 | # -- We're not there yet, skip forward the number of layout-grid cells this cell |
| 95 | # -- occupies. |
| 96 | remaining_offset -= tc.grid_span |
| 97 | |
| 98 | raise ValueError(f"no `tc` element at grid_offset={grid_offset}") |
| 99 | |
| 100 | @property |
| 101 | def tr_idx(self) -> int: |
| 102 | """Index of this `w:tr` element within its parent `w:tbl` element.""" |
| 103 | tbl = cast(CT_Tbl, self.getparent()) |
| 104 | return tbl.tr_lst.index(self) |
| 105 | |
| 106 | @property |
nothing calls this directly
no test coverage detected
searching dependent graphs…