Skip to content

Instantly share code, notes, and snippets.

@AlphaNerd
Created November 18, 2015 01:46
Show Gist options
  • Save AlphaNerd/8fe9361916e56244f857 to your computer and use it in GitHub Desktop.
Save AlphaNerd/8fe9361916e56244f857 to your computer and use it in GitHub Desktop.
Google Sheets JSON pull
<div id="results"></div>
var url = 'https://spreadsheets.google.com/feeds/cells/1iuSmpZx2wN1N8xh9R6GUF5k0-o2budrCBPzKuY5IA-c/od6/public/values?alt=json-in-script&callback=?';
var onSuccess = function(data) {
var html = "";
var entries = data.feed.entry;
for (var i=0, len = entries.length; i<len; ++i) {
html += entries[i].content.$t + ' ';
if ((i + 1) % 3 == 0) {
html += '<br/>';
}
}
$('#results').html(html);
}
$.getJSON(url, cellEntries);
function cellEntries(json) {
var table = document.createElement('table');
table.setAttribute('id', 'output');
var tbody = document.createElement('tbody');
var tr;
for (var i=0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
if (entry.gs$cell.col == '1') {
if (tr != null) {
tbody.appendChild(tr);
}
tr = document.createElement('tr');
}
var td = document.createElement('td');
td.appendChild(document.createTextNode(entry.content.$t));
tr.appendChild(td);
}
tbody.appendChild(tr);
table.appendChild(tbody);
document.getElementById('results').appendChild(table);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment