微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Google Sheets api 无法正确识别所有单元格

如何解决Google Sheets api 无法正确识别所有单元格

我正在尝试编写一个脚本来根据单元格和我选择的每个单元格的值的长度进行评分。问题是当我使用此代码时:

import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ["https://spreadsheets.google.com/Feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json",scope)
client = gspread.authorize(creds)

# get the instance of the Spreadsheet
sheet = client.open('copy of Event Organizer')

# get the first sheet of the Spreadsheet
sheet_instance = sheet.get_worksheet(3)

words = ["C4","C5","C7","C9","C11","C13","C15","C17","C19","C21","C23","C25"]
values = [1012,12317,1120,1345,134,1420,5,531,220,15,2354]

len_list = []
for i,word in enumerate(words):
    try:
        len_list.append(len(sheet_instance.acell(word).value))

    except:
        len_list.append(0)
    len_list[i] = len_list[i] * values[i]

print(len_list)
print(sum(len_list))
sheet_instance.update_acell("C29",sum(len_list))

由于某种原因,代码告诉我第一个单元格 (C4) 是空的,即使它不是,因此计算出错。为什么会这样?有时这也会发生在其他细胞上。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。