Created
October 28, 2019 00:31
-
-
Save hexvolt/4eee9435b9398a17ddd1588ad6d830fe to your computer and use it in GitHub Desktop.
insert note to google spreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gspread.urls import SPREADSHEETS_API_V4_BASE_URL | |
def insert_note(worksheet, label, note): | |
""" | |
Insert note ito the google worksheet for a certain cell. | |
Compatible with gspread. | |
""" | |
spreadsheet_id = worksheet.spreadsheet.id | |
worksheet_id = worksheet.id | |
row, col = a1_to_coords(label) # [0, 0] is A1 | |
url = f"{SPREADSHEETS_API_V4_BASE_URL}/{spreadsheet_id}:batchUpdate" | |
payload = { | |
"requests": [ | |
{ | |
"updateCells": { | |
"range": { | |
"sheetId": worksheet_id, | |
"startRowIndex": row, | |
"endRowIndex": row + 1, | |
"startColumnIndex": col, | |
"endColumnIndex": col + 1 | |
}, | |
"rows": [ | |
{ | |
"values": [ | |
{ | |
"note": note | |
} | |
] | |
} | |
], | |
"fields": "note" | |
} | |
} | |
] | |
} | |
worksheet.spreadsheet.client.request("post", url, json=payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a1_to_coords
isfrom gspread.utils import a1_to_rowcol
?