Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pythongspread-如何在googlesheetapi中删除/删除列_Python_Google Sheets Api_Gspread - Fatal编程技术网

pythongspread-如何在googlesheetapi中删除/删除列

pythongspread-如何在googlesheetapi中删除/删除列,python,google-sheets-api,gspread,Python,Google Sheets Api,Gspread,我正在使用python中的gspread将CSV文件中的数据记录到google工作表中,其值为_update() 然后我使用gspread格式创建背景色。因为我还没有找到从CSV格式化颜色的方法,所以我的脚本读取C列中的数据,在C列中存储我想要使用的颜色 创建背景色后,我想删除C列,包括标题(第1行) 删除或删除整个列的最佳方法是什么? 或者,如果有一种方法可以直接从CSV文件中记录背景颜色,那就更好了 projectSheet.values_update( worksheet, params=

我正在使用python中的gspread将CSV文件中的数据记录到google工作表中,其值为_update()

然后我使用gspread格式创建背景色。因为我还没有找到从CSV格式化颜色的方法,所以我的脚本读取C列中的数据,在C列中存储我想要使用的颜色

创建背景色后,我想删除C列,包括标题(第1行)

删除或删除整个列的最佳方法是什么? 或者,如果有一种方法可以直接从CSV文件中记录背景颜色,那就更好了

projectSheet.values_update(
worksheet, params={'valueInputOption': 'USER_ENTERED'},
body={'values': list(csv.reader(open(csvName)))}
)

blue = [cell.row for cell in worksheet.findall('Blue')]
for i in blue:
    fmtBlue = cellFormat(
    backgroundColor=color(0.5, 0.5, 1),
    textFormat=textFormat(bold=False, foregroundColor=color(0, 0, 0)),
    horizontalAlignment='CENTER'
    )
    rows = f'A{i}:J{i}'
    format_cell_range(worksheet, rows, fmtBlue)

worksheet.delete_column('C')???
  • 您想使用gspread删除列
  • 您已经能够使用Sheets API输入和获取值
  • 你的问题如下。
    • 删除或删除整个列的最佳方法是什么
    • 如果有一种方法可以直接从CSV文件中记录背景颜色,那就更好了
如果我的理解是正确的,那么这个示例脚本怎么样?不幸的是,如果有办法直接从CSV文件记录背景色,我无法理解
。所以我无法回答。但是我可以回答
删除或删除整个列的最佳方法是什么?
。因此,在这里,我想提出使用gspread删除列的方法

gspread中似乎没有删除列的方法。因此,在本例中,我建议使用gspread的
batch\u update()
。请把这看作是几个答案中的一个

示例脚本:
  • 请将范围设置为GridRange
  • 在上面的脚本中,“C”列被删除
参考资料:
如果我误解了你的问题,而这不是你想要的结果,我道歉

spreadsheetId = "###"  # Please set Spreadsheet ID.
sheetName = "###"  # Please set sheet name which has the columns you want to delete.

spreadsheet = client.open_by_key(spreadsheetId)
sheetId = spreadsheet.worksheet(sheetName)._properties['sheetId']
body = {
    "requests": [
        {
            "deleteDimension": {
                "range": {
                    "sheetId": sheetId,
                    "dimension": "COLUMNS",
                    "startIndex": 2,
                    "endIndex": 3
                }
            }
        }
    ]
}
res = spreadsheet.batch_update(body)
print(res)