This tutorial explains to write an app script to search Key element in a sheet. This is useful in many scenarios. Please refer other tutorials to know the application of this operation.
var ss = SpreadsheetApp.openByUrl("Your Spread Sheet URL"); var sheet = ss.getSheetByName("Sheet1"); function doGet(e){ return search(e) ; } function doPost(e){ return search(e) ; } function search(e){ var id = e.parameter.id; var values = sheet.getRange(2, 1, sheet.getLastRow(),sheet.getLastColumn()).getValues(); for(var i = 0;i<values.length; i++){ if(values[i][0] == id ){ i=i+2; var name = sheet.getRange(i,2).getValue(); return ContentService.createTextOutput(name).setMimeType(ContentService.MimeType.TEXT); } } return ContentService.createTextOutput("Id not found").setMimeType(ContentService.MimeType.TEXT); }
Hi, thank you for your work. Your are helping a lot.
Please I copied your code and pasted it in the app script thinking I had it wrong when following you video, but it still giving me ‘Id not found’. But the Id I’m using is in the spreadsheet.
Please what could be the reason?