问题描述
我正在尝试使用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脚本中定义它们。您只需要正确转换即可。在用户界面中,您使用英寸定义缩进长度。为了找到印刷点和英寸之间的精确换算,您可以google:
1 inch (UI) = 72 typographic points (Google Apps Script)