0

I can't figure out an elementary mistake. When I run the following script the output I get is: <?= head1 ?> <?= head2 ?> .

I'm trying to make head1 and head2 printing scriptlets where it references the google apps script and prints the relevant value defined in the google apps script.

Google Apps Script:

function openPage() {
  var html = HtmlService.createHtmlOutputFromFile('Index');
  SpreadsheetApp.getUi().showModalDialog(html, 'Sample Heading');
  var question = 0;
  var answer = 1;
  var category = 2;
  var to_publish = 3;
  var publish_date = 4;

  var questions_faq = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FAQs");
  var heading_1 = questions_faq.getRange("A1").getValue;
  var heading_2 = questions_faq.getRange("B1").getValue;
  var questions = questions_faq.getRange("A2:B" + questions_faq.getLastRow()).getValues();
  html.head1 = heading_1;
  html.head2 = heading_2; 

  
}

and my html script is here:

<!DOCTYPE html>
<html>
<table>
  <tr>
    <th><?= head1 ?></th>
    <th><?= head2 ?></th>
  </tr>
</table>
<main></main>
<script> src = "Code.gs" </script>
</html>

Rubén
  • 34,714
  • 9
  • 70
  • 166
bibby
  • 21
  • 5

2 Answers2

0

Try it this way:

function openPage() {f
  var tempt = HtmlService.createTemplateFromFile('Index');
  SpreadsheetApp.getUi().showModalDialog(html, 'Sample Heading');
  var question = 0;
  var answer = 1;
  var category = 2;
  var to_publish = 3;
  var publish_date = 4;

  var questions_faq = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FAQs");
  var heading_1 = questions_faq.getRange("A1").getValue;
  var heading_2 = questions_faq.getRange("B1").getValue;
  var questions = questions_faq.getRange("A2:B" + questions_faq.getLastRow()).getValues();
  temp.head1 = heading_1;
  temp.head2 = heading_2; 
  temp.evaluate(); 
}
Cooper
  • 59,616
  • 6
  • 23
  • 54
0

SUGGESTION

In my understanding, you want the values of A1 to be the head1 & B1 as the head2 in your HTML file when shown on a sheet dialog window. You may try this tweaked script below.

Tweaked Script

function openPage() {
  var html = HtmlService.createTemplateFromFile('Index');
  var question = 0;
  var answer = 1;
  var category = 2;
  var to_publish = 3;
  var publish_date = 4;

  var questions_faq = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FAQs");
  var heading_1 = questions_faq.getRange("A1").getValue();
  var heading_2 = questions_faq.getRange("B1").getValue();
  var questions = questions_faq.getRange("A2:B" + questions_faq.getLastRow()).getValues();
  html.head1 = heading_1;
  html.head2 = heading_2;
  SpreadsheetApp.getUi().showModalDialog(html.evaluate(), 'Sample Heading')
}

This answer was derived from this post

Demonstration

  • After running the script:

enter image description here

Reference

SputnikDrunk2
  • 3,398
  • 1
  • 5
  • 17