Google 表格 API:'SpreadsheetsClient' 对象没有 'update_cell' 属性

3 投票
1 回答
587 浏览
提问于 2025-04-18 09:59

我在用Python通过Google表格API更新一个单元格的时候,遇到了一个问题,代码是这样的:

import gdata.spreadsheets.client 
import gdata.gauth

gd_client = gdata.spreadsheets.client.SpreadsheetsClient()
gd_client.auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)

wksht_id = od6

gd_client.update_cell(spreadsheet_k, wksht_id, 3, 17, 'TEST')

结果出现了这个错误:

AttributeError: 'SpreadsheetsClient' object has no attribute 'update_cell'

虽然在client.py的源代码中,update_cell这个方法很明显是属于SpreadsheetsClient类的:https://code.google.com/p/gdata-python-client/source/browse/src/gdata/spreadsheets/client.py

这个单元格里面有内容,不知道这是否有影响。但错误并不是因为这个。我就是搞不懂为什么会这样。可能和API的不同版本有关吧?

我到底漏掉了什么呢?

1 个回答

2

我搞明白了!原来源代码更新了一个叫做update_cell的方法,但不知道为什么,gdata下载的版本里没有这个方法。你需要去源代码里把这个方法复制到你自己的gdata版本里,或者可以使用这个替代方案:https://gist.github.com/egor83/4634422

撰写回答