Google apps script 将电子表格Url单元格传递给src Google电子表格&;谷歌文件

Google apps script 将电子表格Url单元格传递给src Google电子表格&;谷歌文件,google-apps-script,google-sheets,google-spreadsheet-api,google-docs-api,Google Apps Script,Google Sheets,Google Spreadsheet Api,Google Docs Api,我的电子表格中有一列谷歌文档的URL(它是第10-J列),我编写了一个脚本,这样,如果我点击文档中的一个单元格,它将恢复该行,该列通过一个bouton常量=10,并将在文本框中启动文档: var TITLE = 'Sidebar Title'; COLUMN_URL = 10; function showHandle() { var link = SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange(

我的电子表格中有一列谷歌文档的URL(它是第10-J列),我编写了一个脚本,这样,如果我点击文档中的一个单元格,它将恢复该行,该列通过一个bouton常量=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>
var TITLE='Sidebar TITLE';
列URL=10;
函数showHandle(){
var link=SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue();
Logger.log('URL为:'+链接);
var body=DocumentApp.openByUrl(link.getBody();
Logger.log('主体为'+主体);
var ui=HtmlService.createTemplateFromFile('ModelsDialog')
.评估()
.setWidth(1000)
.设置高度(500);
SpreadsheetApp.getUi().showModalDialog(ui,标题);
}
事实上,我想在这里传入src->URL

SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue()但它不认识它。我不知道如何在日志中集成src。如果我直接输入单元格的url,链接会正确显示,但我有70行对应于谷歌文档。如果你有想法,非常感谢


您可以将
link
设置为全局变量:

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

//html code    
<iframe  src= "<?= link ?>" height="1000" width="90%"></iframe>
//gs代码
var link=SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue();
//html代码

在HTML代码中使用scriptlet,在应用程序中创建HTML模板时,脚本将链接值传递给HTML模板中的scriptlet,然后对其求值并为其创建模式对话框。[官方文档](HTML服务:模板化HTML |应用程序脚本|谷歌开发者›模板)
function getLink() {
    return SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue();
}

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