简体   繁体   中英

HTML/JS Served by Google Apps Script

I recently started a project using google apps script and I'm brand new to this language. This is a slightly stupid question, but one that I can't find the answer to. In the tool, I'm serving up an HTML form that I later plan on using to create a separate spreadsheet.

function doGet(){
var html = HtmlService.createHtmlOutputFromFile('form');
}

form.html

<head>
<script></script>
</head>
<body>
   ...content...
</body>

I had a question about the language used here. When I try and write stuff in the script tags, am I writing it in Javascript or am I writing it in Google Apps Script? More specifically, do I have access to the SpreadsheetApp class like I do in Google Apps Script?

Client side scripts are plain JavaScripts. You don't get access to Google libraries like SpreadsheetApp . You do get access to google.script.* methods, but nothing else.

Whe using Apps Script scriptlets in your Apps Script Webapp, you can use Apps Script methods and syntax

You can use calls to Apps Script services like SpreadsheetApp in the same manner like within your Code.gs file

Sample:

<head>
<script></script>
</head>
<body>
The value from cell A1 in sheet "Sheet 1" is:  <?= SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet 1").getRange("A1").getValue() ?>.
  </body>

More information about Apps Script WebApps and scriptlets here and here .

Note:

To use scriptlets you need to create a template and evaluate it also you need to return the html output if you want to visualize it clientside.

Sample for the doGet() function:

function doGet(){
  var html = HtmlService.createTemplateFromFile('form').evaluate();
  return html;
}

Also:

Make sure that your script has the necessary scopes to perform the request you implement in the html file, eg "https://www.googleapis.com/auth/spreadsheets.readonly".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM