如何在Google表格应用程序脚本中创建超链接范围? [英] How to create hyperlink to range in Google Sheets App Script?
问题描述
我尝试在Google表格应用程序脚本中使用超链接填充单元格,并获得与GUI中完成的相同期望结果。我设法创建超链接以gid = ...的形式打印,作为sheetID。但是我很努力地获得在GUI中生成超链接时使用的rangeID,例如
HYPERLINK(#rangeid = 1420762593;'List 4'!F2:F15)
code>
是否可以在应用程序脚本中创建范围超链接?
是的,您可以在App Script中执行此操作。这是一个非常简单的实现,其中 HYPERLINK
函数被构建并附加到单元格中: prettyprint-override> function hyperlinkRange(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName(Sheet1);
var sheet2 = ss.getSheetByName(Sheet2)。getSheetId();
sheet1.getRange(A1)。setValue('= hyperlink(#gid ='+ sheet2 +'& range ='+ sheet1.getRange('A1:A10')。getA1Notation )+',点击跳转到Sheet 2)');
}
您可以将其与循环结合以设置多个工作表之间的链接值。
I'm trying to fill cells with hyperlinks to ranges in Google Sheets app script with the same desired outcome I would get had I done it in GUI. I managed to create hyperlinks to sheet in the form of "gid=..." with the ... being a sheetID. But I struggle to get the rangeID that is used when generating the hyperlink in GUI e.g.
HYPERLINK("#rangeid=1420762593";"'List 4'!F2:F15")
Is it possible to create hyperlinks to ranges in app script?
Yes, you can do this in App Script. Here's a very simple implementation where the HYPERLINK
function is built and appended to a cell:
function hyperlinkRange() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("Sheet1");
var sheet2 = ss.getSheetByName("Sheet2").getSheetId();
sheet1.getRange("A1").setValue('=hyperlink("#gid='+sheet2+'&range='+sheet1.getRange('A1:A10').getA1Notation()+'", "Click to jump to Sheet 2")');
}
You can combine this with loops to set a value of links across multiple sheets.
这篇关于如何在Google表格应用程序脚本中创建超链接范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!