Created
December 12, 2023 08:17
-
-
Save Mulannnnn/dc4be13cd39a17f191d6c4f26e156c40 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 ss = SpreadsheetApp.openByUrl("YOUR_SHEET_URL"); | |
var sheet = ss.getSheetByName('YOUR_SHEET_NAME'); | |
const dataRange = sheet.getDataRange(); | |
const values = dataRange.getValues(); | |
const headerRow = values.shift(); | |
const randomIndex = Math.floor(Math.random() * values.length); | |
const rowData = values[randomIndex]; | |
const col1 = rowData[0]; // ใช้ตัวแปร col1Value แทน col1value | |
const col2 = rowData[1]; | |
const col3 = rowData[2]; // ใช้ตัวแปร col3Value แทน col3value | |
const col4 = rowData[3]; | |
const selectedColumns = { | |
column1: col1, | |
column2: col2, | |
column3: col3, | |
column4: col4 | |
}; | |
var output = ContentService.createTextOutput(JSON.stringify(selectedColumns)); | |
output.setMimeType(ContentService.MimeType.JSON); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment