Hann
Hann

Reputation: 713

"SpreadsheetApp is not defined" when accessing spreadsheet from JavaScript

I am receiving this error when trying to access a Google spreadsheet from JavaScript.

Uncaught ReferenceError: SpreadsheetApp is not defined

Why is this happening?

<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
function findAllBP() {
     var sheet = SpreadsheetApp.getActiveSpreadsheet();  // error
    var sid = SpreadsheetApp.openById('ID');
    var dd = sid.getSheetByName('Published').getRange('A').getValues();
        var name = sheet.getName();
        console.log("name of spreadsheet" + name);
    }

    window.onload = function() {findAllBP();};
</script>
</head>

<body>
</body>

</html>

Upvotes: 1

Views: 4482

Answers (1)

Pawel Uchida-Psztyc
Pawel Uchida-Psztyc

Reputation: 3838

According to docs (https://developers.google.com/loader/) first you need to load a module and the use it's API:

google.load("search", "1");

But this is not an issue here. API that you are trying to use is a Apps Script API and it is not available on regular websites. It must be used in context of Spreadsheet. Read more on Apps Script docs: https://developers.google.com/apps-script/

Upvotes: 1

Related Questions