Javascript 将google工作表循环到多个日历事件中
我在网上创建了一个脚本(找到并稍加编辑),它从谷歌表单中获取响应,将答案发送到一张工作表中,然后根据静态时间戳创建日历事件 代码运行得很好。还有一个循环,以防止双重预订,我没有显示 下一步是创建一个循环/if/and语句,允许我在表单中添加多次,允许工作人员(我是一名教师)选择时段,或者在他们想要检查一件设备时选择多个时段 我想附上脚本的图片,但无法b/c我是stackoverflow的新手。因此,这里是最好的,我可以给不使职位太长 原来的Javascript 将google工作表循环到多个日历事件中,javascript,google-apps-script,google-sheets,google-calendar-api,Javascript,Google Apps Script,Google Sheets,Google Calendar Api,我在网上创建了一个脚本(找到并稍加编辑),它从谷歌表单中获取响应,将答案发送到一张工作表中,然后根据静态时间戳创建日历事件 代码运行得很好。还有一个循环,以防止双重预订,我没有显示 下一步是创建一个循环/if/and语句,允许我在表单中添加多次,允许工作人员(我是一名教师)选择时段,或者在他们想要检查一件设备时选择多个时段 我想附上脚本的图片,但无法b/c我是stackoverflow的新手。因此,这里是最好的,我可以给不使职位太长 原来的 //For loop processes the
//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
我的问题是脚本只读取第二组值。日历事件仅使用第4行开始和结束时间创建事件。我需要写什么类型的语句才能在日历上获取这两个事件,而不需要为每个可用时间段创建单独的表单。一个上学日有11个课时。您正在为添加的两个代码块中的第[3]行和第[4]行指定两个不同的值 假设第[3]行和第[4]行是一天中的时间(不是日期值),第二个代码块中的问题是,在将第[3]行的值分配给
start\u time
变量并立即用第[4]行覆盖该值之后
根据我对您要求的理解,我发现您希望为同一位教师创建多个日历事件,用于多个时段。在这种情况下,如果时段的开始时间作为值存储在与第[3]行、第[4]行相同的行中。。您应该首先为第[3]行创建日历事件,然后为第[4]行值创建另一个日历事件
希望有帮助 这是我的问题。我不知道如何在一次单击表单时创建多个事件。我试着复制整个脚本并将其翻倍,希望它先创建事件“A”,然后创建事件“B”,但这不起作用。似乎我需要在google表单上创建第二行,使用相同的时间戳来创建第二个事件。如果脚本的完整版本更容易看到我的问题,我可以复制并超过它。再说一次,我只是个新手,非常感谢你对我的帮助。
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);