Created
December 12, 2023 09:26
-
-
Save Mulannnnn/4fb5230aa8047591acadadcd9258396a to your computer and use it in GitHub Desktop.
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
function doGet(request) { | |
var url = "YOUR_SHEET_URL"; //เปลี่ยน | |
var ss = SpreadsheetApp.openByUrl(url); | |
var sheetName = 'YOUR_SHEET_NAME'; //เปลี่ยน | |
var c1 = request.parameter.col1; | |
var c2 = findColumnValue(ss, sheetName, c1, 2); | |
var c3 = findColumnValue(ss, sheetName, c1, 3); | |
var c4 = findColumnValue(ss, sheetName, c1, 4); | |
var result = { | |
col1: c1, | |
col2: c2, | |
col3: c3, | |
col4: c4, | |
}; | |
console.log(result) | |
return ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON); | |
} | |
function findColumnValue(ss, sheetName, c1, colIndex) { | |
var sheet = ss.getSheetByName(sheetName); | |
var values = sheet.getRange(1, 1, sheet.getLastRow(), 1).getValues(); | |
for (var i = 0; i < values.length; i++) { | |
if (values[i][0] == c1) { | |
return sheet.getRange(i + 1, colIndex).getValue(); | |
} | |
} | |
return null; // Return null if value is not found | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment