Skip to content Skip to sidebar Skip to footer

How To Use Google Sheet Api V4 Insert Note In Cell By Python

I don't know how to add note in a cell by Google Sheet API: https://developers.google.com/sheets/api/guides/values#writing_multiple_ranges I read info of Google Sheet API: https:/

Solution 1:

In Python, I use this piece of code and it work.

from googleapiclient.discovery import build
from google.oauth2 import service_account

SCOPES = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file",
                  "https://www.googleapis.com/auth/spreadsheets"]
SERVICE_ACCOUNT_FILE = 'credentials.json'

credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('sheets', 'v4', credentials=credentials)

spreadsheetId = "O188999ITC"
sheetid_src = "123a"
notes = {
            "updateCells": {
                "range": {
                    "sheetId": sheetid_src,
                    "startRowIndex": 1,
                    "endRowIndex: 1,
                    "startColumnIndex": 1,
                    "endColumnIndex": 1
                },
                "rows": [
                    {
                        "values": [
                            {
                                "note": "my note"
                            }
                        ]
                    }
                ],
                "fields": "note"
            }
        }
body = {"requests":[notes]}
result = service.spreadsheets().values().batchUpdate(
    spreadsheetId=spreadsheetId, body=body).execute()

Note are available in API with cellData, so you have to update values of differents cells with the keyword "Notes".

You can find more information here : https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#celldata

Solution 2:

I don't see any documentation regarding your issue. You may refer with this SO thread however it discussed how to get a note using getNote(). In your case, you need to use Google Apps Script and use the methods:

You may also check into this related reported issue. Hope this helps!

Post a Comment for "How To Use Google Sheet Api V4 Insert Note In Cell By Python"