脚本以自动链接到单元格 [英] Script to get link to the cell automatically

查看:65
本文介绍了脚本以自动链接到单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建模板工作表,并正在寻找脚本来获取活动工作表与特定单元格的链接(右键单击单元格->获取此单元格的链接"->粘贴的结果相同).获取此单元格的链接

I'm building a template sheet and looking for a script to get link of the active sheet to a specific cell (the same result when right-clicking on cell -> 'Get link to this cell' -> Paste. Get link to this cell

这意味着当我从模板工作表进行复制时,新创建的工作表将自动获得其链接.

It means when I do a copy from the template sheet, the newly created sheet will automatically get the link for it.

非常感谢您的帮助.

推荐答案

您想要的东西可以很容易地完成!

What you want can be done fairly easy!

function getLink() {
  let spreadsheet = SpreadsheetApp.getActive();
  let sheet = spreadsheet.getActiveSheet();
  let link = "https://docs.google.com/spreadsheets/d/"+spreadsheet.getId()+"/edit#gid="+sheet.getIndex()+"&range=A1"
  return link;
}

此处选择的范围是 A1 ,但是根据确切的要求,您还可以通过编程将range参数传递给 link 变量.

The range chosen here was A1, but depending on the exact requirements, you can also pass the range parameter to the link variable programmatically.

为了建立链接,使用了 getId() getIndex()方法来检索电子表格的ID和索引.分别.

In order to build the link, the getId() and the getIndex() methods were used in order to retrieve the id of the spreadsheet and the index of the sheet respectively.

Apps脚本表类-getId().

这篇关于脚本以自动链接到单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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