I have a google sheet with each cell containing multiple Hyperlinks.
My goal is to:
- extract url from say cell A1 (or the active cell/range)
- keep existing cell content and append the extracted URL to the existing content (in the same cell)
- Be able to do this for a range instead of each cell individually
Currently, I have this code that works for one cell with only one Hyperlink but gives an error
TypeError: Cannot read property '0' of undefined
when a cell contains multiple hyperlinks.
function URL() {
var spreadsheet =SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
var id = spreadsheet.getId();
var range = sheet.getActiveRange();
var linkArray = Sheets.Spreadsheets.get(id, {ranges: sheet.getName() + "!" +
range.getA1Notation(), fields: "sheets/data/rowData/values/hyperlink"});
var link = linkArray.sheets[0].data[0].rowData[0].values[0].hyperlink;
var cellInE = sheet.getRange(range.getRow(), 5);
var cellEcontent = sheet.getRange(range.getRow(), 5).getValues()
var appnded = cellEcontent + String.fromCharCode(10) + link;
cellInE.setValue(appnded);
}
I am new to google app scripts and coding in general. Any help would be appreciated.