【发布时间】:2020-02-26 12:38:07
【问题描述】:
可以通过格式菜单 > 段落样式 > 边框和底纹为 google 文档段落添加边框。。 p>
结果如下:
但是,我还没有弄清楚如何使用 Google Apps 脚本来做到这一点?
我已经咨询了documentation关于设置属性,但是没有出现边框。似乎可以使用表格和幻灯片来设置它们 - 但这不是我所追求的用例。
我通过 node.js 使用 DOCS API 下载了从包含我需要的边框的文档返回的示例 JSON。
function printDocTitle(auth) {
const documentId = '###';
const docs = google.docs({version: 'v1', auth});
docs.documents.get({
documentId: documentId,
}, (err, res) => {
if (err) return console.log('The API returned an error: ' + err);
const doc = res.data;
console.log(JSON.stringify(doc, null, 4));
})
}
代表我希望创建的效果的 JSON 部分如下所示。
{
"startIndex": 82,
"endIndex": 83,
"paragraph": {
"elements": [
{
"startIndex": 82,
"endIndex": 83,
"textRun": {
"content": "\n",
"textStyle": {
"fontSize": {
"magnitude": 12,
"unit": "PT"
},
"baselineOffset": "NONE"
}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"alignment": "END",
"direction": "LEFT_TO_RIGHT",
"borderBottom": {
"color": {
"color": {
"rgbColor": {}
}
},
"width": {
"magnitude": 1.5,
"unit": "PT"
},
"padding": {
"magnitude": 1,
"unit": "PT"
},
"dashStyle": "SOLID"
}
}
}
}
我想知道是否可以以某种方式利用它而不是使用 Google 脚本 - 但 DOCS API 似乎不支持边框。
如果有任何线索、提示或提示,将不胜感激?
【问题讨论】:
-
您使用过
DocumentApp.Attribute枚举吗?检查我的答案是否适合你。 -
我标记为重复,因为它与 docs api 中的
updateParagraphStyle请求基本相同。 -
大师您好——不一样的...他们是不同的属性?您可以在谷歌应用程序脚本中更新行距 - 但您不能添加我可以看到的边框?因此,这个问题的重点是您无法使用 Google Apps 脚本更新的属性(边框 - 不是行距)。而且它似乎不在 DOC API 中。除非你知道我不知道的东西——请你分享一下吗?非常感谢。
标签: javascript node.js google-apps-script google-docs google-docs-api