Javascript Google应用程序脚本制作按钮,可使用多个参数运行函数
我在侧边栏中创建了一个按钮,当用户单击该按钮时,我希望它运行一个具有多个参数的函数(这些参数会更改,并且不是常量,因此不能硬编码到html中) 我的Javascript Google应用程序脚本制作按钮,可使用多个参数运行函数,javascript,html,google-apps-script,Javascript,Html,Google Apps Script,我在侧边栏中创建了一个按钮,当用户单击该按钮时,我希望它运行一个具有多个参数的函数(这些参数会更改,并且不是常量,因此不能硬编码到html中) 我的HTML代码如下: <!DOCTYPE html> <html> <head> <base target="_top"> <style type="text/css"> button { font-size:
HTML
代码如下:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style type="text/css">
button {
font-size: 13px;
margin:5px;
}
</style>
</head>
<body>
<button class="button" style="background-color:#cfe2f3ff;" onclick="google.script.run.setupOffice()">Setup/Reset</button>
</body>
</html>
officeSelection
参数基于用户从特定单元格(A2)的下拉列表中选择的内容。ss
只是按名称调用特定工作表。officeID
调用与officeSelection
比较的数组
有没有办法让按钮的功能与我绘制图像并为其指定脚本时的功能相同
谢谢!@TheMaster我不知道该怎么做?如何将脚本分配给image并仍然希望传递参数?调用另一个函数,如
main
,该函数将调用setupOffice()
及其参数。或在function@TheMaster我不知道该怎么做?如何将脚本分配给图像,并且仍然希望传递参数?调用另一个函数,例如main
,该函数将使用其参数调用setupOffice()
。或者在函数中使用UI提示符
function runWithButtonAndSupplyParamsAtRunTime() {
const ss=SpreadsheetApp.getActive();
const resp=SpreadsheetApp.getUi().prompt("Enter Parameters","Enter param1/param2/param3/param4....",SpreadsheetApp.getUi().ButtonSet.OK_CANCEL);
if(resp.getSelectedButton()==SpreadsheetApp.getUi().Button.OK) {
let param=resp.getResponseText().split('/');
SpreadsheetApp.getUi().alert(param.join('\n'));//just to view params
//now your params are in param[0],param[1]....
//do the rest of your work here
}else{
SpreadsheetApp.getUi().alert('No parameters provide');
}
}
function runWithButtonAndSupplyParamsAtRunTime() {
const ss=SpreadsheetApp.getActive();
const resp=SpreadsheetApp.getUi().prompt("Enter Parameters","Enter param1/param2/param3/param4....",SpreadsheetApp.getUi().ButtonSet.OK_CANCEL);
if(resp.getSelectedButton()==SpreadsheetApp.getUi().Button.OK) {
let param=resp.getResponseText().split('/');
SpreadsheetApp.getUi().alert(param.join('\n'));//just to view params
//now your params are in param[0],param[1]....
//do the rest of your work here
}else{
SpreadsheetApp.getUi().alert('No parameters provide');
}
}