有没有办法在Google表格中单击鼠标放大图像?

Its*_*ons 5 google-sheets google-apps-script google-spreadsheet-api

我基本上在一张桌子上有小图像,我想在单击鼠标时放大它。我希望放大的图像显示在页面中央。再次单击鼠标以删除放大的图像。我可以使用找到的VB脚本在Excel上执行此操作,但Google表格中没有运气。有没有一种方法可以将这种脚本分配给每个图像?

与此类似http://imgur.com/ETyflIS

亲切的问候,

亚历克斯

SBm*_*ore 1

您可以将脚本分配给图像,但脚本无法(我可以看到)确定正在单击哪个图像。该脚本还可以插入一张新图像,但该图像不会分配有脚本,因此我们无法使其在单击时消失。

我想您可以分配一个脚本来使用 HTML 服务打开图像,如下所示:

点击放大图片

但是您需要为每个图像创建一个单独的函数,以便它可以将源加载到 HTML 中,或者以某种方式识别哪个图像被单击(我会考虑一下,但我认为这是不可能做到的)。

编辑:下面的脚本。第一个图像应运行 popUp1,第二个图像应运行 popUp2。可能有一个更优雅的解决方案来为 HTML 提供不同的图像 URL,但这可行。

代码.gs

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  // Or DocumentApp or FormApp.
  ui.createMenu('Actions')
  .addItem('Authorise', 'Auth')
  .addToUi();
}

function Auth() {
  SpreadsheetApp.getActiveSpreadsheet();
}


function popUp1() {
  var html = HtmlService.createHtmlOutputFromFile('index1')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  html.setHeight(400);
  html.setWidth(600);
  SpreadsheetApp.getUi()
      .showModalDialog(html, 'Image');
}

function popUp2() {
  var html = HtmlService.createHtmlOutputFromFile('index2')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  html.setHeight(400);
  html.setWidth(600);
  SpreadsheetApp.getUi()
      .showModalDialog(html, 'Image');
}
Run Code Online (Sandbox Code Playgroud)

索引1.html

<form>
  <div id="closeDiv"><font face="arial" size="1">Click the image to close...</font></div>
  <img src="http://www.hdwallpapersimages.com/wp-content/uploads/2014/01/Winter-Tiger-Wild-Cat-Images-540x303.jpg" alt="DJ BBQ" style="width:540px;height:303px;" onClick="closeImage()">
</form>

<script type="text/javascript">
  function closeImage() {
    google.script.host.close();
  }
</script>
Run Code Online (Sandbox Code Playgroud)

索引2.html

<form>
  <div id="closeDiv"><font face="arial" size="1">Click the image to close...</font></div>
  <img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg" alt="DJ BBQ" style="width:540px;height:303px;" onClick="closeImage()">
</form>

<script type="text/javascript">
  function closeImage() {
    google.script.host.close();
  }
</script>
Run Code Online (Sandbox Code Playgroud)