Created
August 27, 2022 09:22
-
-
Save OndraZizka/39d9597acb44a97be379aac280162e21 to your computer and use it in GitHub Desktop.
Google Sheets custom function: Get a link from a given cell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Extracts the first text string in double quotes in the formula of the cell at given address. | |
* @param {"A1"} address Cell address as a string. | |
* @customfunction | |
*/ | |
function getCellLink(address) { | |
if(!(address && typeof(address) == 'string')) | |
throw new Error('The 1st param must be a cell address as a string.'); | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var cell = ss.getRange(address); | |
var url = cell.getRichTextValue().getLinkUrl() | |
if (!url) | |
throw new Error('The cell in ' + address + ' does not contain a link.'); | |
return url | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment