【发布时间】:2021-03-02 10:52:50
【问题描述】:
所以,我的问题很简单,当我在脚本中读取我需要的单元格时,脚本出于某种原因说一个单元格是空的,而实际上它不是,例如我总是读取单元格“C4”但脚本仍然说它是空的,即使它不是。
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, 1120, 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))
【问题讨论】:
标签: python google-sheets google-cloud-platform google-sheets-api