【问题标题】:why e.parameter.argument does not work in Google script?为什么 e.parameter.argument 在 Google 脚本中不起作用?
【发布时间】:2018-03-23 18:45:51
【问题描述】:
【问题讨论】:
标签:
google-apps-script
google-sheets
parameter-passing
url-parameters
【解决方案1】:
更改 doPost -> doGet
function doGet(e){
var userName = e.parameter.userName;
return ContentService.createTextOutput(userName);
}
【解决方案2】:
- 这是一个从 doGet 获取查询字符串的简单示例:
- 不要忘记部署为 web 应用程序。
- 我将最新的参数保存在工作表名称 Params 中。
代码.gs
function getParams()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Params');
var rg=sh.getDataRange();
var vA=rg.getValues();
var s='<table>';
for(var i=0;i<vA.length;i++)
{
s+=Utilities.formatString('<tr><td>%s</td><td>%s</td></tr>',vA[i][0],vA[i][1]);
}
s+='</table>';
sh.clearContents();
return s;
}
function showTheThisDialog()
{
var ui=HtmlService.createHtmlOutputFromFile('thethisfunc');
SpreadsheetApp.getUi().showModelessDialog(ui, 'The This Func');
}
function doGet(e)
{
var sh=SpreadsheetApp.getActive().getSheetByName('Params');
var ui=HtmlService.createHtmlOutputFromFile('thethisfunc');
var data=e.parameter;
//Logger.log(e.parameter);
for(key in data)
{
var A=[key + ' is a ',data[key]];
sh.appendRow(A);
}
return ui.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
thisfunc.html
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
google.script.run
.withSuccessHandler(dispParams)
.getParams();
});
function dispParams(hl)
{
console.log(hl);
document.getElementById('mybox').innerHTML=hl;
}
console.log('My Code');
</script>
</head>
<body>
<div id="mybox"></div>
</body>
</html>
这是我的命令行:
https://script.google.com/macros/s/ID/exec?President=Donald&Donald=Duck