投稿

10月, 2020の投稿を表示しています

Google App Scriptでカレンダーからスプレッドシートに予定と時間を出力

 タイトルのまんまです。ちょっと仕事でラクしたいなと思って GAS にて準備しましたが、もう少し考えないといけない部分とかあったけど、基本部分は応用で使えそうなので置いておきます。 カレンダーに登録されている当日の予定をすべて引っこ抜いてきて日付名のシートをつけて出力するという内容です。シート出力済みの制御とか考えてなくて、1日1回スケジューラで実行する予定でしたが、ほかにも考えないといけないことが出てきたので少し考え直し中 ほとんど参考サイトのコピペですけどね。 ■ソースコード //カレンダーIDとスプレッドシートのURLを指定 const CALENDAR_ID = 'XXX'; const SHEET_URL = "https://docs.google.com/spreadsheets/d/XXXXX/edit#gid=X"; function main() { //カレンダー取得用日付設定 const n = 1; const d = new Date(); const todayStartTime = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0); const nd = d.setDate(d.getDate() + n, d.setHours(0), d.setMinutes(0), d.setSeconds(0)); const todayEndTime = new Date(nd); const nextdayEndTime = new Date(n2d); //カレンダーからタスク取得 const todayTasks = getCalendarEvents(todayStartTime, todayEndTime); const nextdayTasks = getCalendarEvents(todayEndTime, nextdayEndTime); //スプレッドシート書き出し const sheetname = todayStartTime.getFullYear() + '-' + t