So I have a Google Spreadsheet and want to create automated daily reports by emailing a portion of the range from my "Daily report" sheet as a HTML table using Google Spreadsheet triggers.
I have some conditional formatting in the sheet to get it to paint all cells in column that have MAX(value) in said column.
I've managed to create the code below which emails me the range but Gmail doesn't recognized it as a HTML table but plain text.
I've tried using {htmlBody: htmltable} in the MailApp.sendEmail function but Gmail just errors out ([Ljava.lang.Object;@SOME_HASH.
Question 1: How can I email the table as HTML and not plain text with all the HTML tags visible?
Question 2: How could I improve my code to get Google Sheets cell formatting and apply it to the table cells instead of using ad hoc formatting just to get the table to look OK?
function sendMail(){
var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var data = sh.getRange("A2:O38").getValues();
//var htmltable =[];
var TABLEFORMAT = 'cellspacing="2" cellpadding="2" dir="ltr" border="1" style="width:100%;table-layout:fixed;font-size:10pt;font-family:arial,sans,sans-serif;border-collapse:collapse;border:1px solid #ccc;font-weight:normal;color:black;background-color:white;text-align:center;text-decoration:none;font-style:normal;'
var htmltable = ['<table ' + TABLEFORMAT +' ">'];
for (row = 0; row<data.length; row++){
htmltable.push ('<tr>');
for (col = 0 ;col<data[row].length; col++){
if (data[row][col] === "" || 0) {htmltable.push('<td>' + 'None' + '</td>');}
else
if (row === 0) {
htmltable.push ('<th>' + data[row][col] + '</th>');
}
else {htmltable.push('<td>' + data[row][col] + '</td>');}
}
htmltable.push('</tr>');
}
htmltable.push ('</table>');
Logger.log(data);
MailApp.sendEmail(Session.getActiveUser().getEmail(), 'Daily report','' ,{htmlBody: htmltable})
}