0
0

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.

フォーム内容をKEYにして、一致するカラムに回答内容を反映する

Posted at

const insertReport = (e) => {
  if(e.namedValues['key']) {
  const key = e.namedValues['key'];
  const information = e.namedValues['information'];

  const Sheet = SpreadsheetApp.opennById('ID).getSheetByName('SHEET_NAME');
  const data_range = Sheet.getRange(1,1).getDataRegion().getValues();
  const criteria_column = data_range.map((data) => data[0]);
  // ここでkeyをtoString()にするのがポイントです。これがないとindexOfが検索値として認知してくれません
  const is_match_row = 
criteria_column.indexOf(key.toString()) + 1;
  // SET_COLUMNには、値をセットしたい列の番号をセットします
  Sheet.getRange(is_match_row, SET_COLUMN).estValue(information);

  }

}


0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?