使用Google API v4添加包含数据的Google表格

Ale*_*ndr 5 python google-sheets google-spreadsheet-api

我正在使用Python.我需要使用Google API v4在电子表格中添加工作表.我可以使用带有电子表格ID和addSheet请求的batchUpdate创建工作表(它返回shetId并创建空工作表).但是如何在其中添加数据?

data = {'requests': [
    {
        'addSheet':{
            'properties':{'title': 'New sheet'}
        }
    }
]}

res = service.spreadsheets().batchUpdate(spreadsheetId=s_id, body=data).execute()
SHEET_ID = res['replies'][0]['addSheet']['properties']['sheetId']
Run Code Online (Sandbox Code Playgroud)

Ale*_*ndr 4

发现在电子表格内创建工作表后,您可以访问范围“nameofsheet!A1”,即

service.spreadsheets().values().update(spreadsheetId=s_id, range='New sheet!A1', body=data_i, valueInputOption='RAW').execute()
Run Code Online (Sandbox Code Playgroud)

此请求会将数据发布到名为“新工作表”的新创建的工作表中