title: Emailing Google Sheet range (with or without formatting) as a HTML table in a Gmail message
body: <p>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.</p>
  
  <p>I have some conditional formatting in the sheet to get it to paint all cells in column that have MAX(value) in said column.</p>
  
  <p>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.</p>
  
  <p>I've tried using {htmlBody: htmltable} in the MailApp.sendEmail function but Gmail just errors out ([Ljava.lang.Object;@SOME_HASH.</p>
  
  <p>Question 1: <strong>How can I email the table as HTML and not plain text with all the HTML tags visible?</strong></p>
  
  <p>Question 2: <strong>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?</strong></p>
  
  <pre><code>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 = ['&lt;table ' + TABLEFORMAT +' "&gt;'];
  
  for (row = 0; row&lt;data.length; row++){
  
  htmltable.push ('&lt;tr&gt;');
  
  for (col = 0 ;col&lt;data[row].length; col++){
    if (data[row][col] === "" || 0) {htmltable.push('&lt;td&gt;' + 'None' + '&lt;/td&gt;');} 
    else
      if (row === 0)  {
        htmltable.push ('&lt;th&gt;' + data[row][col] + '&lt;/th&gt;');
      }
  
    else {htmltable.push('&lt;td&gt;' + data[row][col] + '&lt;/td&gt;');}
  }
  
       htmltable.push('&lt;/tr&gt;');
  }
  
       htmltable.push ('&lt;/table&gt;');
       Logger.log(data);
  MailApp.sendEmail(Session.getActiveUser().getEmail(), 'Daily report','' ,{htmlBody: htmltable})
  }
  </code></pre>