我有一份与会者名单。我想列出每一个,并在其后面添加两个要点,每个要点都有一个子项目符号。
我尝试了以下代码,但它列出了数组的元素,然后在末尾写入所有项目符号。
for (i = 0; i < attendees.length; i++) {
body.insertParagraph(5 + i, attendees[i])
body.insertListItem(6 + i, "One")
body.insertListItem(7 + i, "").setNestingLevel(1).setIndentStart(72)
.setGlyphType(DocumentApp.GlyphType.BULLET);
body.insertListItem(8 + i, "Two")
body.insertListItem(9 + i, "").setNestingLevel(1).setIndentStart(72)
.setGlyphType(DocumentApp.GlyphType.BULLET);
}
这就是我得到的:
One
Two
-
One
*
-
Two
*
-
One
*
-
Two
*
这就是我要的:
One
-
One
*
-
Two
*
Two
-
One
*
-
Two
*
这个修改怎么样?请将此视为几个可能答案之一。
修改后的脚本:
var offset = 5;
for (i = 0; i < attendees.length; i++) {
body.insertParagraph(offset + i, attendees[i]);
body.insertListItem(offset + i + 1, "One");
body.insertListItem(offset + i + 2, "").setNestingLevel(1).setIndentStart(72).setGlyphType(DocumentApp.GlyphType.BULLET);
body.insertListItem(offset + i + 3, "Two");
body.insertListItem(offset + i + 4, "").setNestingLevel(1).setIndentStart(72).setGlyphType(DocumentApp.GlyphType.BULLET);
offset += 4;
}
- 这个修改后的脚本假设
attendees
is ["One", "Two"]
.
- 在你的脚本中,
body.insertParagraph(5 + i, attendees[i])
用来。所以offset = 5
用来。如果您想将值放在正文的顶部,请使用offset = 0
.
参考:
- insertParagraph(childIndex, 文本) https://developers.google.com/apps-script/reference/document/body#insertparagraphchildindex,-text
- insertListItem(childIndex, 文本) https://developers.google.com/apps-script/reference/document/body#insertlistitemchildindex,-text
如果我误解了您的目标并且这不是您想要的方向,我深表歉意。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)