Irf*_*lam 7 cell hyperlink google-sheets google-apps-script google-sheets-formula
我有一个工作表,其中在单元格中设置了超链接,但没有通过公式设置。单击单元格时,在“ fx”栏中,它仅显示该值。
我在网上搜索,但到处都是,信息是通过使用提取超链接getFormula()。
但就我而言,根本没有设定公式。
I can see hyperlink as you can see in image, but it's not there in "formula/fx" bar.
How to get hyperlink of that cell using Apps Script or any formula?
小智 12
当单元格只有一个 URL 时,您可以使用以下简单脚本从单元格中检索 URL。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var url = sheet.getRange()("A2").getRichTextValue().getLinkUrl();
Run Code Online (Sandbox Code Playgroud)
来源:https : //gist.github.com/tanaikech/d39b4b5ccc5a1d50f5b8b75febd807a6
When Excel file including the cells with the hyperlinks is converted to Google Spreadsheet, such situation can be also seen. In my case, I retrieve the URLs using Sheets API. A sample script is as follows. I think that there might be several solutions. So please think of this as one of them.
When you use this script, please enable Sheets API at Advanced Google Services and API console. You can see about how to enable Sheets API at here.
var spreadsheetId = "### spreadsheetId ###";
var res = Sheets.Spreadsheets.get(spreadsheetId, {ranges: "Sheet1!A1:A10", fields: "sheets/data/rowData/values/hyperlink"});
var sheets = res.sheets;
for (var i = 0; i < sheets.length; i++) {
var data = sheets[i].data;
for (var j = 0; j < data.length; j++) {
var rowData = data[j].rowData;
for (var k = 0; k < rowData.length; k++) {
var values = rowData[k].values;
for (var l = 0; l < values.length; l++) {
Logger.log(values[l].hyperlink) // You can see the URL here.
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
spreadsheetId.Sheet1!A1:A10 is a sample. Please set the range for your situation.rowData is corresponding to the index of row. Each element of values is corresponding to the index of column.If this was not what you want, please tell me. I would like to modify it.