最好用代码在实践中展示这一点
SERVICE_ACCOUNT_FILE = "wydupa15.json"
SCOPES = ["https://www.googleapis.com/auth/spreadsheets"]
SAMPLE_SPREADSHEET_ID = "1oEfhwe46ZPPpBgr_LYfVZAzJWV-enZHfW8Tp2RsYhvQ"
CRED = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES
)
service = discovery.build('sheets', 'v4', credentials=credentials)
# The A1 notation of the values to update.
RANGE = 'Test1!A5:C5' # TODO: Update placeholder value.
result = service.spreadsheets().values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID, range=RANGE).execute()
print("Current values in a given area:",result)
# ---inserting DATA - GET function ----------------------------------------------
values = result.get('values', [])
AAA = [['A', 'b', 5220]]
request = service.spreadsheets().values().update(spreadsheetId=SAMPLE_SPREADSHEET_ID,
range=RANGE,
valueInputOption='USER_ENTERED',
body={'values':AAA})
response = request.execute()
# ---------------------------------result------
result = service.spreadsheets().values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID, range=RANGE).execute()
print("Area value after changes:",result)