I have a number of URLs that I first convert from text to the =HYPERLINK-functionHYPERLINK
function and then want to edit the title-section of this function, so that only the domain is visible in the cells.
I attached the spreadsheet with my scripts.
[Spreadsheet][1]Spreadsheet
First I run "Convert Hyperlink", which produces the =HYPERLINK-functionHYPERLINK
function but when I run "Convert Title" then I'm back at my old text-urls URLs.
I want the result to look like =HYPERLINK("url";"www.domain=HYPERLINK("url";"www.example.com")
.com")
Also the script doesn't differentiate between different top-level-domains, which I wanted to by-passbypass by editing the script after a successful run, but is there another way?
I will include examples incasein case the Spreadsheet is not available in the future:
The sheet include various urlsURLs from different websites in column A
function converttolink() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var row = 1;
var val = sheet.getRange(row, 1).getValue();
while (val != "!")
if (val == "")
{
row++;
val = sheet.getRange(row, 1).getValue();
}
else
{
var val = sheet.getRange(row, 1).getValue();
var h_string = '=HYPERLINK("'+val+'";"'+val+'")';
cell = sheet.getRange(row, 1).setValue(h_string);
row++
}
}
function converttolink() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var row = 1;
var val = sheet.getRange(row, 1).getValue();
while (val != "!")
if (val == "")
{
row++;
val = sheet.getRange(row, 1).getValue();
}
else
{
var val = sheet.getRange(row, 1).getValue();
var h_string = '=HYPERLINK("'+val+'";"'+val+'")';
cell = sheet.getRange(row, 1).setValue(h_string);
row++
}
}
With the second script I try to edit the part after the ;;
in the =HYPERLINK-functionHYPERLINK
function with this script:
function converttitle() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var row = 1;
var url = sheet.getRange(row, 1).getValue();
while (url != "!")
if (url == "")
{
row++;
url = sheet.getRange(row, 1).getValue();
}
else
{
var url = sheet.getRange(row, 1).getValue();
myurl= url.replace("'.de'\?.*?html", ".de");
cell = sheet.getRange(row, 1).setValue(myurl);
row++
}
}
function converttitle() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var row = 1;
var url = sheet.getRange(row, 1).getValue();
while (url != "!")
if (url == "")
{
row++;
url = sheet.getRange(row, 1).getValue();
}
else
{
var url = sheet.getRange(row, 1).getValue();
myurl= url.replace("'.de'\\?.*?html", ".de");
cell = sheet.getRange(row, 1).setValue(myurl);
row++
}
}
I realized while writing, that the getValuegetValue
function will only get the actual url-textURL text and not the =Hyperlink-functionHyperlink function and therefore it only writes url-text back into the cell, just like it was before the conversion into the =HYPERLINK-functionHYPERLINK
function.
I
I guess it would be easier to truncate the urlsURLs first and write it in a second column and then change the first script to use the full and the truncated urlURL to form the =HYPERLINK-function.
[1]: https://docs.google.com/spreadsheets/d/1Q2SOXstc8s7f3jKRKoW2jIh1ULoyzieBvwQBKJcdSZI/edit?usp=sharingHYPERLINK
function.