@@ -82,20 +82,36 @@ def tc_at_grid_offset(self, grid_offset: int) -> CT_Tc:
82
82
Raises ValueError when this `w:tr` contains no `w:tc` with exact starting `grid_offset`.
83
83
"""
84
84
# -- account for omitted cells at the start of the row --
85
- remaining_offset = grid_offset - self .grid_before
86
-
85
+
86
+ if grid_offset < self .grid_before :
87
+ raise ValueError (f"no `tc` element at grid_offset={ grid_offset } " )
88
+
89
+ cell_dict = dict ()
90
+ cell_index = 0
87
91
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 } " )
92
+ for _ in range (tc .grid_span ):
93
+ cell_dict [cell_index ] = tc
94
+ cell_index += 1
95
+
96
+ if grid_offset not in cell_dict :
97
+ raise ValueError (f"no `tc` element at grid_offset={ grid_offset } " )
98
+
99
+ return cell_dict [grid_offset ]
100
+
101
+ # remaining_offset = grid_offset - self.grid_before
102
+
103
+ # for tc in self.tc_lst:
104
+ # # -- We've gone past grid_offset without finding a tc, no sense searching further. --
105
+ # if remaining_offset < 0:
106
+ # break
107
+ # # -- We've arrived at grid_offset, this is the `w:tc` we're looking for. --
108
+ # if remaining_offset == 0:
109
+ # return tc
110
+ # # -- We're not there yet, skip forward the number of layout-grid cells this cell
111
+ # # -- occupies.
112
+ # remaining_offset -= tc.grid_span
113
+
114
+ # raise ValueError(f"no `tc` element at grid_offset={grid_offset}")
99
115
100
116
@property
101
117
def tr_idx (self ) -> int :
0 commit comments