"Insert Link" is not producing a =HYPERLINK(’’,’’)
anymore.
Before, if you linked a cell with a value ‘X’. It was converted into the formula
I could confirm your situation. In this case, it seems that the hyperlink can be retrieved from RichTextValue
object. Namely, I thought that the specification was changed to that the hyperlink is given to the text using RichTextValue
.
So as a sample case, it supposes as follows.
X
is put in a cell "A1".https://www.google.com
.In this case, the cell has no =HYPERLINK("https://www.google.com","X")
. The sample script for retrieving the URL from this situation is as follows.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var url = sheet.getRange("A1").getRichTextValue().getLinkUrl();
console.log(url);
In the current stage, the multiple hyperlinks can be added to the texts in one cell. For example, when 2 URLs are put to the text in a cell, you can use the following sample script. In this sample, a text of url1, url2
is put to a cell "A1", and url1
and url2
are linked with each link.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var RichTextValue = SpreadsheetApp.newRichTextValue()
.setText("url1, url2")
.setLinkUrl(0, 4, "https://url1/")
.setLinkUrl(6, 10, "https://url2/")
.build();
sheet.getRange("A1").setRichTextValue(RichTextValue);
When the multiple URLs are retrieved from the text in a cell, you can use the following sample script.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var range = sheet.getRange("A1");
var RichTextValue = range.getRichTextValue().getRuns();
var res = RichTextValue.reduce((ar, e) => {
var url = e.getLinkUrl();
if (url) ar.push(url);
return ar;
}, []);
console.log(res);
By the update at June 12, 2020, the documents of getLinkUrl() and setLinkUrl(linkUrl) were added to the official documents.