From 8f177a80205c5d1bb00104d4e87f508d6f58c376 Mon Sep 17 00:00:00 2001 From: Mudassir Chapra Date: Thu, 1 Aug 2024 15:13:33 +0500 Subject: [PATCH] Added a `batch_merge` method [issue #1473] --- gspread/worksheet.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gspread/worksheet.py b/gspread/worksheet.py index 1c89b5ec1..3d895b021 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -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.