Google Header 部分的脚本换行符

Google Script Line Break on Section Header

我目前正在为 Google 脚本创建换行符。我设法为标题和里面的内容创建了一个换行符。但是,当我尝试为新的 header 标题创建换行符时。我找不到新章节标题的属性或变量,有谁知道如何调出它的变量吗?

前面的标题可以用

调用
var mainTitle = form.getTitle();

并且可以使用

调用文本变量
var title = questions[i].getTitle();

有人知道新章节标题的标题变量吗?

基于 liquidkat 的评论,您可以查看 Google 表单应用程序脚本 documentation

表格由组成。您可以通过在表单上调用 getItems() 来获取列表。

  let myform = FormApp.openById("...")
  let items = myform.getItems() //an array with all the items

  for (i in items){
    console.log(items[i].getTitle()) // will list the titles of all the items
  }

要缩小搜索范围,您还可以通过 itemType 获取项目。您的屏幕截图似乎是 PAGE_BREAK 项目,所以这里有一个示例:

  let myform = FormApp.openById("...")
  let items = myform.getItems(FormApp.ItemType.PAGE_BREAK) //an array with only page breaks

请注意,将对象检索为 Item 仅具有所有项目类型共享的属性。如果要访问特定于特定项目类型的属性,则必须将其强制转换为该类型。这是来自 Google:

的示例
// Create a new form and add a text item.
var form = FormApp.create('Form Name');
form.addTextItem();

// Access the text item as a generic item.
var items = form.getItems();
var item = items[0];

// Cast the generic item to the text-item class.
if (item.getType() == 'TEXT') {
  var textItem = item.asTextItem();
  textItem.setRequired(false);
}

您可能已经注意到,表单开头的第一部分并不算真正的项目之一,您可以使用 myform.getTitle().

进行检查

参考: