[英]how to register unique values? in the spreadsheet google app script web
[英]How to open spreadsheet from Google app script deployed as web app
我有一个Google Apps脚本,该脚本可打开和处理现有的电子表格并将数据写入JSON。 在Google脚本编辑器中,这对我来说效果很好,但是当我将其部署为网络应用程序时却无法打开电子表格。
为了说明这一点,我创建了这个简单的测试版本:
脚本和HTML文件保存在一个Google App脚本项目中。
我将“发布>部署为Web应用程序”与“将应用程序执行为:我”,并为其赋予必要的权限。
当我“测试Web应用程序的最新代码”时,我将显示HTML表单。 当我单击表单上的“确定”时,“在打开电子表格之前”会看到第一个警报。
但是我从来没有在“打开电子表格后”看到第二个警报。 尝试打开电子表格时,页面将重定向到空白的userCodeAppPanel URL,并且不再进行任何操作。
我猜这与身份验证有关??? 任何线索非常感谢!
doGet Google应用脚本:
function doGet() { return HtmlService.createHtmlOutputFromFile("opensheet.html") .setSandboxMode(HtmlService.SandboxMode.IFRAME); }
HTML形式:
<!DOCTYPE html> <html> <head> <base target="_top"> <script> function getData() { var sheetFileId = "1feVgACmd5_g9II2ll_1u7AVt8jIVg2LbKp13k8UQw6w"; alert("before opening spreadsheet"); var sheetFile = SpreadsheetApp.openById(sheetFileId); alert("after opening spreadsheet"); } </script> </head> <body> <p>Update web app from spreadsheet?</p> <form onsubmit='getData()'> <input type='submit' value='Go'> </form> </body> </html>
您可以使用window.open()
方法在新窗口中打开电子表格。 需要更改“提交”按钮,以便在单击按钮后不会在Web应用程序中出现空白屏幕。
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function getData() {
alert("before opening spreadsheet");
window.open("https://docs.google.com/spreadsheets/d/1feVgACmd5_g9II2ll_1u7AVt8jIVg2LbKp13k8UQw6w/edit#gid=0","_blank");
alert("after opening spreadsheet");
}
</script>
</head>
<body>
<p>Update web app from spreadsheet?</p>
<form>
<input type='button' onmouseup="getData()" value='Go'>
</form>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.