Я использую gspread
и gspread_formatting
для обновления своих таблиц в Google. Часть моей кодовой базы была переработана для использования batch_update
, потому что я нашел несколько примеров кода в другом ответе, которые я мог бы использовать в качестве справочного материала. Однако я не могу преобразовать две другие операции. Вот мой код:
import gspread
from gspread_formatting import *
from oauth2client.service_account import ServiceAccountCredentials
def operate():
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive'
]
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'creds.json',
scope
)
gc = gspread.authorize(credentials)
sh = gc.open('My spreadsheet')
ws = sh.sheet1
sheet_id = ws._properties['sheetId']
# Setting the column sizes
body = {
'requests': [
{
'updateDimensionProperties': {
'range': {
'sheetId': sheet_id,
'dimension': 'COLUMNS',
'startIndex': 0,
'endIndex': 10
},
'properties': {
'pixelSize': 150
},
'fields': 'pixelSize'
}
},
{
'updateDimensionProperties': {
'range': {
'sheetId': sheet_id,
'dimension': 'COLUMNS',
'startIndex': 4,
'endIndex': 6
},
'properties': {
'pixelSize': 250
},
'fields': 'pixelSize'
}
}
]
}
res = sh.batch_update(body)
# Request 1
ws.insert_row(['One', 'Two', 'Three'], 1)
# Request 2
format_cell_range(
ws, 'A1:Z7',
cellFormat(
wrapStrategy='WRAP',
verticalAlignment='MIDDLE',
backgroundColor=color(0.886, 0.945, 0.988),
textFormat=textFormat(
foregroundColor=color(0, 0.129, 0.443),
fontFamily='Roboto',
bold=True
)
)
)
Итак, что я хочу сделать, так это каким-то образом добавить запрос 1 и запрос 2 в метод bulk_update
. Можно ли вставить строку и изменить форматирование с помощью bulk_update
? Если да, то как я могу это сделать? Спасибо за любую помощь.