Google関連

[Google Apps Script]jQuery UIのDatepickerを使ってスプレッドシートのセルに日付を入力する

[Google Apps Script]スプレッドシート上にウィンドウを表示する」で、Office 用アプリの「コンテンツ アプリ」のようにWebページ(HTML)をシート上に表示できることが分かったので、この記事のようにjQuery UIのDatepickerを使ってスプレッドシートのセルに日付を入力するスクリプトを作ってみたいと思います。

・コード.gs

var app = SpreadsheetApp;

function onOpen(e){
    showContentApp();
}

function showContentApp(){
    var html = HtmlService.createHtmlOutputFromFile('DatePicker').setTitle('Date Picker').setWidth(320).setHeight(320);
    app.getActiveSpreadsheet().show(html);
}

function setRangeValue(arg){
    app.getActiveRange().setValue(arg);
}

・DatePicker.html

<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/dot-luv/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1/i18n/jquery.ui.datepicker-ja.min.js"></script>
<script>
    $(function(){
        $("#datepicker").datepicker({
            onSelect: function(dateText, inst) {
                google.script.run.setRangeValue(dateText);
            }
        });
    });
</script>
<div id="datepicker"></div>

GoogleAppsScript_05_01

実際にやってみたら、思いのほか簡単に実装できました。
動作(反応)が遅いのが難点ですが、Datepickerの読み込みさえできてしまえば何とか実用に耐え得るレベルのスクリプトではないかと思います。

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

[Google Apps Script]選択文字列を翻訳する次のページ

関連記事

  1. Google関連

    [Google Apps Script]ショートカットファイルを作成する

    リリースノートによると、先月のGoogle Apps Scriptのア…

  2. Office関連

    Google スライドで新規プレゼンテーションを作成するVBAマクロ

    ここ数日PowerPointのマクロに加え、Google Apps S…

  3. Google関連

    [Google Apps Script]スプレッドシートで不要な空白文字を削除する

    スプレッドシートでは、「データ」メニューにある「空白文字を削除」を実行…

  4. Google関連

    [Google Apps Script]Webアプリケーションを作成する。

    Google Apps Scriptではスプレッドシートや文書上で動く…

コメント

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

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP