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]メールからMessage-IDヘッダーを取得する

    はけた(@excelspeedup)氏のツイートで、GASでメールのM…

  2. Excel

    Google翻訳で文字列を翻訳するマクロ

    ※ 2016/2 時点では下記の方法はもう使用できなくなっています。V…

  3. Google関連

    [Google Apps Script]Google フォームとkintoneを連携させる方法

    Webフォームで入力された回答を、直接kintoneのアプリに保存した…

  4. Google関連

    [Google Apps Script]郵便番号から住所を取得する自作関数と住所から地図画像のURL…

    郵便番号検索APIを使って郵便番号から住所を取得する自作関数と、Sta…

  5. Office関連

    Gmail APIを使ってメール送信するVBAマクロ(2)

    前回の記事でGmail APIを使ってメールを送信するVBAマクロを紹…

コメント

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

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

Time limit is exhausted. Please reload CAPTCHA.

Translate

最近の記事

アーカイブ

PAGE TOP