我是Google Apps脚本的新手。我已经看过很多关于此的文章,但我想我仍然不知道如何编写本节的脚本:我有两张纸;一张纸是表单响应,另一张纸是表单信息,以通过Apps脚本来提供日历事件。
我想添加其他事件描述,为此添加的文本将通过以下方式在Google表格中给出:
=CONCATENATE("Offsite: ",$H2,CHAR(10),"Estimated Number of Spaces: ",$I2,CHAR(10),"Setup?: ",$J2,CHAR(10),"Time for Setup?: ",$K2,CHAR(10),"Other Supplies: ",$L2,CHAR(10),"How many of each?: ",$M2,CHAR(10), "Sound: ",$N2,CHAR(10),"Tech-Projector, Wifi, computer, Tech Setup: ",O2,CHAR(10),"Does this need to be posted on the School’s Public Calendar?: ",$P2,CHAR(10),"Marquee: ",$Q2,CHAR(10),"Weekly Newsletter?: ",$R2,CHAR(10),"Guests to Invite: ",$S2,CHAR(10),"My Email Address: ",$T2,CHAR(10)
因此产生的事件如下所示:
但是我需要将其写入我的Google脚本...
串联在工作表中起作用,但是一旦运行createEvent
函数,单元格就会失去串联。因此,我必须在每次提交表单后再次放入。
如何获取所有这些串联的单元格以及文本,并将其添加到我的Google脚本函数中?它将进入F列。
下面的脚本实际上是来自Stack Overflow!谢谢Mogsdad!
function exportEvents() {
var sheet = SpreadsheetApp.getActiveSheet();
var headerRows = 1; // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var data = range.getValues();
var calId = "calendar id";
var cal = CalendarApp.getCalendarById(calId);
for (i = 0; i < data.length; i++) {
if (i < headerRows) continue; // Skip header row(s)
var row = data[i];
var date = new Date(row[3]); // First column
var title = row[1]; // Second column
var tstart = new Date(row[2]);
tstart.setDate(date.getDate());
tstart.setMonth(date.getMonth());
tstart.setYear(date.getYear());
var tstop = new Date(row[3]);
tstop.setDate(date.getDate());
tstop.setMonth(date.getMonth());
tstop.setYear(date.getYear());
var loc = row[4];
var desc = row[5];
var id = row[6]; // Sixth column == eventId
// Check if event already exists, update it if it does
try {
var event = cal.getEventSeriesById(id);
} catch (e) {
// do nothing - we just want to avoid the exception when event doesn't exist
}
if (!event) {
//cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"), {description: desc, location: loc});
var newEvent = cal.createEvent(title, tstart, tstop, {description: desc, location: loc}).getId();
row[6] = newEvent; // Update the data array with event ID
} else {
event.setTitle(title);
event.setDescription(desc);
event.setLocation(loc);
// event.setTime(tstart, tstop); // cannot setTime on eventSeries.
// ... but we CAN set recurrence!
var recurrence = CalendarApp.newRecurrence().addDailyRule().times(1);
event.setRecurrence(recurrence, tstart, tstop);
}
debugger;
}
// Record all event IDs to spreadsheet
range.setValues(data);
}