我试着在谷歌页面上复制几个简单的击键。我想将整个工作表更改为字体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"
}
}
]
}发布于 2018-06-16 23:56:08
您希望添加新格式(例如,horizontalAlignment和textFormat),而所有单元格的原始格式都是而不是修改的。也就是说,当"A1“具有红色背景颜色时,即使新格式是由请求体添加的,您也不希望更改背景色。如果我的理解是正确的,这次修改怎么样?
发自:
"fields": "userEnteredFormat"致:
"fields": "userEnteredFormat/textFormat,userEnteredFormat/horizontalAlignment"通过这种修改,只能修改horizontalAlignment和textFormat。
如果我误解了你的问题,我很抱歉。
编辑:
我知道您只想更改字体系列和字体大小。你能试试这片田地吗?请只修改请求体的字段。
"fields": "userEnteredFormat/textFormat/fontFamily,userEnteredFormat/textFormat/fontSize"加:
工作表API文档说fields是"string (FieldMask格式)“。因此,上面的值也可以写成如下。
"fields": "userEnteredFormat.textFormat.fontFamily,userEnteredFormat.textFormat.fontSize"https://stackoverflow.com/questions/50888131
复制相似问题