0
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.

worksheet = sh.worksheet("Sheet2")

But how I can to upload CSV to second sheets?

  • 1
    Does this answer your question? [python gspread import csv to specific work sheet](https://stackoverflow.com/questions/57264871/python-gspread-import-csv-to-specific-work-sheet) – Kelo Sep 03 '22 at 18:15

1 Answers1

0

Hi using the method import_csv() you cannot do that. As mentioned in the documentation, it erases the content of the spreadsheet and create a single sheet with the content of the CSV file.

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

If you wish to fill up the second sheet with the content of the CSV, you can:

  1. Open the CSV
  2. Read a line
  3. Put this line in the spreadsheet
  4. Repeat to step 2.
Lavigne958
  • 442
  • 5
  • 12