google.script.host 是一种异步客户端 JavaScript API,
  在 Google 文档、表格或表单中使用包含以下内容的对话框或边栏
  HTML 服务网页。要从命令行执行服务器端函数,
  客户端代码,请使用 google.script.run。如需了解详情,请参阅
  该
  与服务器功能通信指南
  。
属性
| 属性 | 说明 | 
|---|---|
| origin | 提供主机域,以便脚本可以设置 正确。 | 
方法
| 方法 | 返回类型 | 简介 | 
|---|---|---|
| close() | void | 关闭当前对话框或边栏。 | 
| editor.focus() | void | 将浏览器焦点从对话框或边栏切换到 Google 文档、表格或表单编辑器。 | 
| setHeight(height) | void | 设置当前对话框的高度。 | 
| setWidth(width) | void | 设置当前对话框的宽度。 | 
详细文档
close()
关闭当前对话框或边栏。
Code.gs
function onOpen(e) {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Sidebar').addItem('Show', 'showSidebar').addToUi();
}
function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('Index');
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showSidebar(html);
}Index.html
<input type="button" value="Close" onclick="google.script.host.close()" />
editor.focus()
将浏览器焦点从对话框或边栏切换到 Google 文档、表格或表单编辑器。
Code.gs
function onOpen(e) {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Sidebar').addItem('Show', 'showSidebar').addToUi();
}
function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('Index');
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showSidebar(html);
}Index.html
<input type="button" value="Switch focus" onclick="google.script.host.editor.focus()" />
setHeight(height)
设置当前对话框的高度。
Code.gs
function onOpen(e) {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Dialog').addItem('Show', 'showDialog').addToUi();
}
function showDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Index')
      .setWidth(300)
      .setHeight(200);
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showModalDialog(html, 'Dialog title');
}Index.html
<script>
  function resizeDialog(width, height) {
    google.script.host.setWidth(width);
    google.script.host.setHeight(height);
  }
</script>
<input type="button" value="Resize dialog"
  onclick="resizeDialog(450, 300)" />参数
| 名称 | 类型 | 说明 | 
|---|---|---|
| height | Integer | 新的高度(以像素为单位) | 
setWidth(width)
设置当前对话框的宽度。
Code.gs
function onOpen(e) {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Dialog').addItem('Show', 'showDialog').addToUi();
}
function showDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Index')
      .setWidth(300)
      .setHeight(200);
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showModalDialog(html, 'Dialog title');
}Index.html
<script>
  function resizeDialog(width, height) {
    google.script.host.setWidth(width);
    google.script.host.setHeight(height);
  }
</script>
<input type="button" value="Resize dialog"
  onclick="resizeDialog(450, 300)" />参数
| 名称 | 类型 | 说明 | 
|---|---|---|
| width | Integer | 新宽度(以像素为单位) |