📋How to Email a Range of Google Spreadsheet Cells

1. Overview

\[ \begin{array}{l} \textbf{You can email specific ranges of cells from a Google Spreadsheet --} \\ \text{using Google Apps Script to extract the data and send it as an email body or attachment.} \\ \textbf{This is useful for sharing reports, summaries, or updates --} \\ \text{without sending the entire spreadsheet.} \end{array} \]

2. Core Steps

\[ \begin{array}{ll} \mathbf{Step\ 1:} & \text{Open the target Google Spreadsheet.} \\ \mathbf{Step\ 2:} & \text{Go to Extensions} \rightarrow \text{Apps Script.} \\ \mathbf{Step\ 3:} & \text{Identify the exact sheet name and range to send.} \\ \mathbf{Step\ 4:} & \text{Use getRange().getValues() to retrieve the range data.} \\ \mathbf{Step\ 5:} & \text{Convert the data array into an HTML table format.} \\ \mathbf{Step\ 6:} & \text{Use MailApp.sendEmail() or GmailApp.sendEmail() to send the content.} \\ \mathbf{Step\ 7:} & \text{(Optional) Schedule with a time-driven trigger for automation.} \end{array} \]

3. Sample Google Apps Script


// Code.gs
function emailSpreadsheetRange() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Report");
  var range = sheet.getRange("A1:D10");
  var values = range.getValues();
  
  // Convert range to HTML table
  var htmlTable = "";
  for (var i = 0; i < values.length; i++) {
    htmlTable += "";
    for (var j = 0; j < values[i].length; j++) {
      htmlTable += "";
    }
    htmlTable += "";
  }
  htmlTable += "
" + values[i][j] + "
"; // Send email MailApp.sendEmail({ to: "[email protected]", subject: "Spreadsheet Range Report", htmlBody: htmlTable }); }

4. Important Notes

\[ \begin{array}{l} \text{• Using HTML formatting makes the email easier to read than plain text.} \\ \text{• Ensure the email recipient has permission if you include spreadsheet links.} \\ \text{• Avoid very large ranges to keep the email size manageable.} \\ \text{• You can attach the range as a CSV by converting it into a string instead.} \\ \text{• Use GmailApp for advanced sending features like inline images.} \end{array} \]

5. Conceptual Flow (in LaTeX)

The process can be described as:

\[ \text{Google Sheets Range} \xrightarrow{\text{Format as HTML Table}} \xrightarrow{\text{Send Email}} \text{Recipient Inbox} \]

Where: \[ \text{Email Body} = \{\text{HTML Table Representation of Selected Cells}\} \]