So recently, Google added the feature where you can hyperlink to a specific cell, which is great. To do so, you use the "Insert link" feature on a specific cell, and then from the dropdown menu, you can click "Select a range of cells to link" where you then choose the cell or range in which you'd like to link to. In doing so, Google generates a very handy (and dynamic) ten-digit "Range ID".
It looks something like this: =HYPERLINK("#rangeid=1234567890","link")
What I can't figure out, though, is how to create this using a script.
It seems strange to me that this function wouldn't exist, since it's possible to do manually.
I can use the following code to generate a sheet ID, which comes in very handy when creating hyperlinks to jump between pages:
var ss = SpreadsheetApp.getActive();
var sheet1 = ss.getSheetByName(name);
var gid = sheet.getSheetId();
sheet2.getRange("A1").setFormula('=hyperlink("#gid='+gid+'","'name'")');
And I can use the following code to create a link to a specific cell, but it's not dynamic and breaks once rows/columns are inserted into the sheet:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRangeByName("A10");
var sheetID = range.getSheet().getSheetId();
var rangeCode = range.getA1Notation();
sheet2.getRange("J10").setFormula('=hyperlink("https://docs.google.com/spreadsheets/d/'+ss.getId()+'/edit#gid='+sheetID+'&range='+rangeCode+'","link")');
There has to be a way to do something like this following code, but I can't find a way, currently:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRangeByName("A10");
var rangeID = range.**getRangeID()**;
sheet2.getRange("J10").setFormula('=hyperlink("#rangeID='+rangeID+'","link")');
I know that getRangeID()
doesn't currently exist in the available options for Google Apps Script; however, is there something that does this function? It would be incredibly helpful if this command existed.
Any help out there? Is there another way to accomplish this that I'm missing?
Thanks for any help!