シート1から二次元配列で取得したリストを編集した後、条件に一致する行をシート2に
転記しようとしていますが、転記する箇所でエラーになり解決することができず行き詰まっております。
セルを1つ1つ指定すると解決するのですが、できれば1行で転記してしまいたいです。
エラーの箇所 : sh1.getRange(m,1,m,6).setValues(c_list);
ロ グ : [[1班,100012,一二田,一二美,2022/04/15,2022/05/29]]
エラーメッセージ
Exception: The number of rows in the data does not match the number of rows in the range. The data has 1 but the range has 2.
listUp @ alert.gs:41
ソースコード
GoogleAppsScript
function listUp() { let n = 0;//リストの行を数えるカウント変数 let m = 2;//転記先の行を数えるカウント変数 const bk = SpreadsheetApp.openById("スプレッドシートID"); const sh = bk.getSheetByName("リスト"); const sh1 = bk.getSheetByName("転記用"); //★指定列の一番下の行番号を取得する let maxRng = sh.getRange(sh.getMaxRows(), 2); let lastRng = maxRng.getNextDataCell(SpreadsheetApp.Direction.UP); let lastraw = lastRng.getRow(); //★日付の変数 const day0 = new Date(); const day_30 = day0.setDate(day0.getDate() + 30); const day_45 = day0.setDate(day0.getDate() + 45); //★閲覧用シートをクリアして項目名を(1行目、1列目のセル、から1行目、6列目のセル)まで入れる sh1.clearContents(); sh1.getRange(1,1,1,6).setValues([["班","ID","姓","名","期日1","期日2"]]); //★表から継続中リストを取得する let list = sh.getRange(2,1,lastraw,15).getValues(); list= list.filter(elm => elm[1] == '継続中'); list= list.map(elm => [elm[11],elm[10],elm[12],elm[13],elm[6],elm[14]]); while(n<list.length){ //★もし今日より期日1が30日以内か期日2が45日以内なら if( day_30 >= list[n][4] || day_45 >= list[n][5]){ list[n][4] = Utilities.formatDate(list[n][4],'JST', 'yyyy/MM/dd'); list[n][5] = Utilities.formatDate(list[n][5],'JST', 'yyyy/MM/dd'); c_list = [[list[n][0] + ',' + list[n][1] + ',' + list[n][2] + ',' + list[n][3] + ',' + list[n][4] + ',' + list[n][5]]]; //★転記用に班から期日2までを転記 sh1.getRange(m,1,m,6).setValues(c_list); //★カウント変数mに1加算して次に書き込むときの転記用の行を1行下に指定する m++; } //★カウント関数nに1加算して継続中リスト次の行を見に行く n++; } }
まだ回答がついていません
会員登録して回答してみよう