gpt4 book ai didi

javascript - Google Apps 脚本 - 使用侧边栏表单将行附加到电子表格

转载 作者:行者123 更新时间:2023-11-27 22:32:15 25 4
gpt4 key购买 nike

此脚本应该在按钮的电子表格“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();

更多信息请参见 communicating with server functions 的指南和 google.script.run .

关于javascript - Google Apps 脚本 - 使用侧边栏表单将行附加到电子表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39460517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com