【问题标题】:Give every question in a Google-Form an unique id为 Google-Form 中的每个问题提供一个唯一的 ID
【发布时间】:2021-12-06 18:44:20
【问题描述】:

我想使用 Google Apps 脚本制作 Google 表单。表单中的问题来自 Google 表格,其中包含问题的 ID 和文本。提交表单并将问题导出到工作表时,列名是文本形式的问题。我宁愿使用基于我自己的 Google 表格中的列的唯一 ID 替换它们,其中问题也存储为文本。

我该如何解决这个问题?

【问题讨论】:

  • 添加提交表单的日期/时间戳(作为隐藏字段)
  • 从问题的文本和 id 构建一个哈希表,以非常快速地将问题转换为 id。

标签: google-apps-script google-sheets google-forms


【解决方案1】:

将问题文本构建到 ID 哈希表

function hashtable() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet0');
  let texttoid = {};
  sh.getDataRange().getDisplayValues().forEach(r => texttoid[r[1]]=r[0]);
  Logger.log(JSON.stringify(texttoid));
}

Execution log
11:58:17 AM Notice  Execution started
11:58:18 AM Info    {"text1":"id0","text2":"id1","text3":"id2","text4":"id3","text5":"id4","text6":"id5","text7":"id6","text8":"id7","text9":"id8","text10":"id9","text11":"id10"}
11:58:18 AM Notice  Execution completed

工作表0:

id0 text1
id1 text2
id2 text3
id3 text4
id4 text5
id5 text6
id6 text7
id7 text8
id8 text9
id9 text10
id10 text11

您可以转到Google Apps Script Reference 并使用搜索框查找您不了解的任何功能。如果它是纯 JavaScript 函数,请转到 here

如果希望重复使用哈希表,可以将哈希表存储在缓存中,以节省每次从电子表格构建它的时间。

【讨论】:

    猜你喜欢
    • 2020-06-13
    • 2015-07-29
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    相关资源
    最近更新 更多