実際のところ
code.gs
function onOpen() { //サイドメニュー表示 SpreadsheetApp.getUi() .createMenu('Custom Menu') .addItem('Show sidebar', 'showSidebar') .addToUi(); } function changeVal(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var cell = ss.getSheets()[0].getRange('B5'); var result = cell.setValue("42"); return result; } function showSidebar() { //サイドバー var html = HtmlService.createHtmlOutputFromFile('page') .setTitle('My custom sidebar') .setWidth(300); //幅300px SpreadsheetApp.getUi() .showSidebar(html); }
page.html
<!DOCTYPE html> <html> <head> <base target="_top"> <script> function onSuccess(numUnread) { var div = document.getElementById('output'); div.innerHTML = "<p>sucess!</p>"; } google.script.run.withSuccessHandler(onSuccess) .changeVal(); </script> </head> <body> <p>Hello, world!</p> <hr/> <div id="output"></div> <hr/> <input type="button" value="Close" onclick="google.script.host.close()" /> </body> </html>
画面