title: Email Google Sheet cells and format
body: <p><strong>Background:</strong> I am a teacher. I gave a test through Forms. I graded the test by using various background colors on each cell (which represented an answer to a question by a student). Each row of the sheet has their email address in Column B. </p>
  
  <p><strong>Problem:</strong> I would like to email the entire row, including formatting, to that address in Column B so that each student has a record of their answers and how I graded them.</p>
  
  <p><strong>Question:</strong> How can I email a row of data, including formatting?</p>
  
  <p>I am working with the following script, which works well for emailing a single cell without formatting:</p>
  
  <pre><code>`function sendEmails() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var startRow = 2;  // First row of data to process
    var numRows = 1;   // Number of rows to process
    // Fetch the range of cells A2:B3
    var dataRange = sheet.getRange(startRow, 1, numRows, 2)
    // Fetch values for each row in the Range.
    var data = dataRange.getValues();
    for (i in data) {
      var row = data[i];
      var emailAddress = row[1];  // Second column
      var message = row[0];       // I want the whole row, including formatting.
      var subject = "Sending emails from a Spreadsheet";
      MailApp.sendEmail(emailAddress, subject, message);
      ContentService.createTextOutput("hello world!");
    }
  }`
  </code></pre>