【发布时间】:2015-05-26 19:06:53
【问题描述】:
我已经创建(找到并稍微编辑)了一个在线脚本,该脚本从谷歌表单中获取响应,将答案发送到工作表中,然后根据静态时间戳创建日历事件。
代码运行良好。还有一个循环可以防止我没有显示的重复预订。
下一步是创建一个循环/if/and 语句,允许我在表单中添加多次,允许员工(我是教师)选择时间段,或者他们想要的多个时间段检查一件设备。
我会附上脚本的图片,但不能 b/c 我是 stackoverflow 的新手。所以这是我能在不让帖子太长的情况下给出的最好的。
原来的...
//For loop processes the entries one row at a time.
for (var i = 0; i < myData.length; ++i)
{
var row = myData[i]; //ith row of data
if(row[0]=="") //row[0] is the entry in the "Timestamp" column (i.e. the first, or index 0 column)
{
i=myData.length //when the timestamp column is empty, you've reached the end of the data, so this jumps you out of the loop
}
else
{
var timestamp = row[0]; //timestamp of the entry (stored as a javascript Date object)
var event_name = "Laptop - Cart 2"; // Second column (first column has timestamp), stores the name of the event as a string.
var start_date = row[3]; // Date for the start of the event (stored as a javascript Date object)
var startDt = new Date();// Time for the start of the event (stored as a javascript Date object)
startDt.setHours(08);
startDt.setMinutes(30);
var end_date;
if(row[4]=="") //if this column is blank, the end date is set to the start date, otherwise the end date is stored.
{end_date=row[3];}
else
{end_date=row[4];} //if this column is blank, the end date is set to the start date, otherwise the end date is stored.
var end_time = new Date();
end_time.setHours(15);
end_time.setMinutes(30);
var location = row[5] ; // Location of the event stored as a string
var description = row[7]; // Description of the event stored as a string
var email_address = row[1]; //Email address of the user stored as a string
我希望更改的内容..注意第 3 行和第 4 行时间戳的变化
var start_time = row [3]
var startDt = new Date();// Time for the start of the event (stored as a javascript Date object)
startDt.setHours(08);
startDt.setMinutes(30);
var end_time = new Date();
end_time.setHours(11);
end_time.setMinutes(30);
var start_time = row [4]
var startDt = new Date();// Time for the start of the event (stored as a javascript Date object)
startDt.setHours(11);
startDt.setMinutes(45);
var end_time = new Date();
end_time.setHours(15);
end_time.setMinutes(30);
我的问题是脚本只读取第二组值。日历事件仅使用第 4 行开始和结束时间创建事件。我需要编写哪种类型的语句才能在日历上获取这两个事件,而无需为每个可用时间段创建单独的表单。一天有 11 个课时。
【问题讨论】:
标签: javascript google-apps-script google-sheets google-calendar-api