Google 幻灯片 API 更新 table 背景颜色
Google Slides API update table background color
基本上我在 Google 幻灯片演示文稿中有 table(8 行 x 3 列),我想通过 API.[=16= 将背景颜色更改为]
我的 rgb 颜色值列表的第一项:
cons_data_lst[0][1][-1]
>>> [0.5882353, 0.7764706, 0.4862745]
我生成请求正文的函数:
def update_table_cell_colors(color_list):
req = [{
'updateTableCellProperties':{
'objectId': 'obj_id',
'tableRange': {
'location': {
'rowIndex': 1,
'columnIndex': 2,
},
'rowSpan': 1,
'columnSpan': 1,
},
'tableCellProperties':{
'tableCellBackgrounFill':{
'solidFill':{
'color':{
'rgbColor':{
'red': color_list[0],
'green': color_list[1],
'blue': color_list[2],
}
}
}}
}}} ]
return req
当我向演示文稿发送批量更新时,我收到以下错误:
HttpError: https://slides.googleapis.com/v1/presentations/1dzxYYPuqTM3VhwaR93Ep2jj_9Y2NCkSBsVBnmN6lcOs:batchUpdate?alt=json
returned "Invalid JSON payload received. Unknown name
"table_cell_backgroun_fill" at
'requests[0].update_table_cell_properties.table_cell_properties':
Cannot find field.". Details: "[{'@type':
'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations':
[{'field':
'requests[0].update_table_cell_properties.table_cell_properties',
'description': 'Invalid JSON payload received. Unknown name
"table_cell_backgroun_fill" at
\'requests[0].update_table_cell_properties.table_cell_properties\':
Cannot find field.'}]}]">
给定一个不同 rgb 颜色值的列表,我如何创建一个请求正文来更新所有列(1 到 2)行(有 8 个)文本背景颜色?
谢谢。
这个答案怎么样?
A1:
本节解释错误原因。
修改点:
- 从
Unknown name "table_cell_backgroun_fill" at 'requests[0].update_table_cell_properties.table_cell_properties'
的错误信息中,发现tableCellBackgrounFill
的属性名字是拼写错误。请修改为tableCellBackgroundFill
.
- 在
updateTableCellProperties
,需要使用fields
的属性。在你的情况下,添加 "fields": "tableCellBackgroundFill"
怎么样?您也可以使用 'fields': '*'
.
当这些修改反映到你的request body中,就变成了下面这样。
修改后的请求正文:
req = [
{
'updateTableCellProperties': {
'objectId': 'obj_id',
'tableRange': {
'location': {
'rowIndex': 1,
'columnIndex': 2
},
'rowSpan': 1,
'columnSpan': 1
},
'tableCellProperties': {
'tableCellBackgroundFill': { # Modified
'solidFill': {
'color': {
'rgbColor': {
'red': color_list[0],
'green': color_list[1],
'blue': color_list[2],
}
}
}
}
},
'fields': 'tableCellBackgroundFill' # Added
}
}
]
- 在使用这个脚本之前,请检查
color_list
和'obj_id'
、 的变量
A2:
本节对Given a list of different rgb color values, how can I create a request body to update all columns (1 to 2) row (there are 8) text background color ?
的问题2进行说明。
在您的问题中,您在问题的顶部说 I have table (8 rows x 3 columns)
。但是在 Given a list of different rgb color values, how can I create a request body to update all columns (1 to 2) row (there are 8) text background color ?
,你说 columns (1 to 2)
。我对此感到困惑。所以我想假设如下。
- 您的 table 有 8 行和 2 列。
- 您想将所有列和行的背景颜色更改为一种颜色。
示例请求正文如下。
示例请求正文:
req = [
{
"updateTableCellProperties":
{
"objectId": "obj_id",
"tableRange":
{
"location":
{
"rowIndex": 0,
"columnIndex": 0
},
"rowSpan": 8,
"columnSpan": 2
},
"tableCellProperties":
{
"tableCellBackgroundFill":
{
"solidFill":
{
"color":
{
"rgbColor":
{
"red": color_list[0],
"green": color_list[1],
"blue": color_list[2]
}
}
}
}
},
"fields": "tableCellBackgroundFill"
}
}
]
rowIndex
和 columnIndex
是起始单元格。
"rowIndex": 0
和 "columnIndex": 0
表示单元格 "A1".
rowSpan
和columnSpan
是行数和列数。
"rowSpan": 8
和 "columnSpan": 2
表示 8 行和 2 列。这样,单元格 "A1:B8" 的背景颜色就会改变。
- 如果你的table是8行3列,你想改变所有单元格,请按如下设置。
"rowIndex": 0
、"columnIndex": 0
和 "rowSpan": 8
、"columnSpan": 3
如果你想改变每个单元格的特殊背景颜色,需要为每个单元格创建请求主体数组。请注意这一点。
注:
- 此答案假定您已经能够使用幻灯片 API.
为 Google 幻灯片输入和获取值
参考文献:
如果我误解了您的问题并且这没有解决您的问题,我深表歉意。
基本上我在 Google 幻灯片演示文稿中有 table(8 行 x 3 列),我想通过 API.[=16= 将背景颜色更改为]
我的 rgb 颜色值列表的第一项:
cons_data_lst[0][1][-1]
>>> [0.5882353, 0.7764706, 0.4862745]
我生成请求正文的函数:
def update_table_cell_colors(color_list):
req = [{
'updateTableCellProperties':{
'objectId': 'obj_id',
'tableRange': {
'location': {
'rowIndex': 1,
'columnIndex': 2,
},
'rowSpan': 1,
'columnSpan': 1,
},
'tableCellProperties':{
'tableCellBackgrounFill':{
'solidFill':{
'color':{
'rgbColor':{
'red': color_list[0],
'green': color_list[1],
'blue': color_list[2],
}
}
}}
}}} ]
return req
当我向演示文稿发送批量更新时,我收到以下错误:
HttpError: https://slides.googleapis.com/v1/presentations/1dzxYYPuqTM3VhwaR93Ep2jj_9Y2NCkSBsVBnmN6lcOs:batchUpdate?alt=json returned "Invalid JSON payload received. Unknown name "table_cell_backgroun_fill" at 'requests[0].update_table_cell_properties.table_cell_properties': Cannot find field.". Details: "[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'requests[0].update_table_cell_properties.table_cell_properties', 'description': 'Invalid JSON payload received. Unknown name "table_cell_backgroun_fill" at \'requests[0].update_table_cell_properties.table_cell_properties\': Cannot find field.'}]}]">
给定一个不同 rgb 颜色值的列表,我如何创建一个请求正文来更新所有列(1 到 2)行(有 8 个)文本背景颜色?
谢谢。
这个答案怎么样?
A1:
本节解释错误原因。
修改点:
- 从
Unknown name "table_cell_backgroun_fill" at 'requests[0].update_table_cell_properties.table_cell_properties'
的错误信息中,发现tableCellBackgrounFill
的属性名字是拼写错误。请修改为tableCellBackgroundFill
. - 在
updateTableCellProperties
,需要使用fields
的属性。在你的情况下,添加"fields": "tableCellBackgroundFill"
怎么样?您也可以使用'fields': '*'
.
当这些修改反映到你的request body中,就变成了下面这样。
修改后的请求正文:
req = [
{
'updateTableCellProperties': {
'objectId': 'obj_id',
'tableRange': {
'location': {
'rowIndex': 1,
'columnIndex': 2
},
'rowSpan': 1,
'columnSpan': 1
},
'tableCellProperties': {
'tableCellBackgroundFill': { # Modified
'solidFill': {
'color': {
'rgbColor': {
'red': color_list[0],
'green': color_list[1],
'blue': color_list[2],
}
}
}
}
},
'fields': 'tableCellBackgroundFill' # Added
}
}
]
- 在使用这个脚本之前,请检查
color_list
和'obj_id'
、 的变量
A2:
本节对Given a list of different rgb color values, how can I create a request body to update all columns (1 to 2) row (there are 8) text background color ?
的问题2进行说明。
在您的问题中,您在问题的顶部说 I have table (8 rows x 3 columns)
。但是在 Given a list of different rgb color values, how can I create a request body to update all columns (1 to 2) row (there are 8) text background color ?
,你说 columns (1 to 2)
。我对此感到困惑。所以我想假设如下。
- 您的 table 有 8 行和 2 列。
- 您想将所有列和行的背景颜色更改为一种颜色。
示例请求正文如下。
示例请求正文:
req = [
{
"updateTableCellProperties":
{
"objectId": "obj_id",
"tableRange":
{
"location":
{
"rowIndex": 0,
"columnIndex": 0
},
"rowSpan": 8,
"columnSpan": 2
},
"tableCellProperties":
{
"tableCellBackgroundFill":
{
"solidFill":
{
"color":
{
"rgbColor":
{
"red": color_list[0],
"green": color_list[1],
"blue": color_list[2]
}
}
}
}
},
"fields": "tableCellBackgroundFill"
}
}
]
rowIndex
和columnIndex
是起始单元格。"rowIndex": 0
和"columnIndex": 0
表示单元格 "A1".
rowSpan
和columnSpan
是行数和列数。"rowSpan": 8
和"columnSpan": 2
表示 8 行和 2 列。这样,单元格 "A1:B8" 的背景颜色就会改变。- 如果你的table是8行3列,你想改变所有单元格,请按如下设置。
"rowIndex": 0
、"columnIndex": 0
和"rowSpan": 8
、"columnSpan": 3
如果你想改变每个单元格的特殊背景颜色,需要为每个单元格创建请求主体数组。请注意这一点。
注:
- 此答案假定您已经能够使用幻灯片 API. 为 Google 幻灯片输入和获取值
参考文献:
如果我误解了您的问题并且这没有解决您的问题,我深表歉意。