简体   繁体   English

如何通过Python API更新一个Google Spreadsheet中的多个工作表

[英]How to update multiple sheets within one Google Spreadsheet via Python API

Currently I am sending DataFrames (Python/Pandas) to a Google Spreadsheet via gspread-dataframe Currently I'm pushing one DataFrame to One Google Spreadsheet. 目前,我正在通过gspread- dataframe将DataFrames(Python / Pandas)发送到Google Spreadsheet。目前,我正在将一个DataFrame推送到一个Google Spreadsheet。

my code is standard via the documentation, and looks like this: 我的代码通过文档是标准的,看起来像这样:

from gspread_dataframe import get_as_dataframe, set_with_dataframe
import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
google_client = gspread.authorize(creds)
sheet = google_client.open('User IDs').sheet1

My question: If I wanted to push multiple dataframes to multiple sheets on the same Google Spreadsheet, could I? 我的问题:如果我想将多个数据框推送到同一Google Spreadsheet上的多个表上,可以吗?

Note: I know I can make Separate Google Spreadsheets to hold Multiple DataFrames, but I would like to be able to have one Spreadsheet with Multiple sheets contained within it. 注意:我知道我可以制作单独的Google Spreadsheets来容纳多个DataFrame,但是我希望能够拥有一个Spreadsheet,其中包含多个工作表。

Thank you 谢谢

Google refers to "tabs" within Google Spreadsheets as "workbooks". Google在Google Spreadsheets中将“标签”称为“工作簿”。

All you need to do is: 您需要做的只是:

sheet1 = google_client.open('User IDs').workbook('sheet1')
sheet2 = google_client.open('User IDs').workbook('sheet2')
...
sheet_n = google_client.open('User IDs').workbook('sheet_n')

where 'sheet1'...'sheet_n' are the names of the workbooks within your spreadsheet 'User IDs' 其中“ sheet1” ...“ sheet_n”是电子表格“用户ID”中工作簿的名称

THEN... you can push the data to the spreadsheet via 然后...您可以通过以下方式将数据推送到电子表格

set_with_dataframe(WORKBOOK_NAME, DATAFRAME_NAME)

*assuming that you are using the gspread_dataframe module *假设您正在使用gspread_dataframe模块

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

相关问题 如何使用 Google Sheets API 和 Python 更新电子表格属性? - How to update Spreadsheet Properties with Google Sheets API and Python? 如何使用 Google 表格 API 在电子表格中创建新表格 - How to create a new sheet within a spreadsheet using Google Sheets API 如何使用 Python 中的 Google Sheets API 在电子表格的特定选项卡中写入数据? - How to write data in a specific tab of a spreadsheet with the Google Sheets API in Python? 如何通过python中的Google Drive API重命名Google电子表格? - How to rename a google spreadsheet via Google Drive API in python? 如何通过 Python API 为 Google 电子表格中的单元格背景着色 - How to color the cell background in Google spreadsheet via Python API 如何通过 gspread 和 python 在电子表格中创建多个工作表? - How to create multiple sheets in a spreadsheet by gspread and python? 如何使用 python 用谷歌 api 更新谷歌表格? - How to update google sheets with google api using python? 通过python中的api通过标题查找Google电子表格 - find google spreadsheet by title via api in python 如何在 Python 中使用 Google 表格 API 更新多个合并单元格? - How can I update multiple merged cells with Google Sheets API in Python? 如何使用 Google 表格 API 更新一行中的行? - How to update row in one line using Google Sheets API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM