https://docs.google.com/document/d/1VrkXwfR24nIkX9KEGquIqFgkqPAke6MDst_N7YgSOY0/edit?usp=sharing
这是一个示例文档 我想做的是自动按下流程:格式>段落>边框和阴影>重置
目标是重置文档白色背景,这显然是通过边框和阴影完成的
所以总而言之,我想: 1.创建代码 2.在谷歌应用程序脚本上运行代码并查看它是否有效 3.将其添加为附加内容让我们重点关注1-2
我尝试过:
我尝试过:
function resetParagraphFormatting() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var paragraphs = body.getParagraphs();
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs[i];
paragraph.setAttributes({
"BORDER_WIDTH": 0,
"BORDER_COLOR": null,
"BACKGROUND_COLOR": null
});
}
}
我们在操作脚本中执行,但当我运行它时它不会影响文档。
我认为在您使用 Google Docs API 的情况下,脚本可能很简单。因此,在这个答案中,我想建议使用 Google Docs API 来实现您的目标。示例脚本如下。
在使用此脚本之前,请在高级 Google 服务中启用 Google Docs API。
function resetParagraphFormatting() {
const docId = DocumentApp.getActiveDocument().getId();
const obj = Docs.Documents.get(docId).body.content;
Docs.Documents.batchUpdate({ requests: [{ updateParagraphStyle: { range: { startIndex: 1, endIndex: obj.pop().endIndex }, fields: "borderBetween,borderBottom,borderTop,borderLeft,borderRight,shading", paragraphStyle: {} } }] }, docId);
}
运行此脚本时,“边框和阴影”的属性将重置如下。
spaceAbove,spaceBelow
的字段包含到fields: "borderBetween,borderBottom,borderTop,borderLeft,borderRight,shading"
中。