这将打印第一张纸的结果,但不会循环到第一页。 第一页的输出很好且准确,它不会循环过去,我也不知道为什么。我是新手,如果这很明显,请原谅我,但是我已经阅读了文档,找不到答案。谢谢。
import gspread
from oauth2client.service_account import ServiceAccountCredentials
sheets_of_months= ['May 2018 Chem Readings', 'April 2018 Chem Readings', 'June 2018 Chem Readings']
scope= ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds= ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client= gspread.authorize(creds)
def get_customers():
for name_of_sheet in sheets_of_months:
spread_sheet= client.open(name_of_sheet)
work_sheet= spread_sheet.sheet1
result= work_sheet.row_count
print result, name_of_sheet
get_customers()
我意识到问题出在这行
work_sheet= spread_sheet.sheet1
无论出于何种原因都会阻止它。
编辑:
def get_customers():
for name_of_sheet in sheets_of_months:
spread_sheet= client.open(name_of_sheet)
print name_of_sheet
work_sheet= spread_sheet.sheet1
print name_of_sheet
它的输出是疯狂的。
May 2018 Chem Readings
April 2018 Chem Readings
June 2018 Chem Readings
June 2018 Chem Readings
它循环一次直到第一次打印,然后打到work_sheet = spread_sheet.sheet1行,此后它又重新开始并且只打印一次。奇怪......