Skip to content

Instantly share code, notes, and snippets.

@quadrochave
Created November 5, 2020 16:06
Show Gist options
  • Save quadrochave/d7b408eaf70a7a342155ec79d3ef478e to your computer and use it in GitHub Desktop.
Save quadrochave/d7b408eaf70a7a342155ec79d3ef478e to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function doGet(e){
// Loading in URL
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1lSOUNz26yK5BPDiE4wvvImn5tvzQ0Ony6f29tLPR9Kw/edit#gid=1370914101");
// Loading in the Name of the Sheet
var sheet = ss.getSheetByName("Guestdata");
return getUsers(sheet);
}
function getUsers(sheet){
//var jo = {};
var dataArray = [];
// collecting data from 2nd Row , 1st column to last row and last column
var rows = sheet.getRange(2,1,sheet.getLastRow()-1, sheet.getLastColumn()).getValues();
for(var i = 0, l= rows.length; i<l ; i++){
var dataRow = rows[i];
var record = {};
record['category'] = dataRow[0];
record['guestvalue'] = dataRow[1];
record['daysbetweenvisits'] = dataRow[2];
dataArray.push(record);
}
//Use the following ONLY if you want the JSON array to have a specified user name. Otherwise, just stringify the object dataArray
//jo.user = dataArray;
//var result = JSON.stringify(jo);
var result = JSON.stringify(dataArray);
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">function doGet(e){
// Loading in URL
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1lSOUNz26yK5BPDiE4wvvImn5tvzQ0Ony6f29tLPR9Kw/edit#gid=1370914101");
// Loading in the Name of the Sheet
var sheet = ss.getSheetByName("Guestdata");
return getUsers(sheet);
}
function getUsers(sheet){
//var jo = {};
var dataArray = [];
// collecting data from 2nd Row , 1st column to last row and last column
var rows = sheet.getRange(2,1,sheet.getLastRow()-1, sheet.getLastColumn()).getValues();
for(var i = 0, l= rows.length; i<l ; i++){
var dataRow = rows[i];
var record = {};
record['category'] = dataRow[0];
record['guestvalue'] = dataRow[1];
record['daysbetweenvisits'] = dataRow[2];
dataArray.push(record);
}
//Use the following ONLY if you want the JSON array to have a specified user name. Otherwise, just stringify the object dataArray
//jo.user = dataArray;
//var result = JSON.stringify(jo);
var result = JSON.stringify(dataArray);
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}
</script></body>
</html>
function doGet(e){
// Loading in URL
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1lSOUNz26yK5BPDiE4wvvImn5tvzQ0Ony6f29tLPR9Kw/edit#gid=1370914101");
// Loading in the Name of the Sheet
var sheet = ss.getSheetByName("Guestdata");
return getUsers(sheet);
}
function getUsers(sheet){
//var jo = {};
var dataArray = [];
// collecting data from 2nd Row , 1st column to last row and last column
var rows = sheet.getRange(2,1,sheet.getLastRow()-1, sheet.getLastColumn()).getValues();
for(var i = 0, l= rows.length; i<l ; i++){
var dataRow = rows[i];
var record = {};
record['category'] = dataRow[0];
record['guestvalue'] = dataRow[1];
record['daysbetweenvisits'] = dataRow[2];
dataArray.push(record);
}
//Use the following ONLY if you want the JSON array to have a specified user name. Otherwise, just stringify the object dataArray
//jo.user = dataArray;
//var result = JSON.stringify(jo);
var result = JSON.stringify(dataArray);
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment