如何从应用程序脚本设置 Google 文档页面布局

问题描述 投票:0回答:1

有没有办法使用应用程序脚本将 Google 文档页面布局设置为横向。

我有一个脚本可以将 Google 电子表格复制到 Google 文档,但它太宽而无法正确显示。如果我可以将布局更改为横向,它将正确显示。

无论页面是纵向还是横向,页面宽度似乎都是相同的数字。

另一个问题是,如果我将 body.setPageWidth(792).setPageHeight(612) 用于字母,它会更改页面宽度和高度,但不会更改为横向。

google-apps-script google-docs google-docs-api
1个回答
0
投票

我相信您的目标如下。

  • 您想要使用 Google Apps 脚本更改横向和纵向之间的页面布局。

遗憾的是,现阶段文档服务(DocumentApp)似乎还无法实现这一点。但幸运的是,当使用 Google Docs API 时,这是可以实现的。在这种情况下,下面的示例脚本怎么样?

示例脚本:

在使用此脚本之前,请在高级 Google 服务中启用 Google Docs API。

function myFunction() {
  const docId = DocumentApp.create("sampleFilename").getId(); // or please manually set the document ID.
  Docs.Documents.batchUpdate({ requests: [{ updateDocumentStyle: { documentStyle: { flipPageOrientation: true }, fields: "flipPageOrientation" } }] }, docId);
}
  • 运行此脚本时,将创建具有横向页面布局的 Google 文档。
  • 如果您想将页面布局设置为“横向”,请使用
    flipPageOrientation: true
  • 如果您想将页面布局设置为“纵向”,请使用
    flipPageOrientation: false

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.