Skip to content

Commit 6d49a69

Browse files
committed
rfctr(table): reimplement CT_Tc._tr_above
Use XPath rather than oxml structures.
1 parent 5a1d614 commit 6d49a69

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/docx/oxml/table.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,10 @@ def _tr_above(self) -> CT_Row:
748748
749749
Raises |ValueError| if called on a cell in the top-most row.
750750
"""
751-
tr_lst = self._tbl.tr_lst
752-
tr_idx = tr_lst.index(self._tr)
753-
if tr_idx == 0:
754-
raise ValueError("no tr above topmost tr")
755-
return tr_lst[tr_idx - 1]
751+
tr_aboves = self.xpath("./ancestor::w:tr[position()=1]/preceding-sibling::w:tr[1]")
752+
if not tr_aboves:
753+
raise ValueError("no tr above topmost tr in w:tbl")
754+
return tr_aboves[0]
756755

757756
@property
758757
def _tr_below(self) -> CT_Row | None:

0 commit comments

Comments
 (0)