Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74045

< and > change to < and > in HTML code inside a Google Script

$
0
0

I have a Google Spreadsheet script that gets specific values from a sheet and puts them in an array which later is transformed to a HTML table and included in an email. The code works fine until I try to push the HTML code of the tables in the email template I have as HTML file in Google Scripts.

This is the specific part of the code which populates the HTML tables:

var i,j;
      for(i=0, j=0; i<(eval('array'+a+'[2];').length), j<(eval('array'+a+'[2];').length); i++, j++) {
          result += "<tr>";
          result += "<td>"+eval('array'+a+'[2][j];')+"</td>";
          result += "<td>"+eval('array'+a+'[3][j];')+"</td>";
      }

      result += "</tr>";
      result += "</table>";

      eval('htmlTable'+a+'.push("'+result+'");')
      var htmlPush = eval('htmlTable'+a)

      if(htmlPush != '<table border=1></tr></table>'){
          emailBody += '<div style="text-align:center;float: left;display: inline-block;margin-left: 10px;font-family: arial,sans,sans-serif">';
          emailBody += htmlPush;
          emailBody += '</div><span>';
      }

So the HTML code is placed inside a div, one div per table.

The log displays correctly for this code:

<div style="text-align:center;float: left;display: inline-block;margin-left: 10px;font-family: arial,sans,sans-serif"><table border=1><tr><td>Locked Proxy</td><td>Fail</td><tr><td>Final Proxy</td><td>Fail</td><tr><td>Final Script</td><td>Fail</td><tr><td>PM</td><td>Fail</td></tr></table></div><span><div style="text-align:center;float: left;display: inline-block;margin-left: 10px;font-family: arial,sans,sans-serif"><table border=1><tr><td>ME</td><td>Fail</td></tr></table></div><span><div style="text-align:center;float: left;display: inline-block;margin-left: 10px;font-family: arial,sans,sans-serif"><table border=1><tr><td>Locked Script</td><td>Fail</td></tr></table></div><span>



But when I implement this other portion that should replace the "marker" in the HTML template with the actual code, the HTML code changes, specifically the < and > symbols change to &lt; and &gt; and this prevents the code from being displayed at all:
P.S.: I found this part of code on this website as I didn't know how to do this specific function.

var templ = HtmlService
      .createTemplateFromFile('testEmail');

  templ.emailBody = emailBody;
  Logger.log(emailBody);
  var emailBody = templ.evaluate().getContent();

The log displays:

<tr>
    <td align="left" valign="top">
        <div style="height: 33px; line-height: 33px; font-size: 31px;">&nbsp;</div><div style="height: 75px; line-height: 75px; font-size: 73px;">&nbsp;</div>


            &lt;div style=&#34;text-align:center;float: left;display: inline-block;margin-left: 10px;font-family: arial,sans,sans-serif&#34;&gt;&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;Locked Proxy&lt;/td&gt;&lt;td&gt;Fail&lt;/td&gt;&lt;tr&gt;&lt;td&gt;Final Proxy&lt;/td&gt;&lt;td&gt;Fail&lt;/td&gt;&lt;tr&gt;&lt;td&gt;Final Script&lt;/td&gt;&lt;td&gt;Fail&lt;/td&gt;&lt;tr&gt;&lt;td&gt;PM&lt;/td&gt;&lt;td&gt;Fail&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;span&gt;&lt;div style=&#34;text-align:center;float: left;display: inline-block;margin-left: 10px;font-family: arial,sans,sans-serif&#34;&gt;&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;ME&lt;/td&gt;&lt;td&gt;Fail&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;span&gt;&lt;div style=&#34;text-align:center;float: left;display: inline-block;margin-left: 10px;font-family: arial,sans,sans-serif&#34;&gt;&lt;table border=1&gt;&lt;tr&gt;&lt;td&gt;Locked Script&lt;/td&gt;&lt;td&gt;Fail&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;span&gt;                           

    </td>
</tr>


Anyone that could help me with this issue?

Many thanks in advance.


Viewing all articles
Browse latest Browse all 74045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>