diff --git a/HISTORY.rst b/HISTORY.rst index b5da9bda9..898f2cbbc 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,12 @@ Release History =============== +5.12.4.(2023-12-31) +------------------- + +* Bump actions/setup-python from 4 to 5 by @dependabot in https://github.com/burnash/gspread/pull/1370 +* Fixed default value of merge_type parameter in merge_cells function docstring. by @neolooong in https://github.com/burnash/gspread/pull/1373 + 5.12.3 (2023-12-15) ------------------- diff --git a/gspread/utils.py b/gspread/utils.py index a22b232d2..e97dced74 100644 --- a/gspread/utils.py +++ b/gspread/utils.py @@ -52,6 +52,15 @@ class Dimension(StrEnum): cols = "COLUMNS" +class MergeType(StrEnum): + merge_all = "MERGE_ALL" + merge_columns = "MERGE_COLUMNS" + merge_rows = "MERGE_ROWS" + + +SILENCE_WARNINGS_ENV_KEY = "GSPREAD_SILENCE_WARNINGS" + + class ValueRenderOption(StrEnum): formatted = "FORMATTED_VALUE" unformatted = "UNFORMATTED_VALUE" diff --git a/gspread/worksheet.py b/gspread/worksheet.py index a6d6bc192..8154b9a4c 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -36,6 +36,7 @@ Dimension, GridRangeType, InsertDataOption, + MergeType, PasteOrientation, PasteType, T, @@ -2492,14 +2493,14 @@ def copy_to( ) @cast_to_a1_notation - def merge_cells(self, name: str, merge_type: str = "MERGE_ALL") -> JSONResponse: - """Merge cells. There are 3 merge types: ``MERGE_ALL``, ``MERGE_COLUMNS``, - and ``MERGE_ROWS``. + def merge_cells(self, name: str, merge_type: str = MergeType.merge_all): + """Merge cells. :param str name: Range name in A1 notation, e.g. 'A1:A5'. - :param str merge_type: (optional) one of ``MERGE_ALL``, - ``MERGE_COLUMNS``, or ``MERGE_ROWS``. Defaults to ``MERGE_ROWS``. + :param merge_type: (optional) one of ``MergeType.merge_all``, + ``MergeType.merge_columns``, or ``MergeType.merge_rows``. Defaults to ``MergeType.merge_all``. See `MergeType`_ in the Sheets API reference. + :type merge_type: :namedtuple:`~gspread.utils.MergeType` Alternatively, you may specify numeric boundaries. All values index from 1 (one): diff --git a/tests/cassettes/WorksheetTest.test_get_merge_cells_and_unmerge_cells.json b/tests/cassettes/WorksheetTest.test_get_merge_cells_and_unmerge_cells.json new file mode 100644 index 000000000..baa794a3e --- /dev/null +++ b/tests/cassettes/WorksheetTest.test_get_merge_cells_and_unmerge_cells.json @@ -0,0 +1,1237 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "POST", + "uri": "https://www.googleapis.com/drive/v3/files?supportsAllDrives=True", + "body": "{\"name\": \"Test WorksheetTest test_get_merge_cells_and_unmerge_cells\", \"mimeType\": \"application/vnd.google-apps.spreadsheet\"}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "124" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:39 GMT" + ], + "Vary": [ + "Origin, X-Origin" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Pragma": [ + "no-cache" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "211" + ] + }, + "body": { + "string": "{\n \"kind\": \"drive#file\",\n \"id\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"name\": \"Test WorksheetTest test_get_merge_cells_and_unmerge_cells\",\n \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:39 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "3355" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_get_merge_cells_and_unmerge_cells\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 26\n }\n }\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:40 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "3355" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_get_merge_cells_and_unmerge_cells\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 26\n }\n }\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/values/%27Sheet1%27:clear", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:40 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "107" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"clearedRange\": \"Sheet1!A1:Z1000\"\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs:batchUpdate", + "body": "{\"requests\": [{\"updateSheetProperties\": {\"properties\": {\"sheetId\": 0, \"gridProperties\": {\"rowCount\": 4, \"columnCount\": 4}}, \"fields\": \"gridProperties/rowCount,gridProperties/columnCount\"}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "190" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:41 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "PUT", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/values/%27Sheet1%27%21A1%3AD4?valueInputOption=RAW", + "body": "{\"values\": [[\"1\", \"\", \"2\", \"3\"], [\"\", \"\", \"\", \"\"], [\"\", \"4\", \"\", \"\"], [\"\", \"5\", \"\", \"\"]]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "89" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:41 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "169" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"updatedRange\": \"Sheet1!A1:D4\",\n \"updatedRows\": 4,\n \"updatedColumns\": 4,\n \"updatedCells\": 16\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs:batchUpdate", + "body": "{\"requests\": [{\"mergeCells\": {\"mergeType\": \"MERGE_ALL\", \"range\": {\"startRowIndex\": 0, \"endRowIndex\": 2, \"startColumnIndex\": 0, \"endColumnIndex\": 2, \"sheetId\": 0}}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "165" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:42 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs:batchUpdate", + "body": "{\"requests\": [{\"mergeCells\": {\"mergeType\": \"MERGE_COLUMNS\", \"range\": {\"startRowIndex\": 0, \"endRowIndex\": 2, \"startColumnIndex\": 2, \"endColumnIndex\": 4, \"sheetId\": 0}}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "169" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:42 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs:batchUpdate", + "body": "{\"requests\": [{\"mergeCells\": {\"mergeType\": \"MERGE_ROWS\", \"range\": {\"startRowIndex\": 2, \"endRowIndex\": 4, \"startColumnIndex\": 1, \"endColumnIndex\": 3, \"sheetId\": 0}}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "166" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:42 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/values/%27Sheet1%27%21A1%3AD4", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:43 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "205" + ] + }, + "body": { + "string": "{\n \"range\": \"Sheet1!A1:D4\",\n \"majorDimension\": \"ROWS\",\n \"values\": [\n [\n \"1\",\n \"\",\n \"2\",\n \"3\"\n ],\n [],\n [\n \"\",\n \"4\"\n ],\n [\n \"\",\n \"5\"\n ]\n ]\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:43 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "4087" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_get_merge_cells_and_unmerge_cells\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 4,\n \"columnCount\": 4\n }\n },\n \"merges\": [\n {\n \"startRowIndex\": 0,\n \"endRowIndex\": 2,\n \"startColumnIndex\": 0,\n \"endColumnIndex\": 2\n },\n {\n \"startRowIndex\": 0,\n \"endRowIndex\": 2,\n \"startColumnIndex\": 2,\n \"endColumnIndex\": 3\n },\n {\n \"startRowIndex\": 0,\n \"endRowIndex\": 2,\n \"startColumnIndex\": 3,\n \"endColumnIndex\": 4\n },\n {\n \"startRowIndex\": 2,\n \"endRowIndex\": 3,\n \"startColumnIndex\": 1,\n \"endColumnIndex\": 3\n },\n {\n \"startRowIndex\": 3,\n \"endRowIndex\": 4,\n \"startColumnIndex\": 1,\n \"endColumnIndex\": 3\n }\n ]\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "POST", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs:batchUpdate", + "body": "{\"requests\": [{\"unmergeCells\": {\"range\": {\"startRowIndex\": 0, \"endRowIndex\": 4, \"startColumnIndex\": 0, \"endColumnIndex\": 4, \"sheetId\": 0}}}]}", + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "141" + ], + "Content-Type": [ + "application/json" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:44 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "97" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"replies\": [\n {}\n ]\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/values/%27Sheet1%27%21A1%3AD4", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:44 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "205" + ] + }, + "body": { + "string": "{\n \"range\": \"Sheet1!A1:D4\",\n \"majorDimension\": \"ROWS\",\n \"values\": [\n [\n \"1\",\n \"\",\n \"2\",\n \"3\"\n ],\n [],\n [\n \"\",\n \"4\"\n ],\n [\n \"\",\n \"5\"\n ]\n ]\n}\n" + } + } + }, + { + "request": { + "method": "GET", + "uri": "https://sheets.googleapis.com/v4/spreadsheets/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs?includeGridData=false", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:44 GMT" + ], + "Vary": [ + "Origin", + "X-Origin", + "Referer" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "private" + ], + "Server": [ + "ESF" + ], + "Transfer-Encoding": [ + "chunked" + ], + "Content-Type": [ + "application/json; charset=UTF-8" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "x-l2-request-path": [ + "l2-managed-6" + ], + "X-XSS-Protection": [ + "0" + ], + "content-length": [ + "3351" + ] + }, + "body": { + "string": "{\n \"spreadsheetId\": \"16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs\",\n \"properties\": {\n \"title\": \"Test WorksheetTest test_get_merge_cells_and_unmerge_cells\",\n \"locale\": \"en_US\",\n \"autoRecalc\": \"ON_CHANGE\",\n \"timeZone\": \"Etc/GMT\",\n \"defaultFormat\": {\n \"backgroundColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n },\n \"padding\": {\n \"top\": 2,\n \"right\": 3,\n \"bottom\": 2,\n \"left\": 3\n },\n \"verticalAlignment\": \"BOTTOM\",\n \"wrapStrategy\": \"OVERFLOW_CELL\",\n \"textFormat\": {\n \"foregroundColor\": {},\n \"fontFamily\": \"arial,sans,sans-serif\",\n \"fontSize\": 10,\n \"bold\": false,\n \"italic\": false,\n \"strikethrough\": false,\n \"underline\": false,\n \"foregroundColorStyle\": {\n \"rgbColor\": {}\n }\n },\n \"backgroundColorStyle\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n \"spreadsheetTheme\": {\n \"primaryFontFamily\": \"Arial\",\n \"themeColors\": [\n {\n \"colorType\": \"TEXT\",\n \"color\": {\n \"rgbColor\": {}\n }\n },\n {\n \"colorType\": \"BACKGROUND\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 1,\n \"blue\": 1\n }\n }\n },\n {\n \"colorType\": \"ACCENT1\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.25882354,\n \"green\": 0.52156866,\n \"blue\": 0.95686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT2\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.91764706,\n \"green\": 0.2627451,\n \"blue\": 0.20784314\n }\n }\n },\n {\n \"colorType\": \"ACCENT3\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.9843137,\n \"green\": 0.7372549,\n \"blue\": 0.015686275\n }\n }\n },\n {\n \"colorType\": \"ACCENT4\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.20392157,\n \"green\": 0.65882355,\n \"blue\": 0.3254902\n }\n }\n },\n {\n \"colorType\": \"ACCENT5\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 1,\n \"green\": 0.42745098,\n \"blue\": 0.003921569\n }\n }\n },\n {\n \"colorType\": \"ACCENT6\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.27450982,\n \"green\": 0.7411765,\n \"blue\": 0.7764706\n }\n }\n },\n {\n \"colorType\": \"LINK\",\n \"color\": {\n \"rgbColor\": {\n \"red\": 0.06666667,\n \"green\": 0.33333334,\n \"blue\": 0.8\n }\n }\n }\n ]\n }\n },\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": 0,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 4,\n \"columnCount\": 4\n }\n }\n }\n ],\n \"spreadsheetUrl\": \"https://docs.google.com/spreadsheets/d/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs/edit\"\n}\n" + } + } + }, + { + "request": { + "method": "DELETE", + "uri": "https://www.googleapis.com/drive/v3/files/16u2Rgrky_mSTXlMiEplZbu40DNyTHjnNEEDSGFBlpWs?supportsAllDrives=True", + "body": null, + "headers": { + "User-Agent": [ + "python-requests/2.31.0" + ], + "Accept-Encoding": [ + "gzip, deflate" + ], + "Accept": [ + "*/*" + ], + "Connection": [ + "keep-alive" + ], + "x-goog-api-client": [ + "cred-type/sa" + ], + "x-allowed-locations": [ + "0x0" + ], + "Content-Length": [ + "0" + ], + "authorization": [ + "" + ] + } + }, + "response": { + "status": { + "code": 204, + "message": "No Content" + }, + "headers": { + "X-Frame-Options": [ + "SAMEORIGIN" + ], + "Date": [ + "Sat, 30 Dec 2023 18:22:45 GMT" + ], + "Vary": [ + "Origin, X-Origin" + ], + "Content-Length": [ + "0" + ], + "Alt-Svc": [ + "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000" + ], + "Cache-Control": [ + "no-cache, no-store, max-age=0, must-revalidate" + ], + "Pragma": [ + "no-cache" + ], + "Server": [ + "ESF" + ], + "Expires": [ + "Mon, 01 Jan 1990 00:00:00 GMT" + ], + "Content-Type": [ + "text/html" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "X-XSS-Protection": [ + "0" + ] + }, + "body": { + "string": "" + } + } + } + ] +} diff --git a/tests/worksheet_test.py b/tests/worksheet_test.py index ae03d648f..f8a4bcf1b 100644 --- a/tests/worksheet_test.py +++ b/tests/worksheet_test.py @@ -297,6 +297,39 @@ def test_get_values_merge_cells_with_named_range(self): ) self.assertEqual(values_with_merged, expected_values) + @pytest.mark.vcr() + def test_get_merge_cells_and_unmerge_cells(self): + self.sheet.resize(4, 4) + sheet_data = [ + ["1", "", "2", "3"], + ["", "", "", ""], + ["", "4", "", ""], + ["", "5", "", ""], + ] + self.sheet.update("A1:D4", sheet_data) + self.sheet.merge_cells("A1:B2", utils.MergeType.merge_all) + self.sheet.merge_cells("C1:D2", utils.MergeType.merge_columns) + self.sheet.merge_cells("B3:C4", utils.MergeType.merge_rows) + + REQUEST_RANGE = "A1:D4" + expected_values = [ + ["1", "1", "2", "3"], + ["1", "1", "2", "3"], + ["", "4", "4", ""], + ["", "5", "5", ""], + ] + values_with_merged = self.sheet.get_values( + REQUEST_RANGE, combine_merged_cells=True + ) + self.assertEqual(values_with_merged, expected_values) + + self.sheet.unmerge_cells("A1:D4") + expected_values = sheet_data + values_with_merged = self.sheet.get_values( + REQUEST_RANGE, combine_merged_cells=True + ) + self.assertEqual(values_with_merged, expected_values) + @pytest.mark.vcr() def test_get_values_and_maintain_size(self): """test get_values with maintain_size=True"""