我正在尝试在Google表单中复制一些简单的按键。我想将整个工作表更改为字体Balthazar
和大小11
。我可以通过ctrl
+a
并在下拉列表中选择字体和大小来完成此操作。不过,我想做1000张。
我的问题是,当我使用下面的代码时,它会把单元格中现有的格式删除。我该怎么避免呢?
这是我的代码:
align=None
fontFamily='balthazar'
fontSize = 11
data={
"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"
}
}
]
}
最佳答案
您希望在不修改所有单元格的原始格式的情况下添加新格式(例如,水平对齐和文本格式)。也就是说,当“A1”具有红色背景色时,即使请求主体添加了新格式,也不希望更改背景色。如果我的理解是正确的,那么这次修改怎么样?
发件人:
"fields": "userEnteredFormat"
致:
"fields": "userEnteredFormat/textFormat,userEnteredFormat/horizontalAlignment"
通过这种修改,只能修改
horizontalAlignment
和textFormat
。如果我误解了你的问题,我很抱歉。
编辑:
我知道你只想改变字体系列和字体大小。你能试试这些田地吗?请仅修改请求正文的字段。
"fields": "userEnteredFormat/textFormat/fontFamily,userEnteredFormat/textFormat/fontSize"
补充:
The document of Sheets API表示
fields
是“字符串(FieldMask格式)”。所以上面的值也可以写成如下。"fields": "userEnteredFormat.textFormat.fontFamily,userEnteredFormat.textFormat.fontSize"
关于python - Google表格“repeatCell”剥离现有单元格的格式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50888131/