SHARE
TWEET

Untitled

a guest Apr 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function doPost(e) {
  2.   var ss = SpreadsheetApp
  3.   .openById("19mJaMW8gC0x0M4FtjhA3bm9Sp4fMj1GHXYRti3H3X38");
  4.  
  5.   var tabelName = e.parameter.tabelName;
  6.   var sheet = ss.getSheetByName(tabelName);
  7.   var action = e.parameter.action;
  8.  
  9.   switch(action){
  10.     case "insert":
  11.       return insertData(e,sheet);
  12.       break;
  13.   }
  14. }
  15.  
  16. function doGet(e){
  17.   var ss = SpreadsheetApp
  18.   .openById("19mJaMW8gC0x0M4FtjhA3bm9Sp4fMj1GHXYRti3H3X38");
  19.   var tabelName = e.parameter.tabelName;
  20.   var sheet = ss.getSheetByName(tabelName);
  21.   var action = e.parameter.action;
  22.  
  23.   switch(action){
  24.     case "read":
  25.       return getData(sheet,tabelName);
  26.       break;
  27.   }
  28. }
  29.  
  30. function getData(sheet,tabelName){
  31.   var data = {};
  32.   data[tabelName] = getObjectData(sheet);
  33.  
  34.   var hasil = JSON.stringify(data);
  35.   return ContentService
  36.   .createTextOutput(hasil)
  37.   .setMimeType(ContentService.MimeType.JSON);
  38. }
  39.  
  40. function getObjectData(sheet){
  41.   var allData = [];
  42.   var rangeObjek = sheet.getDataRange().getValues();
  43.   var jumlahKolom = sheet.getLastColumn();
  44.   for(var row = 1;row<rangeObjek.length;row++){
  45.     var objek = {};
  46.     for(var column = 0;column<jumlahKolom;column++){
  47.       objek[rangeObjek[0][column]] = rangeObjek[row][column];
  48.     }
  49.     allData.push(objek);
  50.   }
  51.   return allData;
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. function insertData(request, sheet){
  60.   var nis = request.parameter.nis;
  61.   var nama = request.parameter.nama;
  62.   var status = request.parameter.status;
  63.   sheet.appendRow([nis,nama,status]);
  64.   var hasil = "Data berhasil dimasukan";
  65.   hasil = JSON.stringify(
  66.     {
  67.       "hasil": hasil
  68.     }
  69.   );
  70.  
  71.   return ContentService
  72.   .createTextOutput(hasil)
  73.   .setMimeType(ContentService.MimeType.JSON);
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top