Google脚本:将脚本附加到电子表格中动态添加的图像上 [英] Google Script: Attach a script to a dynamically added image in a spreadsheet

查看:46
本文介绍了Google脚本:将脚本附加到电子表格中动态添加的图像上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google脚本中构建一个基于Google Spreadsheet的应用程序.它要做的一件事是输出选择的附加到行中的父项的项.我希望用户能够通过单击每行也生成的图像来打开这些项目的编辑界面.

I'm building a Google Spreadsheet-based app in Google Script. One of the things it does is output a selection of items attached to a parent item in rows. I'd like for the user to be able to open an editing interface for these items by clicking an image that is also generated for each row.

在Google表格中,您可以右键单击插入的图像以打开上下文菜单并将脚本附加到该菜单.Google脚本允许您使用assignScript方法将脚本分配给工作表中的图像,但是由于某些原因,当您调用该函数时,它将弹出此错误:脚本函数function editContract(){Logger.log(合同编辑")}找不到""

In Google Sheets, you can right-click on an inserted image to open a contextual menu and attach a script to it. Google Script lets you use the assignScript method to assign a script to an image in the sheet, but for some reason when you call that function it pops this error: "Script function function editContract(){ Logger.log("contract edit") } could not be found"

这是代码.没什么复杂的!

Here's the code. Nothing complicated!

var fileId = '17-6V_HBlSGwHW-_NeLzUo5kizxxrYOjG';
var img = DriveApp.getFileById(fileId).getBlob();
// Insert the image in cell.
searchSheet.insertImage(img, 10, writeRow);    
// now we need to attach a script to that image  
images = searchSheet.getImages(); 
images[images.length - 1].assignScript(editContract);

推荐答案

后代的响应:.assignScript中的函数名称需要用引号引起来.将其记录在某处会很酷.

Responding for posterity: function names in .assignScript need to be encapsulated in quotes. Would have been cool for that to be documented somewhere.

这篇关于Google脚本:将脚本附加到电子表格中动态添加的图像上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆