-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError while acess cell._tc.bottom #1458
Comments
it's a bug in oxml/table.py, line 79, function tc_at_grid_offset(self, grid_offset: int) -> CT_Tc |
I also encountered this error |
fix tc_at_grid_offset implementation in file src/docx/oxml/table.py: def tc_at_grid_offset(self, grid_offset: int) -> CT_Tc:
"""The `tc` element in this tr at exact `grid offset`.
Raises ValueError when this `w:tr` contains no `w:tc` with exact starting `grid_offset`.
"""
# -- account for omitted cells at the start of the row --
if grid_offset < self.grid_before:
raise ValueError(f"no `tc` element at grid_offset={grid_offset}")
cell_dict = dict()
cell_index = 0
for tc in self.tc_lst:
for _ in range(tc.grid_span):
cell_dict[cell_index] = tc
cell_index += 1
if grid_offset not in cell_dict:
raise ValueError(f"no `tc` element at grid_offset={grid_offset}")
return cell_dict[grid_offset]
# remaining_offset = grid_offset - self.grid_before
# for tc in self.tc_lst:
# # -- We've gone past grid_offset without finding a tc, no sense searching further. --
# if remaining_offset < 0:
# break
# # -- We've arrived at grid_offset, this is the `w:tc` we're looking for. --
# if remaining_offset == 0:
# return tc
# # -- We're not there yet, skip forward the number of layout-grid cells this cell
# # -- occupies.
# remaining_offset -= tc.grid_span
# raise ValueError(f"no `tc` element at grid_offset={grid_offset}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OS: updated ubuntu 24.04
Python: 3.12.8
Python-Docx: 1.1.2
test.docx
while parsing table in docx, ValueError exception occurred:
ValueError: no
tc
element at grid_offset=3in line: bottom = cell._tc.bottom
code:
docx file: see test.docx in attachment
The text was updated successfully, but these errors were encountered: