Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 在谷歌应用程序脚本屏幕上显示可点击链接_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 在谷歌应用程序脚本屏幕上显示可点击链接

Google apps script 在谷歌应用程序脚本屏幕上显示可点击链接,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我需要在屏幕上显示一个存储在变量中的链接,并显示一条自定义消息。所有这些都在一个函数中 我尝试过使用HtmlService.createHtmlOutFromFile('index'),但这不起作用,因为我无法从html文件内部访问url变量 main.gs中的代码: function writeScript() { var zipFileId = XYZ; //Then there's a bunch of code to calculate zipFileId

我需要在屏幕上显示一个存储在变量中的链接,并显示一条自定义消息。所有这些都在一个函数中

我尝试过使用HtmlService.createHtmlOutFromFile('index'),但这不起作用,因为我无法从html文件内部访问url变量

main.gs中的代码:

function writeScript() {

    var zipFileId = XYZ; 
    //Then there's a bunch of code to calculate zipFileId

    var url = 'https://docs.google.com/uc?export=download&id=' + zipFileID;

    var html = HtmlService.createHtmlOutput("<h3>URL</h3>" + url);
    SpreadsheetApp.getUi().showModalDialog(html, 'Script Download');

}
函数writeScript(){
var zipFileId=XYZ;
//然后有一堆代码来计算zipFileId
var url='1〕https://docs.google.com/uc?export=download&id=“+zipFileID;
var html=HtmlService.createHtmlOutput(“URL”+URL);
SpreadsheetApp.getUi().showModalDialog(html,“脚本下载”);
}

是否有办法在最后一个对话框中显示文本“URL”,该文本可单击并将我带到存储在变量URL中的链接?

此功能用于添加到www.google.com的链接

函数clickableModal(){
变量url=”https://www.google.com";
var htmlString=“”+
“网址”;
var html=HtmlService.createHtmlOutput(htmlString);
SpreadsheetApp.getUi().showModalDialog(html,“脚本下载”);
}

关于从html文件内部访问
url
变量,请查看文档,因为这样可以做到这一点。

复制并粘贴到code.gs中:

function showDialog() {
  var ss=SpreadsheetApp.getActive();
  var html='<head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>';
  html+='<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">';
  html+='<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script></head><body>';
  html+='<div id="msg"></div>';
  html+='<script>$(function(){google.script.run.withSuccessHandler(function(hl){document.getElementById("msg").innerHTML=hl;}).getUrl();});</script></body>';
  var userInterface=HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Loading a URL')
}

function getUrl() {
  var zipFileID='something';
  var url='https://docs.google.com/uc?export=download&id=' + zipFileID
  return Utilities.formatString('<a href="%s">Clickable Link</a>',url);
}
函数showDialog(){
var ss=SpreadsheetApp.getActive();
var html='';
html+='';
html+='';
html+='';
html+='$(函数(){google.script.run.withSuccessHandler(函数(hl){document.getElementById(“msg”).innerHTML=hl;}).getUrl();');
var userInterface=HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModelessDialog(用户界面,“加载URL”)
}
函数getUrl(){
var zipFileID='something';
var url='1〕https://docs.google.com/uc?export=download&id=“+zipFileID
返回Utilities.formatString(“”,url);
}

运行showDialog()

这正是我想要的。谢谢