នេះគឺការធ្វើ API ដែលទាញទិញទិន្ន័យចេញពី google sheet ជាប្រភេទ API សម្រាប់រៀនធ្វើអ្វីមួយដែលយើងត្រូវការ API សម្រាប់ធ្វើតេស
function doGet(){
const app = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('menu')
const data = app.getRange(1,1).getDataRegion().getValues()// get all data in table
const head = data.shift()// trim head only value
//console.log(head)
const jsonArray = data.map( r =>{// loop body data in table
//console.log(r)
const obj = {}
head.map((d,i) => {// combide head and body to one by one index
obj[d]= r[i]
})
return obj
})
//console.log(jsonArray)
// Set to API
const response = {STATUS: 200, DATA: jsonArray};
return ContentService
.createTextOutput(JSON.stringify(response))
.setMimeType(ContentService.MimeType.JSON);
}
0 Comments