我在使用 Gspread 的 get_all_values() 时遇到问题
import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
from gmail_variables import *
json_key = json.load(open('key7367.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
wks = gc.open_by_url('https://docs.google.com/a/test.com/spreadsheets/d/1-cAg..sLt5Ho/edit?usp=sharing')
recipients = wks.get_all_values()
我正在尝试编写一个从 Google 电子表格中提取的电子邮件程序。当我尝试运行它时;我得到了错误。
'Spreadsheet' object has no attribute 'get_all_values'
感谢任何帮助。
请您参考如下方法:
您只是打开工作簿,而不是指定要从中获取所有值的工作表。您需要调用 get_worksheet() 方法。尝试:
wks = gc.open_by_url('https://docs.google.com/a/test.com/spreadsheets/d/1-cAg..sLt5Ho/edit?usp=sharing').get_worksheet(0)
recipients = wks.get_all_values()
其中“0”是工作表的索引(0 是工作簿中的第一个工作表)。
