作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这shared spreadsheet有一个侧边栏(通过自定义菜单扩展菜单打开)
侧栏显示电子表格中的单元格列表。当前硬编码 A1
,A2
, ...(在脚本编辑器的 SideBarTemplate.html
中)
是否可以链接到特定的单元格?
侧栏中显示的最后一行This is HyperLink test to A1尝试使用带有指向 A1 链接的 href 标签 (href="#gid=1744285851&range=A1"
)但这不起作用。
侧边栏图片:
气体代码:
function onOpen(){
addMenu();
}
function addMenu(){
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'ShowSideBar', functionName: 'showSideBar'}
];
spreadsheet.addMenu ('Extensions Menu', menuItems);
}
function showSideBar(){
// Display a sidebar with custom HtmlService content.
var htmlTemplate = HtmlService
.createTemplateFromFile("SideBarTemplate");
htmlOutput = htmlTemplate.evaluate();
htmlOutput.setTitle('Ext. Side Bar');
SpreadsheetApp.getUi().showSidebar(htmlOutput);
}
HTML 模板:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
.style1 {
color: blue;
}
.style2 {
color: red;
}
</style>
</head>
<body>
<?var cells = ["A1","A2"]
for (var i = 0; i< cells.length;i++){?>
<div class="style1">Cell: <?=cells[i]?> <p class="style2">Required: How to make the blue text to hyper link to cell <?=cells[i]}?>
</p></div>
<a href="#gid=1744285851&range=A1">This is HyperLink test to A1</a>
</body>
</html>
最佳答案
作为documented in this answer ,侧边栏框架沙盒属性缺少 allow-top-navigation
因此,无法导航顶部框架(包括哈希更改)。
使用服务器端range.activate()
方法。使用 google.script.run
,您可以更改谷歌表格中的事件范围:
//client side
a1buttonElement.addEventListener('click',()=>google.script.run.select("a1"))
//server side
const select = e => SpreadsheetApp.getActive().getActiveSheet().getRange(e).activate()
绕过沙盒限制的变通方法是使用网络应用程序。在这种情况下,Google 表格应该由网络应用程序打开。如果它由 webapp 打开,我们可以利用 window.opener
api 写入 top
框架。参见 related answer .
关于html - 如何在谷歌表格侧边栏插件中添加超链接到单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63578516/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!