I'm trying to Unlink all hyperlinks in a Google Spreadsheet, so far I'm trying to do a search and replace which is the code below, but wondering if there is a specific function to do the unlink?
function replacelinks(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Links");
var values = sheet.getDataRange().getValues();
replaceInSheet(values, '.com', '');
replaceInSheet(values, '.net', '');
I believe your goal as follows.
For this, how about this answer?
Unfortunately, in the current stage, it seems that there are no methods for directly removing the hyperlinks of the cells and texts. So in order to achieve your goal, I would like to propose a workaround. The flow of this workaround is as follows.
Please copy and paste the following script to the script editor. And, please enable Sheets API at Advanced Google services . And please set the sheet name you want to remove the hyperlinks.
function myFunction() {
const sheetName = "Sheet1"; // Please set the sheet name.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(sheetName);
const sheetId = sheet.getSheetId();
const range = sheet.getDataRange();
const temp = ss.insertSheet();
const tempId = temp.getSheetId();
range.copyTo(temp.getRange("A1"), {contentsOnly: true});
const requests = range.getRichTextValues().reduce((ar, row, i) => {
row.forEach((col, j) => {
const runs = col.getRuns();
if (col.getLinkUrl() || (runs && runs.some(e => e.getLinkUrl()))) {
const req1 = {updateCells:{range:{sheetId:sheetId,startRowIndex:i,endRowIndex:i + 1,startColumnIndex:j,endColumnIndex:j + 1},fields:"userEnteredValue"}};
const req2 = {copyPaste:{
source:{sheetId:tempId,startRowIndex:i,endRowIndex:i + 1,startColumnIndex:j,endColumnIndex:j + 1},
destination:{sheetId:sheetId,startRowIndex:i,endRowIndex:i + 1,startColumnIndex:j,endColumnIndex:j + 1},
pasteType:"PASTE_NORMAL"
}};
ar = ar.concat(req1, req2);
}
});
return ar;
}, []);
Sheets.Spreadsheets.batchUpdate({requests: requests}, ss.getId());
ss.deleteSheet(temp);
}
HYPERLINK()
can be removed.getRichTextValues()
cannot retrieve the number values. By this, when the number values has the hyperlinks, these hyperlinks cannot be removed. About this issue, I have already reported to the issue tracker. Ref So when this issue was removed, I think that using above script, all hyperlinks might be be able to be removed. Or, in the current stage, the method of getLinkUrl()
used in above script is not included in the official document. So I also think that the method for directly removing the hyperlinks might be added in the future update.What helped for me was to setShowHyperlink
to false for the range.
Example:
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getActiveSheet();
const range = ws.getRange(lastRow, 1)
range.setValue('https://example.com');
range.setShowHyperlink(false);
But as soon as you double click such a cell, Google will re-apply the hyperlink.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.