我的Google Apps脚本代码存在问题。 我试图让它在我的工作表的一行上获取信息并创建一个单独的日历事件,包括开始和结束时间。
//push new events to calendar
function pushToCalendar() {
//spreadsheet variables
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
var range = sheet.getRange(2,1,lastRow,16);
var values = range.getValues();
var numValues = 0;
for (var i = 0; i < values.length; i++) {
//check to see if Age, Competition, Start Date, Start Time and End Date & Time are filled out
if ((values[i][0].length == '<>') && (values[i][1].length == '<>') && (values[i][4].length == '<>') && (values[i][5].length == '<>') && (values[i][6].length == '<>') && (values[i][7].length == '<>')) {
//check if it's been entered before
if ((values[i][8] == '')||(values[i][8] == null)) {
//create event https://developers.google.com/apps-script/class_calendarapp#createEvent
var newEventTitle = 'Game: ' + values[i][0] + ' - ' + values[i][1];
var startDay = Utilities.formatDate(new Date(values[i][3]), 'America/Chicago', 'MMMM dd, yyyy');
var startTime = Utilities.formatDate(new Date(values[i][4]), 'America/Chicago', 'HH:mm');
var start = startDay + ' ' + startTime;
var endDay = Utilities.formatDate(new Date(values[i][5]), 'America/Chicago', 'MMMM dd, yyyy');
var endTime = Utilities.formatDate(new Date(values[i][6]), 'America/Chicago', 'HH:mm');
var end = endDay+ ' ' + endTime;
var newEvent = CalendarApp.getDefaultCalendar().createEvent(newEventTitle, new Date(start), new Date(end), {location: values[i][12]});
//get ID
var newEventId = newEvent.getId();
//mark as entered, enter ID
sheet.getRange(i+2,8).setValue(newEventId);
} //could edit here with an else statement
}
numValues++;
}
}
我在前3列中有相关信息(在事件标题中使用),在第4列中有开始日期,第5列中为开始时间,第6列中有结束日期,第7列中有结束时间。其他列包含我将添加到事件描述中的信息。
我主要遇到的问题是将数据集过滤到尚未推送到日历的事件,以及一旦事件推动事件就准确记录的脚本,这样它就能够在脚本的下一个循环中过滤它。
如果您需要我提供更多信息,请与我们联系。
提前感谢您的帮助! 亚当
答案 0 :(得分:0)
我修改了一些代码但不多。这里是。我能够在日历上获得所有六个事件而几乎没有变化。
function pushToCalendar() {
//spreadsheet variables
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
var range = sheet.getRange(2,1,lastRow,16);
var values = range.getValues();
var numValues = 0;
for (var i = 0; i < values.length; i++) {
//check to see if Age, Competition, Start Date, Start Time and End Date & Time are filled out
if ((values[i][0]) && (values[i][1]) && (values[i][4]) && (values[i][5]) && (values[i][6]) && (values[i][7]))
{
//check if it's been entered before
if (!values[i][8])
{
//create event https://developers.google.com/apps-script/class_calendarapp#createEvent
var newEventTitle = 'Game: ' + values[i][0] + ' - ' + values[i][1];
var startDay = Utilities.formatDate(new Date(values[i][4]), 'GMT-5', 'MMMM dd, yyyy');
var startTime = Utilities.formatDate(new Date(values[i][5]), 'GMT-5', 'HH:mm');
var start = startDay + ' ' + startTime;
var endDay = Utilities.formatDate(new Date(values[i][6]), 'GMT-5', 'MMMM dd, yyyy');
var endTime = Utilities.formatDate(new Date(values[i][7]), 'GMT-5', 'HH:mm');
var end = endDay+ ' ' + endTime;
var newEvent = CalendarApp.getDefaultCalendar().createEvent(newEventTitle, new Date(start), new Date(end), {location: values[i][12]});
//get ID
var newEventId = newEvent.getId();
//mark as entered, enter ID
sheet.getRange(i+2,9).setValue(newEventId);//Why i+2
} //could edit here with an else statement
}
numValues++;
}
}
这是我的测试数据。
Title1 Title2 startDay startTime endDay endTime completed Location
Event1 Day1 4/1/2017 10:00 AM 4/1/2017 2:00 PM sbcfnqdevvc16vs4q237k6udnk@google.com Denver
Event1 Day2 4/2/2017 10:00 AM 4/2/2017 2:00 PM oj8ui4m5h3jcpqmj7ev10ih91k@google.com Honolulu
Event1 Day3 4/3/2017 10:00 AM 4/3/2017 12:00 PM n6fro1u4rcgieu6720ujudents@google.com San Francisco
Event2 Day1 4/4/2017 10:00 AM 4/4/2017 2:00 PM kq3m6cel3jg5j6kiljtlvhgppg@google.com Denver
Event2 Day2 4/5/2017 10:00 AM 4/5/2017 2:00 PM nbmfsb9bar5ucsvgaddqsbvss8@google.com Honolulu
Event2 Day3 4/6/2017 10:00 AM 4/6/2017 12:00 PM p7kc6p82gbvf94terd6cl1aiuo@google.com San Francisco
答案 1 :(得分:0)
我得到了它的工作。我最初在值检查行中引用了错误的列。傻我。
LINE='include "/configs/projectname.conf"'
FILE=lighttpd.conf
grep -qF "$LINE" "$FILE" || echo "$LINE" | sudo tee --append "$FILE"