Home > database >  AppScript get values from spreadsheet to html
AppScript get values from spreadsheet to html

Time:03-05

I have a list of links that I have in my spreadsheet. I created a button. Now I select the link and I click the download button. I want it to start download right away the document from the link.

This is what I have right now:

 function RDownload() {
  var RConSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LookUp");
  var LNumber = RConSheet.getRange("C2").getValue;
  var RLinkID = RConSheet.getRange("J4").getValue();
  var RLink= "https://drive.google.com/uc?export=download&id=" RLinkID;

  return RLink;;
};

/* download RCon */

function test(){
var form = HtmlService.createHtmlOutputFromFile('DownloadR');
SpreadsheetApp.getUi().showModalDialog(form, "Downloading");
}

I don't know how to get value from RLink and put it in the html form.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <a href='here I want to have a value from RLink' target='_blank'>Download</a>
  </body>
</html>

CodePudding user response:

Description

I didn't need to change your Code.gs but I've modified your HTML to include a call to the server to get RLink using google.script.run.withSuccessHandler().

HTML

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <a id="rlink" href='here I want to have a value from RLink' target='_blank'>Download</a>
    <script>
      (function () {
        google.script.run.withSuccessHandler( function (rlink) {
          alert(rlink);
          document.getElementById("rlink").href = rlink;
        }).RDownload();
      })();
    </script>
  </body>
</html>

References

  • Related