Google 文档中的缩进段落 - Google Apps 脚本

Indent Paragraph in a Google Document - Google Apps Script

我正在尝试使用 Google Apps 脚本缩进一个段落 - 只是一个正常的缩进。这应该是世界上最简单的事情,但事实证明却非常令人沮丧。

下面是我正在调用的代码的相关部分,请记住我所做的其他所有事情(下划线、设置粗体等)都运行良好。

function AppendDocument(){
    var doc = DocumentApp.openById('____________________');
    var body = doc.getBody();
    var myParagraph = body.appendParagraph("Hello This is a paragraph - I want to indent this please");
    myParagraph.setUnderline(true); //<-- Things like this work fine
    myParagraph.setIndentStart(72.0); //I just randomly chose 72. No number is working.
}

您需要定义所有缩进参数:

myParagraph.setIndentFirstLine(72);
myParagraph.setIndentStart(72);
myParagraph.setIndentEnd(72*2);

请记住,您传递的参数是 印刷点数 。请参阅下面为什么我使用 72 作为基数。


如果您点击此处的标识选项:

您将看到如何通过 UI:

定义缩进选项

然后您可以了解如何在 Google Apps 脚本中定义它们。您只需要正确转换即可。在 UI 中,您使用英寸定义缩进长度。为了找到印刷点和英寸之间的精确换算,您可以 google 它:

1 inch (UI) = 72 typographic points (Google Apps Script)