[英]How to use Google Sheets script to open a modal form on open event?
It only works if I call the modal by pressing from the custom menu, but if I put it in the event when opening it does not load it, but if it creates the menu that's why I don't know why it doesn't load the modal它只有在我通过从自定义菜单中按下来调用模态时才有效,但是如果我在打开它时将它放在事件中它不会加载它,但是如果它创建菜单这就是为什么我不知道它为什么不加载模态
const spreadsheetId = 'your spreedsheet id'; function addMenuItem() { SpreadsheetApp.getUi().createMenu('My Functions').addItem('Show Dialog', 'showModal').addToUi(); } function showModal() { const userInterface = HtmlService.createHtmlOutputFromFile('modal'); SpreadsheetApp.getUi().showModelessDialog(userInterface, 'My modal'); } function inputData(data) { SpreadsheetApp.openById(spreadsheetId).getSheetByName('Sheet1').appendRow([data]); } function onOpen(e){ addMenuItem(); showModal(); }
<,DOCTYPE html> <html> <head> <base target="_top"> </head> <body> <h1>Hello. and Welcome.</h1> <input id='my_input' placeholder='Insert your Data'><br> <button id='my_button'>Submit</button> <script> document,getElementById('my_button').addEventListener('click'. _ => { const data = document;getElementById('my_input').value. google.script.run;withSuccessHandler(displaySuccess);inputData(data). }). function displaySuccess() { google.script;host;close(); } }); </script> </body> </html>
You are currently using Simple Triggers您当前正在使用简单触发器
Simple Triggers Restrictions: 简单触发器限制:
They cannot access services that require authorization.
他们无法访问需要授权的服务。 For example, a simple trigger cannot send an email because the Gmail service requires authorization, but a simple trigger can translate a phrase with the Language service, which is anonymous.
例如,简单触发器无法发送 email,因为 Gmail 服务需要授权,但简单触发器可以使用语言服务翻译短语,这是匿名的。
There are 2 ways on how to create an installable trigger:有两种创建可安装触发器的方法:
1. Managing triggers manually 1. 手动管理触发器
Sample Configuration:示例配置:
2. Managing triggers programmatically 2. 以编程方式管理触发器
/**
* Creates a trigger for when a spreadsheet opens.
*/
function createSpreadsheetOpenTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger('myFunction')
.forSpreadsheet(ss)
.onOpen()
.create();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.