Google関連

[Google Apps Script]サイドバーを表示する

  • Google Apps Scriptでサイドバーを表示します。
  • サイドバーの内容はcreateHtmlOutputFromFileメソッドで読み込むHTMLで、jQueryを扱うこともできます。
  • Google ドキュメント アドオンではCSSのパッケージ(https://ssl.gstatic.com/docs/script/css/add-ons.css)が用意されていて、link要素で読み込んで利用します。
  • HTML側からサーバースクリプトを呼び出すときは「google.script.run」を使います。
//var ui = SpreadsheetApp.getUi();
var ui = DocumentApp.getUi();

function onOpen(e){
    var html = HtmlService.createHtmlOutputFromFile('Sidebar').setTitle('サンプル サイドバー').setWidth(300);
    ui.showSidebar(html);
}

function showAlert(arg){
    ui.alert('Hello! ' + arg);
}

・Sidebar.html

<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
    $(function(){
        $('#btnOK').click(function(){
            google.script.run.showAlert('Taro.');
        });
    });
</script>
<p><button id="btnOK" class="action">OK</button></p>

GoogleAppsScript_02_01

GoogleAppsScript_02_02

[Google Apps Script]メニューの追加と確認ダイアログの表示前のページ

[Google Apps Script]スプレッドシート上にウィンドウを表示する次のページ

関連記事

  1. Google関連

    [Google Apps Script]OAuth認証(2.0)が必要なWeb APIを利用する。

    前回の記事ではGoogle Apps Scriptを使ってWebアプリ…

  2. Google関連

    [Google Apps Script]Google スライドでスクリプトを実行する

    最近私の周りでPowerPoint VBAがひっそりと流行中です。…

  3. Microsoft Graph

    [Google Apps Script]Office 365 unified APIを使ってメールを…

    久しぶりのGoogle Apps Scriptネタです。今回はGo…

  4. Google関連

    [Google Apps Script]箇条書きと番号付きリストを設定する

    Google スライドでは、段落に対して箇条書きと番号付きリストを設定…

  5. Google関連

    [Google Apps Script]Googleスライドのプレゼンテーションを他形式に変換する

    久しぶりにGASネタです。ドライブにある複数のプレゼンテーションを…

  6. Google関連

    Google Apps Script 活用ミートアップ #4に参加しました – #GAS…

    5月20日(月)にNagatacho GRiDで開催された「【エンジニ…

コメント

  1. この記事へのコメントはありません。

  1. この記事へのトラックバックはありません。

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP