[英]links from spreadsheet not displaying in google html service page
on google script editor of ogle spreadsheets, I am trying to created a webpage which retrieves values from spreadsheet and displays. 在ogle电子表格的Google脚本编辑器上,我试图创建一个从电子表格中检索值并显示的网页。 However, it is not displaying the items linked on the spreadsheet.It is displaying static values but not links.
但是,它不显示电子表格上链接的项目,而是显示静态值而不显示链接。 what am I doing wrong?
我究竟做错了什么? Given below is my code.
下面是我的代码。
Below code in my .gs sheet 我的.gs工作表中的以下代码
function doGet() {
return HtmlService
.createTemplateFromFile('Index')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function getData() {
return SpreadsheetApp
.openById('abcdef')
.getActiveSheet()
.getDataRange()
.getValues();
getURL();
}
function getURL() {
var range = SpreadsheetApp.getActiveSheet().getActiveCell();
var links = SpreadsheetApp.getActiveRange().getFormulas();
//logs - Google
var values = range.getValues();
//logs - =HYPERLINK("http://www.google.com", "Google")
var formula = range.links;
//simple regex to get first quoted string
var url = /"(.*?)"/.exec(formula);
//logs - http://www.google.com
return url;
}
My index.html has the following code 我的index.html具有以下代码
<? var data = getData(); ?>
<table>
<? for (var i = 0; i < data.length; i++) { ?>
<tr>
<? for (var j = 0; j < data[i].length; j++) { ?>
<td>
<a id="button" href=#><?= data[i][j] ?> </a>
</td>
<? } ?>
</tr>
<? } ?>
</table>
Playing with Sandy's code above I found that most urls were refused for many reasons (non https, same origin, etc) so I looked at the doc and ended with this version that includes a target="_blank"
parameter and that opens all the urls I tried. 在上面的Sandy代码中,我发现大多数URL出于多种原因(非https,相同来源等)被拒绝,因此我查看了文档,并以包含
target="_blank"
参数并打开所有URL的该版本结束我试过了。
<? var data = getData(); ?>
<table>
<? for (var i = 0; i < data.length; i++) { ?>
<tr >
<? for (var j = 0; j < data[i].length; j++) { ?>
<td > <a id="button" href=" <?= data[i][j] ?> " target="_blank"> <?= data[i][j] ?></a></td>
<? } ?>
</tr>
<? } ?>
</table>
note also that urls in the spreadsheet must be in the form http://www.google.com to work, a short form like www.google.com won't work. 另请注意,电子表格中的网址必须采用http://www.google.com形式才能使用,而www.google.com之类的简短形式将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.