答案 0 :(得分:2)
要从超链接获取URL,您需要脚本:
function LINK(reference) {
var sheet = SpreadsheetApp.getActiveSheet();
var formula = SpreadsheetApp.getActiveRange().getFormula();
var args = formula.match(/=\w+\((.*)\)/i);
try {
var range = sheet.getRange(args[1]);
}
catch(e) {
throw new Error(args[1] + ' is not a valid range');
}
var formulas = range.getFormulas();
var output = [];
for (var i = 0; i < formulas.length; i++) {
var row = [];
for (var j = 0; j < formulas[0].length; j++) {
var url = formulas[i][j].match(/=hyperlink\("([^"]+)"/i);
row.push(url ? url[1] : '');
}
output.push(row);
}
return output
}
然后使用公式:
=LINK(A1)
或更短的脚本:
function LINK(input) {
var range = SpreadsheetApp.getActiveSheet().getRange(input);
var url = /"(.*?)"/.exec(range.getFormulaR1C1())[1];
return url;
}
具有公式:
=LINK("A1")
或者没有脚本(如果您有超链接fx),则可以使用正则表达式,例如:
=REGEXEXTRACT(FORMULATEXT(A1), """(.+)"",")
要从超链接获取文本,请使用:
=""&A1
或:
=TO_TEXT(A1)