こんにちは。質問をさせていただきます。
開発環境はGoogle App Scriptです。
実行したいこと
毎分実行のトリガーを設定して、下記のコードを動かしたいと考えています。
"03:00" と "07:00" と "11:00" と "15:00" と"19:00" と "23:00" にだけシート全体の数字が入っているセルにだけ1を足すというものです。
問題点
最初はそれぞれ分けて記述していたのですが、毎分実行のトリガーだと数が増えるにつれてGASの制限にひっかかりつつあったので、まとめようと思ったのですが、学んだばかりの論理演算子を用いてやってみてもできませんでした。
何が間違っているのか、また解決策を教えていただきたく思います。
有識者の方、是非ともよろしくお願い致します。
試したコード①
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sh = ss.getActiveSheet(); function plus1() { if(Utilities.formatDate(new Date(), "Asia/Tokyo", "HH:mm") != ("03:00" || "07:00" || "11:00" || "15:00" || "19:00" || "23:00" )) return; const currentValues = sh.getSheetValues(1, 1, sh.getLastRow(), sh.getLastColumn()); const plusOneToEachCell = function(row){ return row.map(function(cellVal){ if (typeof cellVal == "number") return cellVal + 1; return cellVal; }) }; const plusOneValues = currentValues.map(plusOneToEachCell); sh.getRange(1, 1, plusOneValues.length, plusOneValues[0].length).setValues(plusOneValues); }
結果
"03:00"の際は実行されたものの、"07:00"以降は実行されませんでした。
試したコード②
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sh = ss.getActiveSheet(); function plus1() { if(Utilities.formatDate(new Date(), "Asia/Tokyo", "HH:mm") != ((((("03:00" || "07:00" ) || "11:00" ) || "15:00" ) || "19:00" ) || "23:00" )) return; const currentValues = sh.getSheetValues(1, 1, sh.getLastRow(), sh.getLastColumn()); const plusOneToEachCell = function(row){ return row.map(function(cellVal){ if (typeof cellVal == "number") return cellVal + 1; return cellVal; }) }; const plusOneValues = currentValues.map(plusOneToEachCell); sh.getRange(1, 1, plusOneValues.length, plusOneValues[0].length).setValues(plusOneValues); }
結果
いずれも実行されませんでした。
回答2件
あなたの回答
tips
プレビュー