首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >,字体颜色,一次更新多个范围

,字体颜色,一次更新多个范围
EN

Stack Overflow用户
提问于 2020-08-16 20:37:36
回答 1查看 133关注 0票数 1

目前,我通过遍历范围更新多个范围。现在我试着用一个电话更新所有的范围。但我不知道该把第二个射程放哪。我认为这是可能的。我不知道。这是我的密码。

代码语言:javascript
运行
复制
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放在哪里,以便用一个调用来更新两个范围?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-16 21:56:00

这个修改怎么样?

在您的例子中,使用[range1, range2]创建请求如何?

修改脚本:

代码语言:javascript
运行
复制
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])

参考文献:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63441713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档