Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
JavaScript not returning Google Sheets Cell Value

In this code I have declared a variable to get cell value from some spreadsheet owned by me.

And then I used that variable for innerHtml of

element with id "value".

But the web page is not showing any result.

It gives blank page ..

Any idea, what where went wrong ..?

<!DOCTYPE html> 
<html>
<head>
<title>Getting Values from Sheets</title>
</head>
<body>


<p id="value2">Hello World</p>

<p id="value"></p>

<script src="sheets/snippets/snippets.js">

gapi.client.sheets.spreadsheets.values.get({
  spreadsheetId: 1jH0y-PknkZXH7KqjPBWDv98kkBnndGt_GIbdUh_1nRM,
  range: Users!A2
}).then((response) => {
  var result = response.result;
  var numRows = result.values ? result.values.length : 0;
  console.log(`${numRows} rows retrieved.`);
document.getElementById("value").innerHTML = result;
});
</script>

</body>

</html>

Thank You

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Set the value at the time of receiving the response.

gapi.client.sheets.spreadsheets.values.get({
  spreadsheetId: 1jH0y-PknkZXH7KqjPBWDv98kkBnndGt_GIbdUh_1nRM,
  range: users!a2
}).then((response) => {
  var result = response.result;
  var numRows = result.values ? result.values.length : 0;
  console.log(`${numRows} rows retrieved.`);
  document.getElementById("value").innerHTML = result;
});

This is because the next task is executed after sending a request to perform an asynchronous task.

document.getElementById("value").innerHTML = result; code was outside of then().

The var result is not defined at this moment.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda