我正在使用google apps script
为电子表格添加插件,其中电子表格数据将用于在Google日历中创建活动。一切正常,除非我从我的测试插件运行代码,事件由于某种原因没有在日历中添加。但是,如果我从我的脚本运行代码,那么它工作正常。这是我的代码,
function createEvent(date, start_time, end_time, event_title)
{
var dateCol = 0;
var startCol = 0;
var endCol = 0;
var titleCol=0;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getActiveSheet();
var lr = dataSheet.getLastRow()-1;
var lc = dataSheet.getLastColumn();
var rng = dataSheet.getRange(1, 1, 1, lc).getValues();
// This will match the column corresponsing to our selected value in dropdown from html sidebar.
for (var i=0; i < rng[0].length; i++)
{
if (date == rng[0][i]) {
dateCol = i;
}
if (start_time == rng[0][i]) {
startCol = i;
}
if (end_time == rng[0][i]) {
endCol = i;
}
if (event_title == rng[0][i]) {
titleCol = i;
}
}
// This part handles the creating of an event in calendar
var getUser = Session.getEffectiveUser().getUserLoginId();
var getCal = CalendarApp.getCalendarById(getUser);
var data_rng = dataSheet.getRange(2, 1, lr, lc).getValues();
for (var j=0; j < data_rng.length; j++)
{
var getDate = new Date(data_rng[j][dateCol]);
var getDate2 = new Date(data_rng[j][dateCol]);
var getStart =new Date(data_rng[j][startCol]);
var getEnd = new Date(data_rng[j][endCol]);
getDate.setHours(getStart.getHours());
getDate.setMinutes(getStart.getMinutes());
getDate2.setHours(getEnd.getHours());
getDate2.setMinutes(getEnd.getMinutes());
var title = data_rng[j][titleCol];
getCal.createEvent(title, getDate, getDate2);
}
}
我是否需要做其他事情才能让它在插件上运行?如何让CalendarApp在插件上运行?急需这个帮助!感谢。