表題の通り、 GoogleSheetの特定の列のデータを探して、その行のデータを返すGASのコードです。やってることは泥臭く、検索対象の列を配列に格納しておいて、それを線形検索して見つけた位置の行をとってきているだけです。この例では、取ってくる列を指定していますが、行ごととってきて配列に入れるというのがスマートかもしれませんね。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* keyword: 検索したいキーワード | |
* keywordColumn:検索する列 | |
* outputColumn: 出力する列 | |
*/ | |
function searchSheet(keyword,keywordColumn,outputColumn) { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("シート1"); | |
var data = sheet.getRange(1,keywordColumn,3).getValues(); | |
var result = ""; | |
console.log("data="+data); | |
for (var i = 0; i < data.length; i++) { | |
if (data[i] == keyword) { | |
result=getData(i+1,outputColumn); | |
console.log("find:"+result); | |
break; | |
} | |
} | |
return result; | |
} |