You can add this code to write data to Google Sheet. In a document - Reading and writing cell values
Tables can have multiple sheets, with each sheet having any number of rows or columns. A cell is a location at the intersection of a particular row and column and may contain a data value. The Google Sheets API provides spreadsheets.values to make reading and writing values โโsimple.
Single band recording
To write data in one range, use spreadsheets.values.update request:
values = [ [ # Cell values ... ], # Additional rows ... ] body = { 'values': values } result = service.spreadsheets().values().update( spreadsheetId=spreadsheet_id, range=range_name, valueInputOption=value_input_option, body=body).execute()
The body of the update request should be ValueRange , although the only required field is values . If range specified, it must match the range in the URL. In ValueRange you can specify majorDimension . The default is ROWS. If COLUMNS is specified, each inner array is written to a column instead of a row.
Record multiple ranges
If you want to write some discontinuous ranges, you can use spreadsheets.values.batchUpdate request:
values = [ [ # Cell values ], # Additional rows ] data = [ { 'range': range_name, 'values': values }, # Additional ranges to update ... ] body = { 'valueInputOption': value_input_option, 'data': data } result = service.spreadsheets().values().batchUpdate( spreadsheetId=spreadsheet_id, body=body).execute()
The batchUpdate request body must be a BatchUpdateValuesRequest object that contains a ValueInputOption and a ValueRange list (one for each recorded range). Each ValueRange object specifies its own range , majorDimension and input data.
Hope this helps.
source share