gpt4 book ai didi

html - 如何在谷歌表格侧边栏插件中添加超链接到单元格

转载 作者:行者123 更新时间:2023-12-04 14:11:59 25 4
gpt4 key购买 nike

shared spreadsheet有一个侧边栏(通过自定义菜单扩展菜单打开)

侧栏显示电子表格中的单元格列表。当前硬编码 A1,A2, ...(在脚本编辑器的 SideBarTemplate.html 中)

是否可以链接到特定的单元格?

侧栏中显示的最后一行This is HyperLink test to A1尝试使用带有指向 A1 链接的 href 标签 (href="#gid=1744285851&range=A1")但这不起作用。

侧边栏图片:

enter image description here

气体代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com