0

I am planning to create HTML table to be embedded in email body. The values in the table come from Googlesheets cells. So I start to create script in my googlesheet. But I have no idea to add the cell value into HTML.

I start using this code:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>

    <?= SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Daily").getRange(13,8).getValue(); ?>

  </body>
</html>

and it worked. But I thought it's not good idea. So I tried to put in tag of like this:

 <!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  <script>
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Daily");
    var tgl = sheet.getRange(13,8).getValue();
  </script>
    <p id="tgl"></p>
  <script>
    document.getElementById('tgl').innerHTML = tgl;
    document.querySelector('#tgl2').innerHTML = tgl.length;
  </script>
  </body>
</html>

But it didn't work. Would you please to give me advice or suggestion? Thank you in advance

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Nur Holis
  • 31
  • 1
  • 6
  • 1
    The first one uses scriptlets and when you run it with evaluate() command it runs server side. The second one is totally client side and in order to do that you need to use google.script.run – Cooper Jun 20 '20 at 15:51
  • In both cases it would be better to combine all of your operations into one function – Cooper Jun 20 '20 at 15:52
  • Btw google.script.run is only initiated clientside so you will also require the withSuccessHandler() which USA callback – Cooper Jun 20 '20 at 15:56
  • All of this is in the guides section of the documentation under client to server communication. – Cooper Jun 20 '20 at 15:57
  • Hi @Cooper, would u please to help what should I write down to fix above. Honestly I am very new to programming. Thank you so much – Nur Holis Jun 20 '20 at 16:54

0 Answers0