google-apps-script - 如何在谷歌表单中预填日期
问题描述
我正在尝试在谷歌表单中预先填写日期。所以它将把它填充的日期作为默认值。
我尝试在 google sheet 中使用 TODAY() 函数。所以我更改了网址以从谷歌表格中的单元格获取日期。适用于除日期以外的所有内容..
https://docs.google.com/forms/d/e/1FAIpQLSf7cdT34eHp-GXagq3DsnxX1MD_c-G6lbF6yFWOMnUvtPYUUQ/viewform?entry.178275308=**&A6&**
知道如何以最简单的方式做到这一点吗?
解决方案
我以 ziganotschka 的代码为基础,但我必须进行一些更改,也许它可以帮助某人:
function doGet(){
//open your form open by URL
var form = FormApp.openByUrl('https://docs.google.com/forms/d/1M-zgHyDOz2ob5StkwIoDCShJ9tePw-I5TGhdx/prefill')
//get the questions
var questions = form.getItems();
//get the question where you want to prefill the date as an answer, e.g. first question
var question1=questions[0];
//get the current date
var time=new Date();
// prefill form with current date
var prefilledTime=form.createResponse().withItemResponse(question1.asDateItem().createResponse(time));
// Get the link to the prefilled form
var URL=prefilledTime.toPrefilledUrl();
// redirect to the prefilled form URL dynamically created above
return HtmlService.createHtmlOutput("<script>window.top.location.href=\"" + URL + "\";</script>");
}
完成后,不要忘记发布 -> 部署为 Web 应用程序...
推荐阅读
- c - 使用 GCC 在 C 中编译扩展程序集
- javascript - Vue.js - 从过滤的 scopedSlots 动态创建插槽
- gitlab - gitlab-runner 错误:准备失败:VBoxManageOutput 错误:VBoxManage:错误:找不到名为的注册机器
- python - 来自python的url请求被服务器“阻止”
- sql - oracle建表的时候可以动态改变column的数据类型吗?
- html - 为什么引导卡不能并排对齐
- java - 由于媒体播放器在后台播放,我收到 NullPointerException
- reactjs - 在反应中,下拉元素有时不会出现
- php - @if 语句不起作用
- batch-file - 批处理文件:`Do call :Process`