1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

スプレッドシートのタスク管理表から締め切りをメールでリマインドする

Last updated at Posted at 2017-11-08
function myFunction() {
     var mySs = SpreadsheetApp.getActiveSpreadsheet(); //スプレッドシートを取得 
    var Sheet = mySs.getSheetByName('シート名'); // シート名を取得 
    var mySheet = SpreadsheetApp.getActiveSheet(); //シートを取得
    var today = new Date(); //今日の日付を取得
    var strTo = "mail-address"; //To
    var strFrom = "mail-address"; //From

    /* 繰り返し計算 */
    for (var i = 150; i <= 200; i++) {
        var task_name = Sheet.getRange(i, 4).getValue(); //内容を取得
        var task_end_date = Sheet.getRange(i, 7).getValue(); //タスクの期限を取得
        var task_status = Sheet.getRange(i, 8).getValue(); //タスクのステータス
        var dateDi = new Date(task_end_date); //タスク期限のDateを生成
        var dt = dateDi.getTime() - today.getTime(); //dateDiから今日の日付を引く
        var day = Math.ceil(dt / 1000 / 60 / 60 / 24);  //日付に変換
      
        if (task_status == "完了") /* task_status列が完了なら何もしない */;
        else if (task_status == "対応中") /* task_status列が完了なら何もしない */;
 
        else if (0 < day  && day <= 2) { //2日後の日付と締切日を比較
            /* メール本文を準備 */
            var strSubject2 = "【タスク/リマインド】" + task_name + "の期限が迫っています!";
            var strBody2 = task_end_date + "の期限が、残り" + day + "日と迫っています。";
            /* メールを送信 */
            var send = GmailApp.sendEmail(
                strTo,
                strSubject2,
                strBody2, {
                    from: strFrom,
                }
            );
        } else if (day <= 0) { //今日の日付と締切日を比較
            /* メール本文を準備 */
            var strSubject1 = "タスクの期限です";
            var strBody1 = "" + task_name + "の期限日です。" + (-day);
            /* メールを送信 */
            var send = GmailApp.sendEmail(
                strTo,
                strSubject1,
                strBody1, {
                    from: strFrom,
                }
            );
        }
    }
}

##参照サイト
http://komuinresign.net/blog/2016/11/google-apps-script/

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?