【发布时间】:2018-09-27 19:37:16
【问题描述】:
我有一个 Google 电子表格,第 1 列包含 test_name,第 2 列包含测试结果(通过或失败)。我想在电子表格中搜索test_name(字符串),如果匹配,则获取字符串的行、列并更新column2中的结果。
try:
worksheet = sh.worksheet(sheetName)
print("got access to worksheet",worksheet)
except Exception as Ex:
print(Ex)
with open(PATH) as f:
for line in f:
if line.startswith("PASS") or line.startswith("FAIL") or line.startswith("SKIP") or line.startswith('INELIGIBLE') or line.startswith('ERROR'):
print("line",line)
index=line.index("")
result=line[0:index]
tname=line[index+1:]
print("result",result)
print(result+" "+ tname)
list1.append(tname)
print("*******************************")
try:
cell=sh.find(tname)
row=cell.row
column=cell.col
print("row",row)
print("col",col)
print("cell",cell)
except Exception as Ex:
print(Ex)
cell.find(tname) 显示错误,无法获取不区分大小写(或空格)的字符串。:
“电子表格”对象没有属性“单元格”
我已经获取了字符串的确切行,列。
【问题讨论】:
-
您需要使用
worksheet.find(tname)。在您的情况下,sh是Spreadsheet的一个实例,它确实没有cell属性。这就是您收到错误的原因。
标签: python-3.x google-sheets gspread