Skip to content

Commit

Permalink
Added a batch_merge method [issue #1473]
Browse files Browse the repository at this point in the history
  • Loading branch information
muddi900 committed Aug 1, 2024
1 parent a7b04cf commit 8f177a8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gspread/worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,23 @@ def merge_cells(self, name: str, merge_type: str = MergeType.merge_all) -> Any:

return self.client.batch_update(self.spreadsheet_id, body)

def batch_merge(
self,
merges: List[Dict[Literal["range", "mergeType"], Union[str | MergeType]]],
merge_type: MergeType = MergeType.all,
) -> Any:
requests = [
{
"merges": {
"range": a1_range_to_grid_range(i["range"], self.id),
"mergeType": i.get("mergeType", merge_type),
}
}
for i in merges
]

return self.client.batch_update(self.spreadsheet_id, {"requests": requests})

@cast_to_a1_notation
def unmerge_cells(self, name: str) -> JSONResponse:
"""Unmerge cells.
Expand Down

0 comments on commit 8f177a8

Please sign in to comment.