如何解决Google表格API,字体颜色,一次更新多个范围 修改后的脚本:参考文献:
我目前通过遍历范围来更新多个范围。现在,我正在尝试一次调用更新所有范围。但我不知道在哪里放第二个范围。我认为有可能。我不知道。这是我的代码。
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,'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
放在哪里,以便一次调用即可更新两个范围?
解决方法
该修改如何?
在您的情况下,如何使用[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,'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])
参考文献:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。