コード.gs
function openGUI() { var html = HtmlService.createHtmlOutputFromFile('index'); SpreadsheetApp.getUi().showModalDialog(html, 'myGUI'); } function set_values_gs(value) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sh = ss.getActiveSheet(); var last_row = get_last_data_row(ss, sh); sh.getRange("A" + last_row).setValue(value); } function get_last_data_row(ss, sh) { var values = sh.getRange("A:A").getValues(); for (var i = values.length - 1; i >= 0; i--) { if (values[i] != "") { break; } } var last_row = i + 2; return last_row; }
index.html
<!DOCTYPE html> <html> <body> <textarea id="ta"></textarea> <br> <button id="submit">submit</button> <script> document.getElementById("ta").focus(); document.getElementById("submit").onclick = submit_click; function submit_click() { var value = document.getElementById("ta").value; google.script.run.withSuccessHandler(onSuccess) .withFailureHandler(onFailure) .set_values_gs(value); } function onSuccess() { document.getElementById("ta").value = ""; } function onFailure(e) { alert([e.message, e.stack]); } </script> </body> </html>
スプレッドシートに表示される画面