且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Google电子表格中使图片可点击

更新时间:2022-10-31 11:29:39

这些是我能够想到的两个解决方案:



(1)将此脚本分配给您的图像,并用您自己的链接替换链接。它需要多一个用户点击,但它可能是你能做的***的。 Caja锁定HTML服务输出的所有内容非常紧密,所以像 window.location.replace(http://www.example.com); window.location.href =http://www.example.com; 是不行的。
  function redirectTest(){
var htmlOutput = HtmlService
.createHtmlOutput('< a href =http://www.example.com> Click me! < / a>')
.setWidth(100)
.setHeight(100);
SpreadsheetApp.getUi()。showModelessDialog(htmlOutput,); (2)根据>

google.com/forum/#!topic/docs/BjnpMxEdbcIrel =nofollow noreferrer> this source and 这个来源,以下公式应该可以工作:

  = HYPERLINK(http://www.example.com,IMAGE(https://www.google.com/images/srpr/logo11w.png))

我无法在测试中使用它,但源代码并不旧。


I try to make clickable an imported image into Google spreadsheet. When I click it to take me to another website.

I was able to: - insert the image - to 'Assign script' to it - that looks like this:

function showMessageBox() {
  Browser.msgBox('You clicked it!');
}

When I click the image the above message comes up. However I need a script that I can assign and opens an outside url when image clicked.

Is there such a script available?

These are the two solutions I was able to come up with:

(1) Assign this script to your image and replace the link with your own. It requires one more user click, but it's probably the best you can do. Caja locks down everything output by the HTML Service pretty tight, so things like window.location.replace("http://www.example.com"); or window.location.href = "http://www.example.com"; are a no go.

function redirectTest(){
  var htmlOutput = HtmlService
    .createHtmlOutput('<a href="http://www.example.com">Click Me!</a>')
    .setWidth(100)
    .setHeight(100);
 SpreadsheetApp.getUi().showModelessDialog(htmlOutput, " ");
}

(2) According to this source and this source, the following formula should work:

=HYPERLINK("http://www.example.com", IMAGE("https://www.google.com/images/srpr/logo11w.png"))

I couldn't get it to work in my tests, but the sources aren't that old.