Google apps script 使用谷歌应用程序脚本更改谷歌文档的背景色
我想使用Google Apps脚本更改整个文档的页面颜色。我不想更改段落的突出显示颜色。我想做的事情相当于去Google apps script 使用谷歌应用程序脚本更改谷歌文档的背景色,google-apps-script,google-docs,Google Apps Script,Google Docs,我想使用Google Apps脚本更改整个文档的页面颜色。我不想更改段落的突出显示颜色。我想做的事情相当于去文件>页面设置>页面颜色我相信你的目标如下 您想更改Google文档的背景色 您希望使用谷歌应用程序脚本实现这一点 我认为在这种情况下,有两种模式 模式1: 在此模式中,使用文档服务(DocumentApp)。示例脚本如下所示 示例脚本: 请将以下脚本复制并粘贴到Google文档的脚本编辑器中,然后运行函数myFunction。在此示例中,文档的背景设置为红色 function myF
文件>页面设置>页面颜色
我相信你的目标如下
- 您想更改Google文档的背景色
- 您希望使用谷歌应用程序脚本实现这一点
myFunction
。在此示例中,文档的背景设置为红色
function myFunction() {
const obj = {[DocumentApp.Attribute.BACKGROUND_COLOR]: "#ff0000"};
DocumentApp.getActiveDocument().getBody().setAttributes(obj);
}
function myFunction() {
const documentId = DocumentApp.getActiveDocument().getId();
const resource = { requests: [{ updateDocumentStyle: { documentStyle: { background: { color: { color: { rgbColor: { red: 1, green: 0, blue: 0 } } } } }, fields: "background" } }] };
Docs.Documents.batchUpdate(resource, documentId);
}
模式2:
在这个模式中,使用了googledocsapi。示例脚本如下所示
示例脚本:
请将以下脚本复制并粘贴到Google文档的脚本编辑器中,然后。然后,运行函数myFunction
。在此示例中,文档的背景设置为红色
function myFunction() {
const obj = {[DocumentApp.Attribute.BACKGROUND_COLOR]: "#ff0000"};
DocumentApp.getActiveDocument().getBody().setAttributes(obj);
}
function myFunction() {
const documentId = DocumentApp.getActiveDocument().getId();
const resource = { requests: [{ updateDocumentStyle: { documentStyle: { background: { color: { color: { rgbColor: { red: 1, green: 0, blue: 0 } } } } }, fields: "background" } }] };
Docs.Documents.batchUpdate(resource, documentId);
}
结果:
当使用上述两种图案时,得到以下结果
发件人:
致:
参考资料:
- 您想更改Google文档的背景色
- 您希望使用谷歌应用程序脚本实现这一点
- 我相信你的目标如下
myFunction
。在此示例中,文档的背景设置为红色
function myFunction() {
const obj = {[DocumentApp.Attribute.BACKGROUND_COLOR]: "#ff0000"};
DocumentApp.getActiveDocument().getBody().setAttributes(obj);
}
function myFunction() {
const documentId = DocumentApp.getActiveDocument().getId();
const resource = { requests: [{ updateDocumentStyle: { documentStyle: { background: { color: { color: { rgbColor: { red: 1, green: 0, blue: 0 } } } } }, fields: "background" } }] };
Docs.Documents.batchUpdate(resource, documentId);
}
模式2:
在这个模式中,使用了googledocsapi。示例脚本如下所示
示例脚本:
请将以下脚本复制并粘贴到Google文档的脚本编辑器中,然后。然后,运行函数myFunction
。在此示例中,文档的背景设置为红色
function myFunction() {
const obj = {[DocumentApp.Attribute.BACKGROUND_COLOR]: "#ff0000"};
DocumentApp.getActiveDocument().getBody().setAttributes(obj);
}
function myFunction() {
const documentId = DocumentApp.getActiveDocument().getId();
const resource = { requests: [{ updateDocumentStyle: { documentStyle: { background: { color: { color: { rgbColor: { red: 1, green: 0, blue: 0 } } } } }, fields: "background" } }] };
Docs.Documents.batchUpdate(resource, documentId);
}
结果:
当使用上述两种图案时,得到以下结果
发件人:
致:
参考资料: