如何使用python gspread表重置所有行和列数据 [英] how to reset all rows and column data uisng python gspread sheets

查看:119
本文介绍了如何使用python gspread表重置所有行和列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google工作表,其中工作表包含所有数据,但是在将数据添加到同一Google工作表中之前如何重置Google工作表任何帮助将不胜感激

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表格图片链接: https://i.stack.imgur.com/6sbvr.png

Google Sheet Image Link Given Here :https://i.stack.imgur.com/6sbvr.png

推荐答案

  • 您要使用gspread重置工作表.
  • 您已经能够使用gspread获取和放置Google Spreadsheet的值.
  • 如果我的理解是正确的,那么这个答案如何?请认为这只是几个可能的答案之一.

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

    如果您的问题中的 reset 是要清除电子表格中工作表上所有单元格的值,那么以下示例脚本如何?在这种模式下,将清除单元格中的所有值.

    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.

    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()
    

    模式2:

    如果您的问题中的 reset 是要清除电子表格中工作表上所有单元格的值和格式,那么以下示例脚本如何?在这种模式下,将清除单元格中的所有值和单元格格式.

    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.

    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)
    

    参考文献:

    • clear()
    • batch_update()
    • UpdateCellsRequest
    • 如果我误解了您的问题,而这不是您想要的结果,我深表歉意.

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

      这篇关于如何使用python gspread表重置所有行和列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆