Batch update spreadsheet cells using Python


Using the gdata-python-client, you can change the value in multiple cells with one HTTP request. Here is an example:
import gdata.spreadsheet
import gdata.spreadsheet.service

client = gdata.spreadsheet.service.SpreadsheetsService()
client.email = 'your email address'
client.password = 'your password'
client.ProgrammaticLogin()

# Use the spreadsheet key and worksheet ID for the worksheet you want to edit.
cells = client.GetCellsFeed('pKq0C...', wksht_id='od6')

batchRequest = gdata.spreadsheet.SpreadsheetsCellsFeed()

# This sample changes the first four cells in the spreadsheet.
cells.entry[0].cell.inputValue = 'x'
batchRequest.AddUpdate(cells.entry[0])
cells.entry[1].cell.inputValue = 'y'
batchRequest.AddUpdate(cells.entry[1])
cells.entry[2].cell.inputValue = 'z'
batchRequest.AddUpdate(cells.entry[2])
cells.entry[3].cell.inputValue = '=sum(3,5)'
batchRequest.AddUpdate(cells.entry[3])

updated = client.ExecuteBatch(batchRequest, cells.GetBatchLink().href)

No comments: