Python 如何使用一个API调用从google电子表格中的所有工作表(选项卡)中获取所有记录?

Python 如何使用一个API调用从google电子表格中的所有工作表(选项卡)中获取所有记录?,python,google-sheets,google-sheets-api,Python,Google Sheets,Google Sheets Api,我想在一个api调用中检索google电子表格中的所有记录(而不是遍历所有的表格并逐个检索)。目前我正在做这件事 creds = ServiceAccountCredentials.from_json_keyfile_name('path-to-key', 'key.json'), self.scope) client = gspread.authorize(creds) spread = client.open("My SpreadSheet") data_for_sheet_0 = spr

我想在一个api调用中检索google电子表格中的所有记录(而不是遍历所有的表格并逐个检索)。目前我正在做这件事

creds = ServiceAccountCredentials.from_json_keyfile_name('path-to-key', 'key.json'), self.scope)
client = gspread.authorize(creds)
spread = client.open("My SpreadSheet")

data_for_sheet_0 = spread.get_worksheet(0).get_all_records()
data_for_sheet_1 = spread.get_worksheet(1).get_all_records()
.
.
.

正如你所看到的,这是没有效率的。有没有办法获取所有的工作表数据(或整个电子表格作为一个可编辑的可编辑列表)?谢谢。

试试这个。使用
电子表格.worksheets()
签出此gspread文档:

creds = ServiceAccountCredentials.from_json_keyfile_name('path-to-key', 'key.json'), self.scope)
client = gspread.authorize(creds)
spread = client.open("My SpreadSheet")

#Getting a list of worksheets inside a spreadsheet.
sheets = spreadsheet.worksheets()

for sheet in sheets:
    record = sheet.get_all_records()

    # Do whatever you want
    print(record)