简体   繁体   English

Python GSpread - 遍历行

[英]Python GSpread - Loop through rows

I am trying to loop through the rows on a Google sheet using python and gspread.我正在尝试使用 python 和 gspread 遍历 Google 工作表上的行。 Every time I try to get the values, the list is returned as columns and not rows.每次我尝试获取值时,列表都会以列而不是行的形式返回。

Is there a way to retrieve the rows and loop through them?有没有办法检索行并循环遍历它们?

Looking here https://docs.gspread.org/en/latest/user-guide.html#getting-all-values-from-a-row-or-a-column I am not too sure how many rows there will be.看这里https://docs.gspread.org/en/latest/user-guide.html#getting-all-values-from-a-row-or-a-column我不太确定会有多少行. Is there a way to count the first column?有没有办法计算第一列?

Import, Authenticate and Open the Sheet as defined by the gspread documentation:按照gspread文档的定义导入、验证和打开工作表:

import gspread
gc = gspread.service_account()
worksheet = gc.open("Sheet1").sheet1

Then use .get_all_values() to iterate through the rows:然后使用.get_all_values()遍历行:

rows = worksheet.get_all_values()
for row in rows:
   # ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM