【问题标题】:How can I change onlyOnWeekday(day) with weekday from Google Sheets?如何在 Google 表格中将 onlyOnWeekday(day) 更改为工作日?
【发布时间】:2020-03-01 19:46:48
【问题描述】:

我可以让这个例子example 工作。我需要的是从“工作日”列中的单元格设置工作日。

我试过这个:

if(type=='PD'){
  var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(weekday);
  event.setRecurrence(recurrence, tstart, tstop);
}else

...其中 weekday 指的是“weekday”列。

我在my own version 做错了什么?

【问题讨论】:

    标签: google-apps-script google-sheets google-calendar-api google-calendar-recurring-events


    【解决方案1】:

    我可以从您的脚本和共享电子表格中确认,NewWeekday 的值是字符串类型的WEDNESDAYMONDAY。既然如此,那么下面的修改呢?

    发件人:

    var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(weekday);
    event.setRecurrence(recurrence, tstart, tstop);
    

    收件人:

    var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday[NewWeekday]);  // Modified
    event.setRecurrence(recurrence, tstart, tstop);
    

    参考资料:

    如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

    补充:

    • 您想将tstop 用作“直到”。

    为此,下面的修改如何?

    发件人:

    var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(weekday);
    event.setRecurrence(recurrence, tstart, tstop);
    

    收件人:

    var recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday[NewWeekday]).until(tstop);  // Modified
    event.setRecurrence(recurrence, tstart);  // Modified
    

    【讨论】:

    • 真的很接近 :-) 括号有效。不过有两件事; 1) 脚本将第一个事件放在开始日期,即使这不是星期一或星期三。 2)没有停止:-)事件持续多年......
    • 也许 .times(times) 固定 2).
    • @Allan Bech 感谢您的回复。我带来的不便表示歉意。关于There is no stop :-) Events keep on for years...,您想将tstop 用作“直到”。如果我的理解是正确的,您能否确认添加的修改?关于The script puts first event on the startdate even if this is not a monday or wednesday.Maybe .times(times) fixed 2).,我不明白你想做什么。这是因为我的英语水平不好。我对此深表歉意。能详细介绍一下吗?
    • 我可以确认 [tstop] 在 .until 中有效。谢谢你。我也尝试了 .times([times]) 并且它也有效。剩下的挑战:如果我在星期日为星期一和星期三创建活动,那么第一次出现将在这些星期日。
    • @Allan Bech 感谢您的回复。我很高兴你的问题得到了解决。关于你If I create events for i.e. MONDAYS and WEDNESDAYS on a SUNDAY, the first appearences will be on those sundays. 的新问题,很遗憾,我无法理解你想要做什么。这是因为我的英语水平不好。我对此深表歉意。可以提供一下细节吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 1970-01-01
    • 2018-12-31
    • 2020-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多