[英]Unlink all hyperlinks from a sheet
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?我正在尝试取消链接 Google 电子表格中的所有超链接,到目前为止,我正在尝试进行搜索并替换下面的代码,但想知道是否有特定的 function 来执行取消链接?
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 .
并且, 请在高级 Google 服务中启用表格 API 。 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.HYPERLINK()
的超链接。getRichTextValues()
cannot retrieve the number values.getRichTextValues()
无法检索数字值。 By this, when the number values has the hyperlinks, these hyperlinks cannot be removed.getLinkUrl()
used in above script is not included in the official document.getLinkUrl()
方法并未包含在官方文档中。 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.对我有帮助的是将范围的
setShowHyperlink
设置为 false。
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.但是一旦你双击这样的单元格,谷歌就会重新应用超链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.