Table Google 文档中的边框 API
Table border in Google Docs API
我正在寻找一种使用 API?
获取 Google 文档边框宽度的方法
我已经设置了一个包含两个 1-cell table 的测试文档。
第一个具有默认边框,第二个具有 0 宽度边框,第三个具有 3 pt 边框。
https://docs.google.com/document/d/1KOiw6bmsNhdOGGr9OZDWHNHrEID5RZncyCRRFFSU_Ok/edit
我使用 get request
检索文档
我在边框宽度方面找不到三个 table 之间的任何区别。
根据 documentation TableCellStyle 应该有 borderTop/Bottom/Left/Right 值,但我不确定我需要做什么才能将它们包含在响应中。
所有 3 个 tableCellStyle 看起来都一样,像这样:
"tableCellStyle": {
"rowSpan": 1,
"columnSpan": 1,
"backgroundColor": {},
"paddingLeft": {
"magnitude": 5,
"unit": "PT"
},
"paddingRight": {
"magnitude": 5,
"unit": "PT"
},
"paddingTop": {
"magnitude": 5,
"unit": "PT"
},
"paddingBottom": {
"magnitude": 5,
"unit": "PT"
},
"contentAlignment": "TOP"
}
每个 table 单元格包含一个具有相同段落样式的段落:
"borderLeft": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
更新
我在上面的例子中设置了 table 边框,API 响应中没有显示。
我的假设是 table 边框反映在响应数据的单元格中,因为 table 边框本身没有 属性。部分正确,请参阅答案。
来自TableCellStyle documentation:
Inherited table cell styles are represented as unset fields in this message. A table cell style can inherit from the table's style.
在这种情况下,TableCellStyle 继承了默认的 borderLeft、borderRight、borderTop 和 borderBottom 的默认样式,其表示如下:
"borderTop": {
"color": {
"color": {
"rgbColor": {}
}
},
"width": {
"magnitude": 1,
"unit": "PT"
},
"dashStyle": "SOLID"
}
本质上,如果您要获取边框宽度,则必须首先检查该边框字段是否存在于您的数据中。如果没有,您可以为其设置默认值 (1 PT
)。例如,使用 JavaScript 及其 ternary operator:
var borderTopMagnitude = tableCellStyle.borderTop ? tableCellStyle.borderTop.width.magnitude : 1;
var borderBottomMagnitude = tableCellStyle.borderBottom ? tableCellStyle.borderBottom.width.magnitude : 1;
var borderLeftMagnitude = tableCellStyle.borderLeft ? tableCellStyle.borderLeft.width.magnitude : 1;
var borderRightMagnitude = tableCellStyle.borderRight ? tableCellStyle.borderRight.width.magnitude : 1;
从新的 table 开始,以下顺序适用。
更改 table 边框样式不会反映在 API 响应中。
单个单元格或所有单元格的更改将反映在 API 响应中。
执行第 2 步后,table 边框样式的更改现在将反映在 API 响应中,但仅限于之前单独修改过的单元格。
显然,google 文档 API 中存在错误。我找到了错误报告:(https://issuetracker.google.com/186012454)
我制作了一个 document:在那里我增加了 table 边框的宽度和颜色。
左上单元格的 TableCellStyle 元素为 nil。
与 table 单元格链接的 Content.Paragraph 元素的边框属性也为零。
我正在寻找一种使用 API?
获取 Google 文档边框宽度的方法我已经设置了一个包含两个 1-cell table 的测试文档。 第一个具有默认边框,第二个具有 0 宽度边框,第三个具有 3 pt 边框。
https://docs.google.com/document/d/1KOiw6bmsNhdOGGr9OZDWHNHrEID5RZncyCRRFFSU_Ok/edit
我使用 get request
检索文档我在边框宽度方面找不到三个 table 之间的任何区别。
根据 documentation TableCellStyle 应该有 borderTop/Bottom/Left/Right 值,但我不确定我需要做什么才能将它们包含在响应中。
所有 3 个 tableCellStyle 看起来都一样,像这样:
"tableCellStyle": {
"rowSpan": 1,
"columnSpan": 1,
"backgroundColor": {},
"paddingLeft": {
"magnitude": 5,
"unit": "PT"
},
"paddingRight": {
"magnitude": 5,
"unit": "PT"
},
"paddingTop": {
"magnitude": 5,
"unit": "PT"
},
"paddingBottom": {
"magnitude": 5,
"unit": "PT"
},
"contentAlignment": "TOP"
}
每个 table 单元格包含一个具有相同段落样式的段落:
"borderLeft": {
"color": {},
"width": {
"unit": "PT"
},
"padding": {
"unit": "PT"
},
"dashStyle": "SOLID"
},
更新
我在上面的例子中设置了 table 边框,API 响应中没有显示。 我的假设是 table 边框反映在响应数据的单元格中,因为 table 边框本身没有 属性。部分正确,请参阅答案。
来自TableCellStyle documentation:
Inherited table cell styles are represented as unset fields in this message. A table cell style can inherit from the table's style.
在这种情况下,TableCellStyle 继承了默认的 borderLeft、borderRight、borderTop 和 borderBottom 的默认样式,其表示如下:
"borderTop": {
"color": {
"color": {
"rgbColor": {}
}
},
"width": {
"magnitude": 1,
"unit": "PT"
},
"dashStyle": "SOLID"
}
本质上,如果您要获取边框宽度,则必须首先检查该边框字段是否存在于您的数据中。如果没有,您可以为其设置默认值 (1 PT
)。例如,使用 JavaScript 及其 ternary operator:
var borderTopMagnitude = tableCellStyle.borderTop ? tableCellStyle.borderTop.width.magnitude : 1;
var borderBottomMagnitude = tableCellStyle.borderBottom ? tableCellStyle.borderBottom.width.magnitude : 1;
var borderLeftMagnitude = tableCellStyle.borderLeft ? tableCellStyle.borderLeft.width.magnitude : 1;
var borderRightMagnitude = tableCellStyle.borderRight ? tableCellStyle.borderRight.width.magnitude : 1;
从新的 table 开始,以下顺序适用。
更改 table 边框样式不会反映在 API 响应中。
单个单元格或所有单元格的更改将反映在 API 响应中。
执行第 2 步后,table 边框样式的更改现在将反映在 API 响应中,但仅限于之前单独修改过的单元格。
显然,google 文档 API 中存在错误。我找到了错误报告:(https://issuetracker.google.com/186012454)
我制作了一个 document:在那里我增加了 table 边框的宽度和颜色。
左上单元格的 TableCellStyle 元素为 nil。 与 table 单元格链接的 Content.Paragraph 元素的边框属性也为零。