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
SpreadsheetsGoogle WorkspaceJavaScriptHTML

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

Any chance we can see more code and / or returned JSON?
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>
Julian Hansen

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
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
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Julian Hansen

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.
OliG

ASKER
exactly what I've been looking for. Thank you so much.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Julian Hansen

You are most welcome.