目前,我通过遍历范围更新多个范围。现在我试着用一个电话更新所有的范围。但我不知道该把第二个射程放哪。我认为这是可能的。我不知道。这是我的密码。
from multicore import g
key = '1-I9CugmHB1Ds6n1jBy4Zo4hk_k4sQsTmOFfccxRc2qo'
robo_font_color = [0.6, 0.0, 0.3]
range1 = {'sheetId': 184514576, 'startRowIndex': 2, 'endRowIndex': 3, 'startColumnIndex': 6, 'endColumnIndex': 9}
range2 = {'sheetId': 184514576, 'startRowIndex': 0, 'endRowIndex': 3, 'startColumnIndex': 1, 'endColumnIndex': 2}
def font_color(key, color): # color is a 1x3 list
data = {"requests": [{
"repeatCell": {
"range": range1,
"cell": {
"userEnteredFormat": {
"textFormat": {
"foregroundColor": { # color of text
"red": color[0],
"green": color[1],
"blue": color[2]
},
}
}
},
"fields": "userEnteredFormat.textFormat.foregroundColor"
}
}]
}
g.service.spreadsheets().batchUpdate(spreadsheetId=key, body=data).execute()
font_color(key,robo_font_color)我应该把range2放在哪里,以便用一个调用来更新两个范围?
发布于 2020-08-16 21:56:00
这个修改怎么样?
在您的例子中,使用[range1, range2]创建请求如何?
修改脚本:
from multicore import g
key = '1-I9CugmHB1Ds6n1jBy4Zo4hk_k4sQsTmOFfccxRc2qo'
robo_font_color = [0.6, 0.0, 0.3]
range1 = {'sheetId': 184514576, 'startRowIndex': 2, 'endRowIndex': 3, 'startColumnIndex': 6, 'endColumnIndex': 9}
range2 = {'sheetId': 184514576, 'startRowIndex': 0, 'endRowIndex': 3, 'startColumnIndex': 1, 'endColumnIndex': 2}
def font_color(key, color, ranges): # color is a 1x3 list
data = {"requests": [{
"repeatCell": {
"range": r,
"cell": {
"userEnteredFormat": {
"textFormat": {
"foregroundColor": { # color of text
"red": color[0],
"green": color[1],
"blue": color[2]
},
}
}
},
"fields": "userEnteredFormat.textFormat.foregroundColor"
}
} for r in ranges]}
g.service.spreadsheets().batchUpdate(spreadsheetId=key, body=data).execute()
font_color(key,robo_font_color, [range1, range2])参考文献:
https://stackoverflow.com/questions/63441713
复制相似问题