【问题标题】:Submission timestamp of custom Form using Google Apps Script使用 Google Apps 脚本提交自定义表单的时间戳
【发布时间】:2014-10-05 02:40:27
【问题描述】:

我想创建一个包含图像上传字段的数据收集表单。我试过谷歌表单,它本身不支持文件上传,但我发现了这个例子:Form and file upload with htmlService and app script not working

我设法通过图片上传对其进行了配置,但是,原生 Google 表单在电子表格响应中确实有一个时间戳列。

我试过了:

var timestamp = theForm.getTimestamp();

但是没用……

如何获取响应时间戳?

代码摘录:

function processForm(theForm) {
  var fileBlob = theForm.myFile;
  var folder = DriveApp.getFolderById(folderId);
  var doc = folder.createFile(fileBlob);

  // Fill in response template
  var template = HtmlService.createTemplateFromFile('Thanks.html');

  var name = template.name = theForm.name;
  var email = template.email = theForm.email;
  var timestamp = template.timestamp = theForm.getTimestamp();

  // Record submission in spreadsheet
  var sheet = SpreadsheetApp.openById(submissionSSKey).getSheets()[0];
  var lastRow = sheet.getLastRow();
  var targetRange = sheet.getRange(lastRow+1, 1, 1, 5).setValues([[timestamp,name,department,message,email,fileUrl]]);

  // Return HTML text for display in page.
  return template.evaluate().getContent();
}

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    HTML 表单不会像 Google 表单那样在提交时自动将任何时间戳传递给服务器。您必须自己生成该时间戳。 new Date() 会做你想做的事:

    var timestamp = template.timestamp = new Date();
    

    如果您需要将此日期对象输出到页面中的屏幕,则需要通过格式化使其易于阅读。您可以使用Utilities.formatDate() method 来执行此操作。

    【讨论】:

    • 成功了,谢谢。但这不是客户端时间戳吗?
    • 否,.gs Google Apps 脚本文件在服务器上处理和执行,而不是在客户端的浏览器中。所以时间戳将是服务器时间戳。您应该确保您的 GAS 项目在菜单 File->Project properties 下的 Info 选项卡上选择了正确的时区。
    • 哦,谢谢你的信息。我对 GAS 没有经验。谢谢!
    猜你喜欢
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    相关资源
    最近更新 更多