简体   繁体   English

如何使用 gspread 上传到工作表 2

[英]How to upload to sheet 2 using gspread

import gspread
sh = gc.open("Nameofsheet")
content = open("file.csv", "r").read().encode("utf8")
gc.import_csv(sh.id, content)

This code to upload csv to google spreadsheets in first sheet.此代码将 csv 上传到第一张表中的谷歌电子表格。

worksheet = sh.worksheet("Sheet2")

But how I can to upload CSV to second sheets?但是我怎样才能将 CSV 上传到第二张纸?

Hi using the method import_csv() you cannot do that.嗨,使用方法import_csv()你不能这样做。 As mentioned in the documentation, it erases the content of the spreadsheet and create a single sheet with the content of the CSV file.如文档中所述,它会擦除电子表格的内容并使用 CSV 文件的内容创建一个工作表。

Imports data into the first page of the spreadsheet.将数据导入电子表格的第一页。

https://docs.gspread.org/en/v5.4.0/api/client.html?highlight=import#gspread.Client.import_csv https://docs.gspread.org/en/v5.4.0/api/client.html?highlight=import#gspread.Client.import_csv

If you wish to fill up the second sheet with the content of the CSV, you can:如果您想用 CSV 的内容填写第二张表,您可以:

  1. Open the CSV打开 CSV
  2. Read a line读一行
  3. Put this line in the spreadsheet将此行放在电子表格中
  4. Repeat to step 2.重复步骤 2。

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

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