我正在寻找一种方法,使用googlesheetapi和python只删除单元格区域选择上的格式,而不是它们的内容。在
目前,我唯一的解决方案是应用与普通格式相同的逻辑,并将样式设置为NONE。例如,当我将边框格式设置为特定范围时,我使用:
request_dict = {'requests': [{
"updateBorders": {
"range": {
"sheetId": sheetId,
"startRowIndex": 1,
"endRowIndex": raws,
"startColumnIndex": first_col,
"endColumnIndex": last_col},
"top": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"bottom": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"left": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"right": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"innerHorizontal": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}},
"innerVertical": {
"style": "SOLID_MEDIUM",
"width": 1,
"color": {"blue": 0}}}}]}
body = {'requests': request_dict['requests']}
service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId,
body=body).execute()
如果我想删除它,我将“样式”字段替换为“无”,如下所示:
^{pr2}$但这意味着我需要定义一个函数来删除我定义的每种格式的格式,这不是很实用。。。 第一步是找到一种方法来删除整个工作表上的格式,也许之后就可以在我的工作表的特定范围内这样做。在
This documentation似乎声明,如果在
updateCells
请求中将fields
设置为"userEnteredValue"
,则它将删除所有格式。我还没有测试过,但是你可以:相关问题 更多 >
编程相关推荐