Python 使用updateCells API请求更新多个单元格的格式
我正在尝试将一个单元格区域居中对齐,但只有该区域中的第一个单元格更新为指定格式 这是我的密码:Python 使用updateCells API请求更新多个单元格的格式,python,google-sheets-api,google-api-python-client,Python,Google Sheets Api,Google Api Python Client,我正在尝试将一个单元格区域居中对齐,但只有该区域中的第一个单元格更新为指定格式 这是我的密码: align = 'CENTER' data={ "requests": [ { "updateCells": { "rows": [ { "values": [ { "userEnteredFor
align = 'CENTER'
data={
"requests": [
{
"updateCells": {
"rows": [
{
"values": [
{
"userEnteredFormat": {
"horizontalAlignment": align,
"textFormat": {
"fontFamily": fontFamily,
"fontSize": fontSize
}
}
}
]
}
],
"range": {
"sheetId": sheetId,
"startRowIndex": startRowIndex,
"endRowIndex": endRowIndex,
"startColumnIndex": startColumnIndex,
"endColumnIndex": endColumnIndex
},
"fields": "userEnteredFormat"
}
}
]
}
如果我记录值-即打印(startRowIndex、endRowIndex、startColumnIndex、endColumnIndex)
-它们是正确的(例如0 1 27 30
),但只有第一个单元格更新为格式-而不是整个范围
这是怎么回事?如何将指定的格式应用于整个范围?是否要更新“AB1:AD1”({startRowIndex:0,endRowIndex:1,startColumnIndex:27,endColumnIndex:30}
)。如果我的理解是正确的,这次修改怎么样
修改点:
- 更新3列时,还需要更新值。在您的情况下,需要更新3列。因此需要创建类似
{value:[{userEnteredFormat:#####},{userEnteredFormat:####},{userEnteredFormat:####]}
repeatCell
。请求正文如下。在此示例中,修改范围内的所有单元格
修改请求:
参考:
updateCells
而不是repeatCell
。。。对于单个单元格,我可以使用repeatCell
并使用一系列AB1:AB1
@jason,我很荣幸能使用它。我很高兴你的问题解决了。我可以从你的问题中学习。也谢谢你。
{
"requests":
[
{
"updateCells":
{
"rows":
[
{
"values":
[
{
"userEnteredFormat":
{
"horizontalAlignment": align , #'CENTER','LEFT','RIGHT',
"textFormat":
{
"fontFamily": fontFamily,
"fontSize": fontSize
}
}
},
{
"userEnteredFormat":
{
"horizontalAlignment": align , #'CENTER','LEFT','RIGHT',
"textFormat":
{
"fontFamily": fontFamily,
"fontSize": fontSize
}
}
},
{
"userEnteredFormat":
{
"horizontalAlignment": align , #'CENTER','LEFT','RIGHT',
"textFormat":
{
"fontFamily": fontFamily,
"fontSize": fontSize
}
}
}
]
}
],
"range":
{
"sheetId": sheetId,
"startRowIndex": startRowIndex,
"endRowIndex": endRowIndex,
"startColumnIndex": startColumnIndex,
"endColumnIndex": endColumnIndex
},
"fields": "userEnteredFormat",
}
}
]
}
{
"requests":
[
{
"repeatCell":
{
"cell":
{
"userEnteredFormat":
{
"horizontalAlignment": align , #'CENTER','LEFT','RIGHT',
"textFormat":
{
"fontFamily": fontFamily,
"fontSize": fontSize
}
}
},
"range":
{
"sheetId": sheetId,
"startRowIndex": startRowIndex,
"endRowIndex": endRowIndex,
"startColumnIndex": startColumnIndex,
"endColumnIndex": endColumnIndex
},
"fields": "userEnteredFormat"
}
}
]
}