从Google Apps脚本获取TextBox值 [英] Get TextBox Value from Google Apps Script
问题描述
我对Google的Apps Script世界很陌生,我正在为最终用户创建一个基本的用户界面来查询数据(存储在Google电子表格中),并以格式化/用户友好的方式显示数据。
因为我想从学习Apps脚本开始简单并添加组件,所以我决定创建一个基本表单,允许我在文本框中输入文本,然后分配这个价值标签(我认为这将是一个简单的练习,在创建基本表单组件,并检索/赋值)。
不幸的是,我遇到的绊脚石是没有getText()或TextBox.getValue()函数。我尝试通过在线论坛/谷歌等寻找解决方法,但我没有尝试似乎工作(先前的搜索导致我在一个事件处理程序中进行处理)。
我的问题是这样的。如果我有一个文本框('textBox1')和一个按钮('button1')和一个标签('label1')。如何让我的web应用程序将我在textBox1中输入的值分配给label1,当我点击button1时?
我意识到这可能是最基本的问题,而且我知道它之前已经被问过......但是不管我多努力挖掘这些旧帖子似乎无法确定应该是什么样的代码。
预先致谢。
假设您的代码如下所示:
var textbox = app.createTextBox( ).setName( textboxName);
var buttonHandler = app.createServerHandler(updateLabelText)。addCallbackElement(textbox);
var button = app.createButton(Click me)。addClickHandler(buttonHandler);
var label = app.createLabel()。setId(label);
然后在你的函数中:
function updateLabelText(e){
var app = UiApp.getActiveApplication();
app.getElementById(label)。setText(e.parameter.textboxName);
返回应用程序;
}
所以要注意的是:
- 按钮处理程序被赋予一个函数的名称,您可以在代码中的其他位置定义该函数的名称。
- 按钮处理程序也必须被赋予回调元素。如果要读取函数中该元素的值,则这是必需的。您可以将面板添加为回调元素,并将该面板上的任何内容添加到回调中。 回调元素的值通过
e.parameter传回
。属性名称是元素的名称。示例:e.parameter.textboxName
。 - 标签需要一个ID,以便您可以从其他函数中引用它。
I am new to the world of Google's Apps Script, and I am trying to create a basic UI for my end user to query data (stored in google spreadsheets) and display the data in a formatted / user friendly way.
Since I want to start off simple and add in components as I learn Apps Script I decided to create a basic form that will allow me to enter text in a text box, then assign that value to a label (what I thought would be a simple exercise in creating basic form components, and retrieving / assigning values).
Unfortunately the stumbling block I ran into is that there is no getText() or TextBox.getValue() function. I tried searching through online forums / google etc to find out the way around this, but nothing I try seems to work (previous searched led me totry and work this out in an event handler).
My question is this. If I have a textBox ('textBox1') and a button ('button1') and a label ('label1'). How to I get my web app to assign the value I enter in textBox1 to label1 when I click button1?
I realize this is probably the most basic of questions, and I know it has been asked before....but no matter how hard I dig through these old posts I can't seem to figure what should be an easy bit of code out.
Thanks in advance.
Suppose you have code that looks like this:
var textbox = app.createTextBox().setName("textboxName");
var buttonHandler = app.createServerHandler("updateLabelText").addCallbackElement(textbox);
var button = app.createButton("Click me").addClickHandler(buttonHandler);
var label = app.createLabel().setId("label");
Then in your function:
function updateLabelText(e) {
var app = UiApp.getActiveApplication();
app.getElementById("label").setText(e.parameter.textboxName);
return app;
}
So the things to note:
- The button handler is given the name of a function that you define somewhere else in your code.
- The button handler also must be given a "callback element". This is required if you want to read the value of that element in your function. You can add a panel as a callback element and anything that's on that panel will be added to the callback.
- Values of callback elements are passed back through
e.parameter
. The property name is the name of the element. Example:e.parameter.textboxName
. - The label needs an ID so that you can reference it from your other function.
这篇关于从Google Apps脚本获取TextBox值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!