admin管理员组

文章数量:1397110

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=''></script>

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

</body>
</html>

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./jsapi'></script>

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

</body>
</html>
Share Improve this question edited Dec 4, 2014 at 14:54 safwanmoha asked Dec 4, 2014 at 13:55 safwanmohasafwanmoha 3061 gold badge2 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

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.

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./spreadsheets/d/1i9of_RcoDih65x2h7-agSdCaUSvc1fvfOm4Y7dQEb-s/edit#gid=0")
var ws = ss.getSheetByName("Data")
ws.appendRow(["name"])

  }

本文标签: javascriptReferenceError SpreadsheetApp is not definedStack Overflow