javascript 单元格悬停时的工具提示图像,Google 电子表格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15740798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tooltip image on cell hover, Google Spreadsheet
提问by timkl
I'm currently working on a Google Spreadsheet that has to include a bunch of image references.
我目前正在处理必须包含一堆图像引用的 Google 电子表格。
What I want to achieve is this: When you hover over a cell an image appear (like a tooltip).
我想要实现的是:当您将鼠标悬停在单元格上时,会出现一个图像(如工具提示)。
I found this widgeton the Google Developers, but when I add the code to my spreadsheet nothing happens.
我在 Google Developers 上找到了这个小部件,但是当我将代码添加到电子表格时,没有任何反应。
Does any of you guys know how to do something like this? Any hints on how to go about this is highly appreciated!
你们有没有人知道如何做这样的事情?任何有关如何解决此问题的提示都非常感谢!
回答by Guest
Displaying a User Interface from a Spreadsheet
从电子表格显示用户界面
As an alternative to deploying your user interface as a standalone web app, you can create a container-bound script from a Spreadsheet, and display the user interface from the Spreadsheet. To do this, find your doGet function and simply replace the call to
作为将用户界面部署为独立 Web 应用程序的替代方法,您可以从电子表格创建容器绑定脚本,并从电子表格显示用户界面。为此,请找到您的 doGet 函数并简单地将调用替换为
return app;
with the following:
具有以下内容:
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
where app is the variable name for the UiInstance object you are returning. Additionally, when you display the user interface from a Spreadsheet, the function does not have to be named doGet. You could instead call it something like displayMyUi, and then call that function directly to display the user interface in your Spreadsheet. When a user interface is displayed from a Spreadsheet, the script runs as the user who's accessing the Spreadsheet.
其中 app 是您要返回的 UiInstance 对象的变量名称。此外,当您从电子表格显示用户界面时,该函数不必命名为 doGet。您可以改为将其称为 displayMyUi,然后直接调用该函数以在电子表格中显示用户界面。从电子表格显示用户界面时,脚本以访问电子表格的用户身份运行。
e.g.
例如
function doGet() {
var app = UiApp.createApplication();
// The very first Google Doodle!
app.add(app.createImage("http://www.google.com/logos/googleburn.jpg"));
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
}
回答by Serge insas
What you are wanting to do is not possible in a Google Spreadsheet, widgets are only available in UiApp or HTML service.
您想要做的在 Google 电子表格中是不可能的,小部件仅在 UiApp 或 HTML 服务中可用。
What should be doable is to recreate the spreadsheet display in a Ui and from there use some kind of popup with a mouseOver handler to show the images as you want.
应该可行的是在 Ui 中重新创建电子表格显示,然后使用某种带有 mouseOver 处理程序的弹出窗口来根据需要显示图像。
Depending of your use case - mainly on what spreadsheet specific features you want to have when looking at your data - this could be a good or bad solution but only you can answer this last point.
根据您的用例 - 主要取决于您在查看数据时想要拥有哪些电子表格特定功能 - 这可能是一个好的或坏的解决方案,但只有您可以回答最后一点。