道歉,如果這已被覆蓋,但我想寫一個谷歌表單的腳本,當完成後會發送'事件'我的谷歌日曆。我希望這些活動能夠成爲全天活動,但我可以最接近地完成這項工作,但我仍然可以在00:00得到時間......任何人都可以幫忙嗎?谷歌腳本創建全天日曆條目
///this is the ID of the calendar to add the event to, this is found on the calendar settings page of the calendar in question
var calendarId = "[email protected]";
//below are the column ids of that represents the values used in the spreadsheet (these are non zero indexed)
var startDtId = 4;
var endDtId = 5;
var titleId = 2;
var descId = 3;
var formTimeStampId = 1;
function getLatestAndSubmitToCalendar() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var lr = rows.getLastRow();
var startDt = sheet.getRange(lr,startDtId,1,1).getValue();
//set to first hour and minute of the day.
startDt.setHours(0);
startDt.setMinutes(00);
var endDt = sheet.getRange(lr,endDtId,1,1).getValue();
//set endDt to last hour and minute of the day
endDt.setHours(23);
endDt.setMinutes(59);
var subOn = "Submitted on :"+sheet.getRange(lr,formTimeStampId,1,1).getValue();
var desc = "Added by :"+sheet.getRange(lr,descId,1,1).getValue()+"\n"+subOn;
var title = sheet.getRange(lr,titleId,1,1).getValue()
createEvent(calendarId,title,startDt,endDt,desc);
}
function createEvent(calendarId,title,startDt,endDt,desc) {
var cal = CalendarApp.getCalendarById(calendarId);
var start = new Date(startDt);
var end = new Date(endDt);
var loc = '';
var event = cal.createEvent(title, start, end, {
description : desc,
location : loc
});
};
請格式化這個問題的代碼。 – Joseph
使用[debugger](https://developers.google.com/apps-script/troubleshooting#using_the_debugger_and_breakpoints)並逐句通過代碼。我們不知道從電子表格中檢索的值或值類型。在調試器中,它將顯示值類型。調試窗口應顯示日期值是日期類型。我不明白將開始時間設置爲「00:00」的意義嗎?你有沒有試過將它設置爲午夜1分鐘? –