(谷歌文档)如何基于某些输入变量创建自定义文档



当你有某种输入时,有没有办法让一段文字被吐出来,比如说谷歌问卷?

这样你就可以说有5个输入,它会把5段信息吐到一个文档中吗?

例如:

如果有人填写了一份第一个问题是出生年份的问卷,该工具会在第一段中列出他们出生年份的描述。

第二个问题是他们的出生国,该工具会在文件中放置一段关于他们出生国的文本。

等等

提前感谢的任何帮助

可以使用基于表单响应的特定条件创建文档。我使用谷歌应用程序脚本创建了以下示例脚本,这样你就可以得到这个想法:

function docCreation() {
var ss = SpreadsheetApp.getActive().getSheetByName("Form Responses 1");
var range = ss.getDataRange();
var values = range.getValues().reverse(); //reverses the array to get the last value in the first position
var doc = DocumentApp.create("Testing doc"); // You can change the name to match a username or any other variable instead
switch (getMonth(values[0][1].toString())) {
case 'Aug':
doc.getBody().appendParagraph("This is a sample body for August");
break;
case 'Jul':
doc.getBody().appendParagraph("This is a sample body for July");
break;
}
}
// Second function that returns the month value of the date introduced by the user
// I separated it because it is not that relevant to the main goal
function getMonth(val){
var month = val.split(" ");
return month[1];
}

这是一个非常简单的脚本,用于检查用户介绍的日期的月份是8月还是7月,如果是,它将创建一个以简单文本作为段落的文档。

该脚本与表单响应的Google表单绑定,您可以创建一个触发器,以便每次用户填写表单时,脚本都会开始运行以创建所需的文档。现在,正如我所提到的,这只是一个示例,逻辑和文档格式将取决于您的特定需求和用法。

参考文献:

  • 类主体
  • 创建文档

最新更新