0
votes

I have a column of URL(it's the column 10 - J) of Google Docs in my Spreadsheet and I did a script so that if I click on a cell in the document it will recuperate the row the column is constant = 10 via a bouton and will launch the document in a text box:

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>

In fact I want to pass in the src -> the URL here

SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRowIndex(),COLUMN_URL).getValue() but it does't recognize it enter image description here.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.

1
Use Scriptlets in HTML code and when creating the HTML template in the Apps Script pass the link value to the scriptlet in the HTML template and then evaluate it and create a Modal Dialog for it. [Official Doc ](HTML Service: Templated HTML | Apps Script | Google Developers developers.google.com › templates ) - Suhail Ansari

1 Answers

1
votes

You can make link a global variable:

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

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

or alternatively call a function that returns your link:

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

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