【问题标题】:looping google sheets into multiple calendar events将谷歌表格循环到多个日历事件中
【发布时间】: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


    【解决方案1】:

    您在添加的两个代码块中为 row[3] 和 row[4] 分配了两个不同的值。

    假设 row[3] 和 row[4] 是一天中的时间(不是日期值),第二个代码块中的问题是在将 row[3] 值分配给 start_time 变量并覆盖它之后立即使用 row[4] 的值。

    根据我对您的要求的理解,我看到您想为同一位老师创建多个日历事件多个时段。在这种情况下,如果周期的开始时间作为值存储在与 row[3]、row[4].. 相同的行中,您应该首先为 row[3] 创建一个日历事件,然后为行 [4] 值。

    希望有帮助!

    【讨论】:

    • 这是我的问题。我无法弄清楚如何通过单击表单来创建多个事件。我试图复制并通过整个脚本并将其翻倍,希望它首先创建事件“A”,然后创建事件“B”,但这没有用。似乎我需要在谷歌表单上创建具有相同时间戳的第二行来创建第二个事件。如果可以更轻松地查看我的问题,我可以复制并粘贴完整版本的脚本。同样,我只是一个新手,感谢我得到的任何帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多