user12571160
user12571160

Reputation:

how to reset all rows and column data uisng python gspread sheets

I have the google sheet in which sheet has all data but how to reset the google sheet before adding the data in same google sheets any help would be appreciated

Google Sheet Image Link Given Here :https://i.sstatic.net/6sbvr.png

Upvotes: 3

Views: 2889

Answers (1)

Tanaike
Tanaike

Reputation: 201553

  • You want to reset the sheet using gspread.
  • You have already been able to get and put values for Google Spreadsheet using gspread.

If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

Pattern 1:

If reset in your question is to clear all values of cells on the sheet in the Spreadsheet, how about the following sample script? In this pattern, all values in the cells are cleared.

Sample script:

spreadsheetId = "###"  # Please set the Spreadsheet ID.
sheetName = "Sheet1"  # Please set the sheet name.

spreadsheet = client.open_by_key(spreadsheetId)
worksheet = spreadsheet.worksheet(sheetName)
worksheet.clear()

Pattern 2:

If reset in your question is to clear all values and format of cells on the sheet in the Spreadsheet, how about the following sample script? In this pattern, all values and cell formats in the cells are cleared.

Sample script:

spreadsheetId = "###"  # Please set the Spreadsheet ID.
sheetName = "Sheet1"  # Please set the sheet name.

spreadsheet = client.open_by_key(spreadsheetId)
worksheet = spreadsheet.worksheet(sheetName)

requests = {"requests": [{"updateCells": {"range": {"sheetId": worksheet._properties['sheetId']}, "fields": "*"}}]}
res = spreadsheet.batch_update(requests)
print(res)

References:

If I misunderstood your question and this was not the result you want, I apologize.

Upvotes: 4

Related Questions