Translate

How to Email a Range of Google Spreadsheet Cells


How to Email a Range of Google Spreadsheet Cells – A Complete Guide

Google Sheets is more than just a place to store data — it’s a powerful tool for automating reports, alerts, and data sharing. One especially useful feature is the ability to email a selected range of cells directly from the spreadsheet.

Whether you want to send a weekly sales report, share a dynamic table with your team, or send customer-specific data on demand, you can do it programmatically using Google Apps Script.

In this complete guide, you’ll learn how to email a specific range of Google Spreadsheet cells — formatted like a mini-table — directly into the body of an email. No downloads, no copy-pasting, just clean, automated email reports straight from your spreadsheet.


Why Email a Range of Google Sheets Cells?

You might want to email a range of cells for several reasons:

  • Scheduled reports (daily/weekly summaries)

  • Triggered alerts when specific values change

  • Sharing filtered data with clients or teams

  • Sending personalized data for each recipient

  • Automation of recurring tasks

Google Apps Script makes it easy to pull data from a sheet and email it in a well-formatted layout using simple JavaScript.


Step 1: Prepare Your Google Sheet

Set up your spreadsheet with some sample data. Example:

Name Department Sales
Alice Marketing 5000
Bob Sales 7000
Carol IT 4000

Let’s say this is in range A1:C4.


Step 2: Open the Script Editor

  1. In your Google Sheet, click on Extensions > Apps Script.

  2. Delete any default code in Code.gs.


Step 3: Write the Apps Script to Email the Range

Here’s the complete script:

function emailSpreadsheetRange() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  const range = sheet.getRange("A1:C4"); // Update as needed
  const values = range.getValues();
  
  let htmlTable = '<table border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse;">';
  
  values.forEach((row, rowIndex) => {
    htmlTable += "<tr>";
    row.forEach(cell => {
      const cellTag = rowIndex === 0 ? "th" : "td"; // Header row uses <th>
      htmlTable += `<${cellTag}>${cell}</${cellTag}>`;
    });
    htmlTable += "</tr>";
  });

  htmlTable += "</table>";
  
  const recipient = "recipient@example.com"; // Change to your email
  const subject = "Weekly Sales Report";
  const body = "Please find the current report below:<br><br>" + htmlTable;

  GmailApp.sendEmail(recipient, subject, "", {
    htmlBody: body
  });

  Logger.log("Email sent successfully.");
}

Script Explanation

  • getRange("A1:C4"): Defines which range of cells to email.

  • getValues(): Pulls the cell contents as a 2D array.

  • HTML Table Formatting:

    • The first row is wrapped in <th> (headers).

    • Remaining rows use <td>.

  • GmailApp.sendEmail():

    • Sends the email using the Gmail account connected to the sheet.

    • The htmlBody parameter formats the email to preserve the table layout.

  • Logger: Confirms successful execution in the Apps Script logs.


Step 4: Run the Script

  1. Click the disk icon to save your project.

  2. Click the Run ▶ button on emailSpreadsheetRange.

  3. The first time, it will prompt you to authorize permissions.

  4. After confirming, the email will be sent with your selected range formatted in a table.


Step 5: Make It Dynamic (Optional)

You may want to make the script more dynamic:

Option A: Use Named Ranges

const range = sheet.getRangeByName("SalesTable");

Option B: Find Range by Content

const lastRow = sheet.getLastRow();
const range = sheet.getRange(1, 1, lastRow, 3); // 3 columns from row 1

Option C: Email Based on Cell Value

const emailTo = sheet.getRange("F1").getValue(); // Email in cell F1

Bonus: Add Styling to the Email

You can enhance the table by adding CSS inline styles:

<th style="background-color:#f2f2f2;font-weight:bold;">...</th>

Full example:

htmlTable += `<th style="background-color:#f2f2f2;">${cell}</th>`;

You can also wrap the email with custom branding:

const body = `
  <div style="font-family:Arial, sans-serif;">
    <h2 style="color:#333;">Weekly Report</h2>
    ${htmlTable}
    <p>Sent automatically from Google Sheets.</p>
  </div>
`;

Schedule It to Send Automatically

  1. In Apps Script, go to the clock icon (Triggers).

  2. Click Add Trigger.

  3. Choose the function emailSpreadsheetRange.

  4. Set to run time-driven, daily or weekly.

Now your reports will go out on autopilot.


Use Cases

  • Daily or Weekly Sales Reports

  • Project status reports

  • School attendance summaries

  • Inventory alerts

  • KPI dashboards


Troubleshooting

  • If the script fails:

    • Check for typos in the range reference.

    • Ensure the email address is valid.

  • If the email is blank:

    • Verify that your range actually contains data.

  • If formatting looks wrong:

    • Use inline styles and make sure htmlBody is used (not plain body).

  • If permissions error appears:

    • Run the script manually once to authorize.


Conclusion

With just a few lines of Google Apps Script, you can email a selected range from your Google Spreadsheet — formatted neatly as an HTML table — to any recipient you choose. It’s a powerful and practical automation that can replace countless hours of copy-pasting, file downloads, or manual formatting.

Use this technique to send reports, summaries, notifications, or customized datasets directly from your spreadsheet — on demand or automatically — and supercharge your workflow with the power of Apps Script.