首页 > 解决方案 > 可以以编程方式修改现有的 Google 文档表单吗?

问题描述

我有一个预先存在的表单,以交互方式创建。看来(根据我的实验)如果以编程方式创建表单可以以编程方式修改,但如果以交互方式创建则不能。

背景涉及维护:如果表单/电子表格所有者想要修改表单,正确更新相关的选项卡/工作表是他们头上的事。有一些复选框列表需要随着时间的推移而更新。我正在编写一个脚本,用户可以在其中为复选框项目添加标签,它会根据需要更新所有选项卡/工作表......但我试图在表单中添加一个复选框。

“var form = FormApp.getActiveForm();” 只返回空值。“openById”和:

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var form = FormApp.openByUrl(ss.getFormUrl());

似乎可以工作,但是当我遍历“表单”时,我得到了一些奇怪的结果。例如:

for each (var i in form.getItems(FormApp.ItemType.CHECKBOX)) { 
    Logger.log(i);
    for each (var j in i) {
      Logger.log(j);
    }
}

虽然“表单”包含许多“项目”对象,但每个项目似乎都包含 Item 类的源代码:

> [19-03-15 07:53:57:329 HST] Item 
> [19-03-15 07:53:57:330 HST] function asPageBreakItem() {/*
> */} [19-03-15 07:53:57:331 HST] function asParagraphTextItem() {/*
> */} [19-03-15 07:53:57:331 HST] function getHelpText() {/*
> */} [19-03-15 07:53:57:332 HST] function getIndex() {/*
> */} [19-03-15 07:53:57:332 HST] function asTimeItem() {/*
> */} [19-03-15 07:53:57:332 HST] function asImageItem() {/*
> */} [19-03-15 07:53:57:333 HST] function asScaleItem() {/*
> */} [19-03-15 07:53:57:333 HST] function getId() {/*
> */} [19-03-15 07:53:57:333 HST] function asMultipleChoiceItem() {/*
> */} [19-03-15 07:53:57:334 HST] function getTitle() {/*
> */} [19-03-15 07:53:57:334 HST] function asGridItem() {/*
> */} [19-03-15 07:53:57:335 HST] function asDurationItem() {/*
> */} [19-03-15 07:53:57:335 HST] function asVideoItem() {/*
> */} [19-03-15 07:53:57:335 HST] function asTextItem() {/*
> */} [19-03-15 07:53:57:336 HST] function asDateTimeItem() {/*
> */} [19-03-15 07:53:57:336 HST] function setTitle() {/*
> */} [19-03-15 07:53:57:337 HST] function duplicate() {/*
> */} [19-03-15 07:53:57:337 HST] function asCheckboxItem() {/*
> */} [19-03-15 07:53:57:337 HST] function setHelpText() {/*
> */} [19-03-15 07:53:57:338 HST] function asDateItem() {/*
> */} [19-03-15 07:53:57:338 HST] function getType() {/*
> */} [19-03-15 07:53:57:339 HST] function asSectionHeaderItem() {/*
> */} [19-03-15 07:53:57:339 HST] function toString() {/*
> */} [19-03-15 07:53:57:339 HST] function asCheckboxGridItem() {/*
> */} [19-03-15 07:53:57:340 HST] function asListItem() {/*
> */}

希望我刚刚离开杂草,我可以修改现有的复选框......有人可以指出我正确的方向吗?

标签: google-apps-scriptgoogle-forms

解决方案


您是否考虑过在电子表格中维护选项卡列表,然后从电子表格中填充表单?


推荐阅读