Attach or Display an Excel Workbook in Gmail with Node.js
Question details
The user wants to send an Excel workbook in a Gmail message using Node.js and know whether it can be embedded as an editable spreadsheet.

- Product
- Gmail, Node.js, and Microsoft Excel
- Device & OS
- not provided
- Scenario
- A Node.js application needs to send workbook content by email.
- Observed behavior
- Gmail does not display an XLSX file as an editable spreadsheet inside the message body. The workbook can be attached, or worksheet content can be displayed as static HTML.
Have the XLSX file and recipient address ready, and make sure Node.js is installed. For Gmail SMTP, use OAuth 2.0 or an app password where available; an app password generally requires 2-Step Verification.
Attach the Excel workbook with Nodemailer
Use an attachment when the recipient needs the original workbook and its editable spreadsheet content.
Open a terminal in your Node.js project and run `npm install nodemailer`.
Set the `GMAIL_USER` and `GMAIL_APP_PASSWORD` environment variables to your Gmail address and app password. Create an app password in your Google Account security settings if your account supports it, or configure Nodemailer with OAuth 2.0 instead.
Create a JavaScript file such as `send.js` with the code below. Replace the recipient and workbook path, then run `node send.js`. const nodemailer = require('nodemailer'); const transport = nodemailer.createTransport({ service: 'gmail', auth: { user: process.env.GMAIL_USER, pass: process.env.GMAIL_APP_PASSWORD } }); transport.sendMail({ from: process.env.GMAIL_USER, to: 'recipient@example.com', subject: 'Excel workbook', text: 'Please find the workbook attached.', attachments: [{ filename: 'workbook.xlsx', path: './workbook.xlsx' }] }).then(() => console.log('Message sent')) .catch(console.error);

Convert a worksheet to HTML for the Gmail message body
Use a static HTML table when recipients should see worksheet content directly in the email.
Prepare an Excel Attachment in WPS Spreadsheet
Use WPS Spreadsheet to create or review the workbook, save it as an XLSX file, and send it from Node.js as a Gmail attachment. Gmail will not make the attachment interactive inside the message body.
- 1. Open the workbook: Open WPS Spreadsheet and choose Open to select your Excel workbook, or create a new spreadsheet.
- 2. Save an XLSX copy: Choose File > Save As and select the Excel XLSX format. Note the saved file path.
- 3. Set up the Node.js mailer: In your project terminal, run `npm install nodemailer` and configure Gmail authentication using an app password or OAuth 2.0.
- 4. Send the workbook: Use the Nodemailer attachment code in the first solution, set its `path` to your saved XLSX file, and run the JavaScript file with Node.js.

Frequently Asked Questions
Can a recipient edit an XLSX workbook directly inside a Gmail message?
No. Gmail does not embed an interactive XLSX spreadsheet as native message content. Attach the workbook so the recipient can open it in a spreadsheet application.
How do I show worksheet data in the email body?
In Node.js, use a library such as `xlsx` to convert a worksheet to HTML, sanitize the result, and pass it to Nodemailer's `html` field. The result is a static preview.
Why can't I create a Gmail app password?
App passwords generally require 2-Step Verification and may be unavailable for some accounts or organization policies. Check your Google Account security settings or use OAuth 2.0 with Nodemailer.
Will an HTML worksheet preview preserve all Excel features?
No. An HTML table does not retain workbook interactivity, and some formatting or formulas may not carry over. Attach the XLSX file if the recipient needs the original workbook.




