英文:
How to put html in a prompt window in google app script
问题
我正在工作中玩得开心,并正在构建一个包含许多小脚本的表格(即:我是一个初学者,懂一点点appscript和html代码)。我成功地创建了一个脚本,以使提示框出现,但我想在弹出窗口中添加一张图片。
到目前为止,这是我的代码:
function promptbox() {
var ui = SpreadsheetApp.getUi();
var result = ui.prompt(
'Inscrire le No Projet à copier',
ui.ButtonSet.OK_CANCEL);
}
我找到了有关HTML的帖子并尝试了其中的代码,效果非常好,但是我不知道如何在我的提示框中编写HTML代码。我尝试了不同的方法,但没有成功。
是否可以在提示框中使用HTML?如果是的话,我该如何使用HTML编写我的提示框?如果不行,是否可以简单地向提示框添加一张图片?如果可以的话,我该如何为我的提示框添加图片?如果不行,那没关系!
提前谢谢!
英文:
I'm having fun at work and building a sheet with a bunch of little scripts (read: I'm a debutant that know a little bit appscript and html code). I succeeded to make a script to make a prompt box appear but I would like to add an image in the popup window.
Here's my code so far:
function promptbox() {
var ui = SpreadsheetApp.getUi();
var result = ui.prompt(
'Inscrire le No Projet à copier',
ui.ButtonSet.OK_CANCEL);
}
I found that post about html and try the code as it is and works really well, although, I don't know how to code html in my prompt box. I tried different things, but I didn't succeed.
Is it possible to use html with a prompt box? If yes, how do I code my prompt box with html? If no, is it possible to simply add an image to a prompt box? If yes, how do I code my prompt box with an image? If no, oh well!
Thanks in advance!
答案1
得分: 1
你不能在提示中使用HTML输出。
请查看Ui类的文档:https://developers.google.com/apps-script/reference/base/ui
查看该类具有的方法。
HTML输出(你正在尝试的操作)只能在以下方法中使用:
- showModalDialog(HTML, title)
- showModelessDialog(HTML, title)
- showSidebar(HTML)
英文:
Hy Mole
You can not use an HTML output in a prompt.
Please have a look at the Ui class documentation: https://developers.google.com/apps-script/reference/base/ui
Check on the methods the class has.
HTML outputs(what you are trying to do) can only work on the following methods
- showModalDialog(HTML, title)
- showModelessDialog(HTML, title)
- showSidebar(HTML)
答案2
得分: 0
这将显示一个HTML对话框,然后当您单击"显示提示"时,将出现一个提示,您可以在其中输入一个值,该值将显示在一个提示框中。
function myfunction() {
const ss = SpreadsheetApp.getActive();
const ui = SpreadsheetApp.getUi();
let body = '<form><input type="text" id="name" name="value" value="请输入您的姓名。" readonly/><br><input type="button" value="显示提示" onclick="doStuff()" /></form>';
let script = 'function doStuff(){ const v = document.getElementById("name").value;google.script.run.alert(v)}';
let html = `<!DOCTYPE html><html><head><base target="_top"></head><body>${body}<script>${script}</script></body></html>`;
ui.showModelessDialog(HtmlService.createHtmlOutput(html),"对话框");
}
function alert(v) {
let r = SpreadsheetApp.getUi().prompt(v);
SpreadsheetApp.getActive().toast(r.getResponseText())
}
所有的HTML都嵌入在gs函数中,作为简单的字符串。
英文:
This will display an html dialog and then when you click display prompt a prompt will appear where you can respond with a value that will be displayed in a toast.
function myfunction() {
const ss = SpreadsheetApp.getActive();
const ui = SpreadsheetApp.getUi();
let body = '<form><input type="text" id="name" name="value" value="Please enter you name." readonly/><br><input type="button" value="Display Prompt" onclick="doStuff()" /></form>';
let script = 'function doStuff(){ const v = document.getElementById("name").value;google.script.run.alert(v)}'
let html = `<!DOCTYPE html><html><head><base target="_top"></head><body>${body}<script>${script}</script></body></html>`;
ui.showModelessDialog(HtmlService.createHtmlOutput(html),"Dialog");
}
function alert(v) {
let r = SpreadsheetApp.getUi().prompt(v);
SpreadsheetApp.getActive().toast(r.getResponseText())
}
All of the html is embedded in the gs functions as simple strings.
Modeless Dialog:
Modal Prompt:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论