簡體   English   中英

Google Apps Script - 使用側邊欄表單向電子表格追加一行

[英]Google Apps Script - Using Sidebar form to append a row to spreadsheet

該腳本應該在我的電子表格“onclick”按鈕中添加一個新行,但事實並非如此。 最終,我希望能夠將數據添加到與一列對應的每個文本框並附加一個新行。 不知道為什么這不起作用。 如何追加新行? 當我運行它時,這個腳本在腳本編輯器中工作,只是不在側邊欄 html 中。

 // Use this code for Google Docs, Forms, or new Sheets. function onOpen() { SpreadsheetApp.getUi() // Or DocumentApp or FormApp. .createMenu('SideBar') .addItem('Open', 'openDialog') .addToUi(); } function openDialog() { var html = HtmlService.createHtmlOutputFromFile("Index"); html.setTitle('Gmf Sent Msg Form'); SpreadsheetApp.getUi().showSidebar(html); } function insertRow(){ var doc = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1RY3TZvU- TFhlCyF9TKRk4Hb4b6Q1TnYa5K7ixyktykY/edit#gid=0"); doc.getActiveSheet().appendRow(['700','9/12/16','PO 16-45789']) }
 <body> Use this form to enter information into the cells of the spreadsheet.<br> <form> <p>ID</p> <input type="text" name="txtID" /> <p>Date</p> <input type="text" name="txtDate"/> <p>Subject</p> <input type="text" name="txtSub" /> <input type="button" value="Append Row" onclick="google.script.run .withSuccessHandler(insertRow)" /> </form> </body>

在這一行:

<input type="button" value="Append Row" onclick="google.script.run.withSuccessHandler(insertRow)" />

您正在設置回調函數withSuccessHandler()但您沒有調用任何服務器端函數,要直接調用它,您需要使用:

google.script.run.insertRow();

如果要設置回調函數在服務端函數成功返回時運行。

google.script.run.withSuccessHandler(onSuccess).insertRow();

有關更多信息,請參閱與服務器功能google.script.run 通信的指南。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM