Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: SpreadsheetApp is not defined

I get "ReferenceError: SpreadsheetApp is not defined" when i run the above code. Is there any error? This is working in script editor but not working in separate file

<html>

<head>
    <title>Site</title>
</head>
<body>

<p id="demo"></p>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>

<script>
var ss = SpreadsheetApp.openById('1-wYHx2ynT1fMAUKHSeRDBABjE_cAbJ2tfBP_deKjhGs');
document.getElementById("demo").innerHTML =ss.getName();
</script>

</body>
</html>
like image 665
safwanmoha Avatar asked Aug 30 '25 18:08

safwanmoha


2 Answers

Take a look at the Google Apps Script tutorials. For the most part, GAS is all server-side scripting, whereas you're trying to gain client-side access to a spreadsheet. It doesn't work like that. You'll need to follow one of the tutorials and open the script editor to begin writing your code.

like image 94
John Avatar answered Sep 02 '25 07:09

John


You need to redirect call function in a way html apps script allows you. Please have a look at simple line below, which permits you to access any function

a file called "lookatme.html"

</script>
function doStuff() {
google.script.run.doStuff()
console.log("ggg")
  }
        </script>

if it is a .gs extension file unlike html file, it will recognize the code below and any extended apps scripts' built-in functions

a file called "anyfile.gs"

function doStuff() {

console.log("ggg")
// google.script.run.userClicked(userInfo)
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1i9of_RcoDih65x2h7-agSdCaUSvc1fvfOm4Y7dQEb-s/edit#gid=0")
var ws = ss.getSheetByName("Data")
ws.appendRow(["name"])

  }
like image 31
Bitdom8 Avatar answered Sep 02 '25 06:09

Bitdom8