【问题标题】:Prefill current date in Google Form with Google Apps Script使用 Google Apps 脚本在 Google 表单中预填当前日期
【发布时间】:2016-12-16 00:14:21
【问题描述】:

我有一个电子表格的 Google 表单,我需要一个预先填写当前日期的日期字段。

类似于"onOpen trigger",它使用 now() 更新日期字段或日期字段。

这在 Google Apps 脚本中可行吗?

【问题讨论】:

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


【解决方案1】:

我在 S3 上放置了一个静态 HTML 页面,其中包含几行用于重定向的 Javascript。见https://jsfiddle.net/barryku/3etd8qf0/

var formId = "1FAIpQLSc_acGSzp2VeJIyG0tNJwqcNdUPOweLROGenY0Fe56I635VGQ";
var dateField = "entry.1608430301";
var formsUrl = "https://docs.google.com/forms/d/e/"+ formId + "/viewform?usp=pp_url&" + dateField + "=$$today&entry.747437339=Yes";

var today = new Date();
var redirectUrl = formsUrl.replace("$$today", new Date(today.getTime() - (today.getTimezoneOffset() * 60000)).toISOString().split('T')[0]);
window.location.replace(redirectUrl);

【讨论】:

  • 您能否详细说明如何实现这一点?当表单加载或在重定向到表单的另一个页面上运行时,您是否调用 Javascript?
【解决方案2】:

就您而言,使用表单的一些要点仍不清楚。假设您能够编辑表单的链接,或者您的用户同意将bookmarklet 添加到他们的浏览器。

常用代码

let id='1FAIpQLScx-1H1moCzBfkTEOZnVgBScbJeHZ4YE5E6IY2mNZvMuVcOXA';
window.open(
  `https://docs.google.com/forms/d/e/${id}/viewform?usp=pp_url&entry.1000000=`+
  (new Date()).toISOString().split('T')[0]
);

书签

只需将下一个字符串添加到书签栏

javascript:let id = '1FAIpQLScx-1H1moCzBfkTEOZnVgBScbJeHZ4YE5E6IY2mNZvMuVcOXA'; window.open(`https://docs.google.com/forms/d/e/${id}/viewform?usp=pp_url&entry.1000000=` + (new Date()).toISOString().split('T')[0]);

【讨论】:

  • 在花费至少 2 小时搜索和创建应用脚本后,我认为这是有史以来最好的解决方案!
猜你喜欢
  • 2015-10-03
  • 1970-01-01
  • 1970-01-01
  • 2018-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多