我想将 Google 表格中的 URL 替换为我的 Google Dcs 正文中的个性化超链接

I want to replace an URL in Google Sheets as a personalized hyperlink in my Google Dcs body

我在像 this 这样的 Google 表格单元格之一中有一个 link,我知道如何通过以下步骤将它附加到 Google 文档正文:

const body = doc.getBody();
body.replaceText('{{MyURL}}',row[number]

这给了我你可以观看的结果here but I would like to have this result instead (watch here)

那么,我该怎么做呢?任何帮助将不胜感激!

试试这个:

function insertHyperlink() {
  var doc = DocumentApp.openById('Insert Doc ID here');
  var body = doc.getBody();
  var text = "Google Link";
  var url = "https://www.google.com/";
  body.replaceText('{{MyURL}}', text); //replace text with hyperlink label
  var foundElement = body.findText(text); //find the hyperlink label
  var foundText = foundElement.getElement().asText(); 
  var start = foundElement.getStartOffset(); 
  var end = foundElement.getEndOffsetInclusive();
  foundText.setLinkUrl(start, end, url)
}

参考文献: