pythongspread-如何在googlesheetapi中删除/删除列
我正在使用python中的gspread将CSV文件中的数据记录到google工作表中,其值为_update() 然后我使用gspread格式创建背景色。因为我还没有找到从CSV格式化颜色的方法,所以我的脚本读取C列中的数据,在C列中存储我想要使用的颜色 创建背景色后,我想删除C列,包括标题(第1行) 删除或删除整个列的最佳方法是什么? 或者,如果有一种方法可以直接从CSV文件中记录背景颜色,那就更好了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=
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文件中记录背景颜色,那就更好了
。
。所以我无法回答。但是我可以回答删除或删除整个列的最佳方法是什么?
。因此,在这里,我想提出使用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)