クラス google.script.host(クライアントサイド API)

google.script.host: 操作可能な非同期のクライアントサイド JavaScript API Google ドキュメント、スプレッドシート、フォームのダイアログやサイドバーに HTML サービス ページ。サーバー側の関数を google.script.run を使用します。詳細については、次をご覧ください: サーバー機能との通信に関するガイド 使用できます。

プロパティ

プロパティ説明
originホストドメインを提供し、スクリプトが自身の URL を 検証できます。

メソッド

メソッド戻り値の型概要
close() void 現在のダイアログまたはサイドバーを閉じます。
editor.focus() void ブラウザのフォーカスを、ダイアログまたはサイドバーから Google ドキュメント、スプレッドシート、フォームのエディタに切り替えます。
setHeight(height) void 現在のダイアログの高さを設定します。
setWidth(width) void 現在のダイアログの幅を設定します。

詳細なドキュメント

close()

現在のダイアログまたはサイドバーを閉じます。

コード.gsIndex.html
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);
}
<input type="button" value="Close"
 
onclick="google.script.host.close()" />

editor.focus()

ブラウザのフォーカスを、ダイアログまたはサイドバーから Google ドキュメント、スプレッドシート、フォームのエディタに切り替えます。

コード.gsIndex.html
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);
}
<input type="button" value="Switch focus"
 
onclick="google.script.host.editor.focus()" />

setHeight(height)

現在のダイアログの高さを設定します。

コード.gsIndex.html
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');
}
<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)" />

パラメータ

名前説明
heightInteger新しい高さ(ピクセル単位)

setWidth(width)

現在のダイアログの幅を設定します。

コード.gsIndex.html
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');
}
<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)" />

パラメータ

名前説明
widthInteger新しい幅(ピクセル単位)