简体   繁体   English

由 Google Apps 脚本提供的 HTML/JS

[英]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.在该工具中,我提供了一个 HTML 表格,我稍后计划用它来创建一个单独的电子表格。

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

form.html表格.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?当我尝试在脚本标签中编写内容时,我是在 Javascript 中编写它还是在 Google Apps Script 中编写它? More specifically, do I have access to the SpreadsheetApp class like I do in Google Apps Script?更具体地说,我是否可以像在 Google Apps 脚本中一样访问 SpreadsheetApp class?

Client side scripts are plain JavaScripts.客户端脚本是纯 JavaScript。 You don't get access to Google libraries like SpreadsheetApp .您无法访问像SpreadsheetApp这样的 Google 库。 You do get access to google.script.* methods, but nothing else.您确实可以访问google.script.*方法,但没有别的。

Whe using Apps Script scriptlets in your Apps Script Webapp, you can use Apps Script methods and syntax在您的 Apps Script Webapp 中使用 Apps Script 脚本时,您可以使用 Apps Script 方法和语法

You can use calls to Apps Script services like SpreadsheetApp in the same manner like within your Code.gs file您可以使用与在 Code.gs 文件中相同的方式调用 Apps Script 服务(如 SpreadsheetApp)

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 .有关 Apps Script WebApps 和 scriptlet 的更多信息,请点击此处此处

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.要使用 scriptlet,您需要创建一个templateevaluate ,如果您想在客户端可视化它,您还需要return html output。

Sample for the doGet() function: 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".确保您的脚本具有执行您在 html 文件中实现的请求所需的范围,例如“https://www.googleapis.com/auth/spreadsheets.readonly”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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