将电子表格 Url 单元格传递给 src Google 电子表格和 Google 文档

Pass a Spreadsheet Url cell to the src Google Spreadsheet & Google Docs

我的电子表格中有 URL 文档的 URL 列(这是第 10 - J 列),我做了一个脚本,如果我点击文档中的一个单元格,它将通过一个按钮恢复列为常量 = 10 的行,并将在文本框中启动文档:

var TITLE = 'Sidebar Title';
COLUMN_URL = 10;

function showHandle() {

  var link = SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue();
  Logger.log('The URL is : ' +  link );
  var body = DocumentApp.openByUrl(link).getBody();
  Logger.log('The body is ' +  body );

  var ui = HtmlService.createTemplateFromFile('ModeLessDialog')
      .evaluate()
      .setWidth(1000)
      .setHeight(500);
  SpreadsheetApp.getUi().showModalDialog(ui, TITLE);
}

<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<iframe  src= "link + ' '" height="1000" width="90%"></iframe>
</body>
</html>

其实我想传入src -> 这里的URL

SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue() but it does't recognize it .I don't know how to integrate in the src in the logs the link is shown correctly if i put directly the url of the cell it works but i have 70 rows that corresponds to a Google doc.If you have an idea thank you very much.

你可以让link成为一个全局变量:

//gs code
var link = SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue();

//html code    
<iframe  src= "<?= link ?>" height="1000" width="90%"></iframe>

或者调用一个函数 returns 你的 link:

function getLink() {
    return SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue();
}

<iframe  src= "<?= getLink() ?>" height="1000" width="90%"></iframe>