Link to home
Start Free TrialLog in
Avatar of OliG
OliG

asked on

Get one Cell Value from Google Sheets via HTML Javascript

Hi all,
I am trying to get one specific cell from a google sheet for displaying on a website.
What i have found is a lot of examples to create a table in html from a google sheet source, but not how to get f.e. Cell "A4" only.

$.getJSON( "https://spreadsheets.google.com/feeds/cells/19weOqnGlADXwhxUUtVnfZYv2uH6UJUeSmV5WQXQ5Ccc/od6/public/values?alt=json-in-script&callback=?"
function (data) {
       //what to put in here??
});
any help appreciated
thanks in advance
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Any chance we can see more code and / or returned JSON?
Avatar of OliG
OliG

ASKER

Julian, hi
I only have a working example which generates a list:


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
      <h1>Ranking</h1>
      <div id="ranking-list"></div>
</body>
</html>
<script type="text/javascript">

$(document).ready(function() {      
//source file is https://docs.google.com/spreadsheets/d/19weOqnGlADXwhxUUtVnfZYv2uH6UJUeSmV5WQXQ5Ccc

$(function listBooks() {      
$.getJSON( "https://spreadsheets.google.com/feeds/list/19weOqnGlADXwhxUUtVnfZYv2uH6UJUeSmV5WQXQ5Ccc/od6/public/values?alt=json-in-script&callback=?",
      function (data) {      
            $('div#ranking-list').append('<ul class="items"></ul>');
            $.each(data.feed.entry, function(i,entry) {      
                  var item = '<span style="display:none">' + entry.id.$t + '</span>';      
                  item += 'erhalten: ' + entry.gsx$erhalten.$t;      
                  $('.items').append('<li>' + item + '</span></li>');      
                  });
            });
      });
});
</script>
Your getJSON call URL returns
Invalid parameter value: callback=?

Open in new window


to answer the question we need to see the returned JSON as well.
Avatar of OliG

ASKER

did you just click on the hyperlink? then yes.
but if you embed the whole html code on a website, it will return a list of 14 rows.

remove the ?callback to get the raw data:
https://spreadsheets.google.com/feeds/list/19weOqnGlADXwhxUUtVnfZYv2uH6UJUeSmV5WQXQ5Ccc/od6/public/values?alt=json-in-script
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just a comment on your jQuery. In your source you have
$(document).ready(function() {      
...
  $(function listBooks() {      
  });
});

Open in new window

$(document).ready() is the same as $(function() - so nesting one in side the other is not required - you only need the one as shown in my previous post.
Avatar of OliG

ASKER

exactly what I've been looking for. Thank you so much.
You are most welcome.