如何使用GoogleApps脚本向Google工作表中的htmloutput添加其他内容
我找到了使用HTML输出创建弹出窗口的代码。它当前设置为显示一个项目:在新选项卡中超链接到网站的标题。我有兴趣在此弹出窗口中添加其他内容 2.愿望:如何使用GoogleApps脚本向Google工作表中的htmloutput添加其他内容,html,google-apps-script,google-sheets,Html,Google Apps Script,Google Sheets,我找到了使用HTML输出创建弹出窗口的代码。它当前设置为显示一个项目:在新选项卡中超链接到网站的标题。我有兴趣在此弹出窗口中添加其他内容 2.愿望: 在弹出窗口中显示多个链接 显示附加内容(例如,链接上方的介绍段落;链接说明 我尝试使用多个showAnchor函数调用提醒功能,结果只显示了最后一个链接 我尝试在提醒功能中为showAnchor函数的“name”和“url”使用数组。下面是代码以及在相关应用程序脚本的notepad.gs代码文件中包含此代码的示例表 函数onOpen(){ var
function reminders() {
showAnchors([
{
description: 'Search the web without being tracked',
name: 'DuckDuckGo',
url: 'https://duckduckgo.com/',
},
{
description: 'A fairly popular search engine',
name: 'Google',
url: 'https://www.google.com/',
},
]);
}
function showAnchors(anchors) {
let html = '<html><body style="word-break:break-word; font-family:sans-serif;">';
html += '<p>Introduction paragraph above links.</p>'
anchors.forEach(anchor => {
html += '<h3>' + anchor.description + '</h3>'
+ '<a href="'
+ anchor.url
+ '" target="_blank" rel="noopener" onclick="google.script.host.close()">'
+ anchor.name
+ '</a>';
});
html += '</body></html>';
SpreadsheetApp.getUi()
.showModelessDialog(HtmlService.createHtmlOutput(html), 'Reminders');
}
功能提醒(){
主播([
{
description:'搜索web而不被跟踪',
名称:“DuckDuckGo”,
网址:'https://duckduckgo.com/',
},
{
描述:“一个相当流行的搜索引擎”,
名称:'谷歌',
网址:'https://www.google.com/',
},
]);
}
功能显示锚(锚){
让html='';
html+='上面的介绍段落链接。'
anchors.forEach(anchor=>{
html+=''+anchor.description+''
+ '';
});
html+='';
SpreadsheetApp.getUi()
.showModelessDialog(HtmlService.createHtmlOutput(html),“提醒”);
}
试试这个:
function reminders() {
showAnchors([
{
description: 'Search the web without being tracked',
name: 'DuckDuckGo',
url: 'https://duckduckgo.com/',
},
{
description: 'A fairly popular search engine',
name: 'Google',
url: 'https://www.google.com/',
},
]);
}
function showAnchors(anchors) {
let html = '<html><body style="word-break:break-word; font-family:sans-serif;">';
html += '<p>Introduction paragraph above links.</p>'
anchors.forEach(anchor => {
html += '<h3>' + anchor.description + '</h3>'
+ '<a href="'
+ anchor.url
+ '" target="_blank" rel="noopener" onclick="google.script.host.close()">'
+ anchor.name
+ '</a>';
});
html += '</body></html>';
SpreadsheetApp.getUi()
.showModelessDialog(HtmlService.createHtmlOutput(html), 'Reminders');
}
功能提醒(){
主播([
{
description:'搜索web而不被跟踪',
名称:“DuckDuckGo”,
网址:'https://duckduckgo.com/',
},
{
描述:“一个相当流行的搜索引擎”,
名称:'谷歌',
网址:'https://www.google.com/',
},
]);
}
功能显示锚(锚){
让html='';
html+='上面的介绍段落链接。'
anchors.forEach(anchor=>{
html+=''+anchor.description+''
+ '';
});
html+='';
SpreadsheetApp.getUi()
.showModelessDialog(HtmlService.createHtmlOutput(html),“提醒”);
}
您可以使用google.script.run.withSuccessHandler(obj=>{//display returned data})获取其他数据。get addationalData()
@Cooper感谢您的回复。这有点超出了我的理解范围。不过,在快速浏览了您引用的web应用程序的HTML代码后,我做了一个注释,在我准备涉入web应用程序领域后返回。您可以使用google.script.run.withSuccessHandler(obj=>{//display returned data})。get AddationalData();
@Cooper感谢您的回复。这有点超出了我的理解范围。不过,在快速浏览了您引用的web应用程序的HTML代码后,我记下了一个注意事项,一旦我准备涉入web应用程序领域,我将返回。