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 <
and >
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;"> </div><div style="height: 75px; line-height: 75px; font-size: 73px;"> </div>
<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>
</td>
</tr>
Anyone that could help me with this issue?
Many thanks in advance.