Skip to content

Instantly share code, notes, and snippets.

@ChaiyachetU
Created March 25, 2022 15:42
Show Gist options
  • Save ChaiyachetU/2e1529a7fd6e88804222f7ac026ad6a6 to your computer and use it in GitHub Desktop.
Save ChaiyachetU/2e1529a7fd6e88804222f7ac026ad6a6 to your computer and use it in GitHub Desktop.
function doGet(e) {
const ssURL = "ํYour Google Sheet URL";
const ss = SpreadsheetApp.openByUrl(ssURL);
let response = [];
const sheetName = e.parameter.sheet;
if (sheetName === "address") {
const sheet = ss.getSheetByName(sheetName);
const address = sheet.getDataRange().getValues();
address.forEach((address, index) => {
if (index !== 0) {
response.push({id: index, province: address[0], district: address[1], subdistrict: address[2], postcode: address[3] });
}
})
return ContentService.createTextOutput(JSON.stringify(response)).setMimeType(ContentService.MimeType.JSON);
} else {
return ContentService.createTextOutput(JSON.stringify(response)).setMimeType(ContentService.MimeType.JSON);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment