作成したテキストエリアに
アクティブセルの値が入力される
Code.gs /************************************ メニューを追加する ************************************/ function onOpen() { SpreadsheetApp.getUi() .createMenu('SCRIPT') .addItem('GUI', 'openGUI') .addToUi(); } /************************************ UIを表示する ************************************/ function openGUI() { var html = HtmlService.createHtmlOutputFromFile('index') .setSandboxMode(HtmlService.SandboxMode.IFRAME); SpreadsheetApp.getUi() .showModalDialog(html, 'myGUI'); } /************************************ アクティブセルの値を取得して返す ************************************/ function get_active_value(){ var ss = SpreadsheetApp.getActive(); var sh = ss.getActiveSheet(); var range = sh.getActiveRange(); var value = range.getValue(); return value; }
index.html <!--/************************************ HTML ************************************/--> <textarea id="ta"></textarea> <!--/************************************ JavaScript ************************************/--> <script> load_active_value(); function load_active_value(){ google.script.run.withSuccessHandler(to_ta) .withUserObject(this) .get_active_value(); } function to_ta(value){ document.getElementById("ta").value=value; } </script>