0
我會盡量保持簡短。我試圖在谷歌電子表格中制作一個谷歌網絡應用程序,它將允許我輸入最小值和最大值。如何將輸入值傳遞給使用GAS的函數
我已經能夠創建GUI並將其添加到面板。但我似乎無法將正在輸入的整數傳遞到另一個函數中。我已經嘗試了所有的東西,我對創建Google腳本相對來說比較陌生,所以我很抱歉,如果這看起來有些不好的問題。
這是迄今爲止所有代碼:
function onOpen() {
var ss = SpreadsheetApp.getActive();
var menuEntries = [];
menuEntries.push({name: "Open Dialog", functionName: "showDialog"});
ss.addMenu("Min/Max", menuEntries);
}
//creating a panel to add the min and max of low to high for scoring
function showDialog() {
max = 10;
var app = UiApp.createApplication();
app.setTitle("My Applicaition");
var panel = app.createVerticalPanel();
var textBox = app.createTextBox();
var label = app.createLabel("Set the min value for 'Low'");
//had to create a hidden element with id="min" for a global value that can be updated
var min = app.createHidden().setValue('0').setName('min').setId('min');
textBox.setName('myTextBox').setId('myTextBox');
var button = app.createButton('Submit');
panel.add(label);
panel.add(textBox);
panel.add(min);
panel.add(button);
//click handler for setting the value of min to the new value
var clickHandler = app.createServerClickHandler("responedToSubmit");
button.addClickHandler(clickHandler);
clickHandler.addCallbackElement(panel);
app.add(panel);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
function responedToSubmit(e) {
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.myTextBox;
Logger.log(e.parameter.min);
if (typeof textBoxValue != "number") {
var num = parseInt(textBoxValue);
app.getElementById('min').setValue(num);
Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
} else {
throw "value needs to be set as number";
}
return app.close();
}
這是我相信事情正在按計劃不會:
function responedToSubmit(e) {
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.myTextBox;
Logger.log(e.parameter.min);
if (typeof textBoxValue != "number") {
var num = parseInt(textBoxValue);
app.getElementById('min').setValue(num);
Logger.log("textBoxValue is = "+textBoxValue+"\n min value is = "+e.parameter.min);
} else {
throw "value needs to be set as number";
}
return app.close();
}
我發現,每次我測試.setValue ()不會更新'min'的值,我不明白爲什麼。你能幫忙嗎?
好,我又增加了文本框面板的名稱myTextBox和被稱爲回用 e.parameter.myTextBox目前 日誌看起來是這樣的: [13 -06-13 11:07:26:032 BST] textBoxValue是= 77 最小值是= 0 有一些關於setValue(),這是不適合我... – user2096568
更新剛剛解決,如果我我們addCallBackElement與min然後我可以更新min的值:e.parameter.min = textBoxValue; 感謝您的幫助br araujo :) – user2096568
編輯:我有另一個問題,如何可能更新另一個變量在單獨的frongs respondToSubmit?我想知道,因爲我想在我的電子表格的公式中使用更新後的變量。 – user2096568