MCPcopy Create free account
hub / github.com/scanny/python-pptx / merge

Method merge

src/pptx/table.py:260–288  ·  view source on GitHub ↗

Create merged cell from this cell to `other_cell`. This cell and `other_cell` specify opposite corners of the merged cell range. Either diagonal of the cell region may be specified in either order, e.g. self=bottom-right, other_cell=top-left, etc. Raises |ValueError

(self, other_cell: _Cell)

Source from the content-addressed store, hash-verified

258 self._tc.marB = margin_bottom
259
260 def merge(self, other_cell: _Cell) -> None:
261 """Create merged cell from this cell to `other_cell`.
262
263 This cell and `other_cell` specify opposite corners of the merged cell range. Either
264 diagonal of the cell region may be specified in either order, e.g. self=bottom-right,
265 other_cell=top-left, etc.
266
267 Raises |ValueError| if the specified range already contains merged cells anywhere within
268 its extents or if `other_cell` is not in the same table as `self`.
269 """
270 tc_range = TcRange(self._tc, other_cell._tc)
271
272 if not tc_range.in_same_table:
273 raise ValueError("other_cell from different table")
274 if tc_range.contains_merged_cell:
275 raise ValueError("range contains one or more merged cells")
276
277 tc_range.move_content_to_origin()
278
279 row_count, col_count = tc_range.dimensions
280
281 for tc in tc_range.iter_top_row_tcs():
282 tc.rowSpan = row_count
283 for tc in tc_range.iter_left_col_tcs():
284 tc.gridSpan = col_count
285 for tc in tc_range.iter_except_left_col_tcs():
286 tc.hMerge = True
287 for tc in tc_range.iter_except_top_row_tcs():
288 tc.vMerge = True
289
290 @property
291 def span_height(self) -> int:

Calls 6

iter_top_row_tcsMethod · 0.95
iter_left_col_tcsMethod · 0.95
TcRangeClass · 0.90

Tested by

no test coverage detected