Python/gspread - how can I update multiple cells with DIFFERENT VALUES at once?

前端 未结 4 2153
广开言路
广开言路 2021-01-01 00:23

To update a range of cells, you use the following command.

## Select a range
cell_list = worksheet.range(\'A1:A7\')

for cell in cell_list:
    cell.value =          


        
4条回答
  •  梦毁少年i
    2021-01-01 01:01

    1. Import modules
    import gspread
    from gspread.models import Cell
    from oauth2client.service_account import ServiceAccountCredentials
    import string as string
    import random
    
    1. create cell array with values
    cells = []
    cells.append(Cell(row=1, col=1, value='Row-1 -- Col-1'))
    cells.append(Cell(row=1, col=2, value='Row-1 -- Col-2'))
    cells.append(Cell(row=9, col=20, value='Row-9 -- Col-20'))
    
    1. Find the sheet
    # use creds to create a client to interact with the Google Drive API
    scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
    creds = ServiceAccountCredentials.from_json_keyfile_name('Sheet-Update-Secret.json', scope)
    client = gspread.authorize(creds)
    
    1. Update the cells
    sheet.update_cells(cells)
    

    You could refer these link for more details.

提交回复
热议问题