MCPcopy Index your code
hub / github.com/python-openxml/python-docx / _swallow_next_tc

Method _swallow_next_tc

src/docx/oxml/table.py:708–731  ·  view source on GitHub ↗

Extend the horizontal span of this `w:tc` element to incorporate the following `w:tc` element in the row and then delete that following `w:tc` element. Any content in the following `w:tc` element is appended to the content of `top_tc`. The width of the following `w:t

(self, grid_width: int, top_tc: CT_Tc)

Source from the content-addressed store, hash-verified

706 self.vMerge = vMerge
707
708 def _swallow_next_tc(self, grid_width: int, top_tc: CT_Tc):
709 """Extend the horizontal span of this `w:tc` element to incorporate the
710 following `w:tc` element in the row and then delete that following `w:tc`
711 element.
712
713 Any content in the following `w:tc` element is appended to the content of
714 `top_tc`. The width of the following `w:tc` element is added to this one, if
715 present. Raises |InvalidSpanError| if the width of the resulting cell is greater
716 than `grid_width` or if there is no next `<w:tc>` element in the row.
717 """
718
719 def raise_on_invalid_swallow(next_tc: CT_Tc | None):
720 if next_tc is None:
721 raise InvalidSpanError("not enough grid columns")
722 if self.grid_span + next_tc.grid_span > grid_width:
723 raise InvalidSpanError("span is not rectangular")
724
725 next_tc = self._next_tc
726 raise_on_invalid_swallow(next_tc)
727 assert next_tc is not None
728 next_tc._move_content_to(top_tc)
729 self._add_width_of(next_tc)
730 self.grid_span += next_tc.grid_span
731 next_tc._remove()
732
733 @property
734 def _tbl(self) -> CT_Tbl:

Calls 3

_add_width_ofMethod · 0.95
_move_content_toMethod · 0.80
_removeMethod · 0.80