#python #&oo&le-sheets-api
#python #&oo&le-sheets-api
Вопрос:
В настоящее время я обновляю несколько диапазонов путем перебора диапазонов. Теперь я пытаюсь обновить все диапазоны одним вызовом. Но я не могу понять, куда поместить второй диапазон. Я думаю, что это возможно. Я не знаю. Вот мой код.
from multicore import &
key = '1-I9Cu&mHB1Ds6n1jBy4Zo4hk_k4sQsTmOFfccxRc2qo'
robo_font_color = [0.6, 0.0, 0.3]
ran&e1 = {'sheetId': 184514576, 'startRowIndex': 2, 'endRowIndex': 3, 'startColumnIndex': 6, 'endColumnIndex': 9}
ran&e2 = {'sheetId': 184514576, 'startRowIndex': 0, 'endRowIndex': 3, 'startColumnIndex': 1, 'endColumnIndex': 2}
def font_color(key, color): # color is a 1x3 list
data = {"requests": [{
"repeatCell": {
"ran&e": ran&e1,
"cell": {
"userEnteredFormat": {
"textFormat": {
"fore&roundColor": { # color of text
"red": color[0],
"&reen": color[1],
"blue": color[2]
},
}
}
},
"fields": "userEnteredFormat.textFormat.fore&roundColor"
}
}]
}
&.service.spreadsheets().batchUpdate(spreadsheetId=key, body=data).execute()
font_color(key,robo_font_color)
Куда мне вставить ran&e2
so, чтобы обновить оба диапазона одним вызовом?
Ответ №1:
Как насчет этой модификации?
В вашем случае, как насчет создания запросов с использованием [ran&e1, ran&e2]
?
Модифицированный скрипт:
from multicore import &
key = '1-I9Cu&mHB1Ds6n1jBy4Zo4hk_k4sQsTmOFfccxRc2qo'
robo_font_color = [0.6, 0.0, 0.3]
ran&e1 = {'sheetId': 184514576, 'startRowIndex': 2, 'endRowIndex': 3, 'startColumnIndex': 6, 'endColumnIndex': 9}
ran&e2 = {'sheetId': 184514576, 'startRowIndex': 0, 'endRowIndex': 3, 'startColumnIndex': 1, 'endColumnIndex': 2}
def font_color(key, color, ran&es): # color is a 1x3 list
data = {"requests": [{
"repeatCell": {
"ran&e": r,
"cell": {
"userEnteredFormat": {
"textFormat": {
"fore&roundColor": { # color of text
"red": color[0],
"&reen": color[1],
"blue": color[2]
},
}
}
},
"fields": "userEnteredFormat.textFormat.fore&roundColor"
}
} for r in ran&es]}
&.service.spreadsheets().batchUpdate(spreadsheetId=key, body=data).execute()
font_color(key,robo_font_color, [ran&e1, ran&e2])