Tired of copy-pasting the same content into multiple Google Docs? Want a fast, free way to do a mail merge-style document generation right inside Google Sheets? Google Apps Script makes this possible! With just a bit of code, you can automatically create personalized Google Docs from each row in your spreadsheet.
Whether you’re generating invoices, certificates, offer letters, or meeting summaries, this tool saves hours of manual work. Best of all — no add-ons required. This is perfect for beginners who want simple automation to boost productivity.
What Is Google Apps Script?
Google Apps Script is a JavaScript-based tool built into Google Workspace. It lets you automate repetitive tasks in Sheets, Docs, Gmail, and more — all without needing to install anything.
Real-Life Scenario: Generate Internship Offer Letters
Let’s say you’re managing a list of selected students in Google Sheets and want to generate offer letters for each of them in Google Docs. Here’s a simple example of how your spreadsheet might look:
Sample Sheet: “Internship Offers”
Name | Role | Start Date | Duration (Months) | Location |
---|---|---|---|---|
Alice Johnson | Marketing Intern | 2025-05-01 | 3 | New York |
Ben Martinez | Data Analyst Intern | 2025-05-15 | 6 | Chicago |
Step-by-Step: Generate Docs from Each Row
- Open your spreadsheet and click on Extensions > Apps Script.
- Delete any existing code and paste the following:
function generateOfferLetters() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Internship Offers"); const data = sheet.getDataRange().getValues(); const templateDocId = 'PASTE_YOUR_TEMPLATE_DOC_ID_HERE'; const folder = DriveApp.createFolder("Generated Offer Letters"); for (let i = 1; i < data.length; i++) { const [name, role, startDate, duration, location] = data[i]; const copy = DriveApp.getFileById(templateDocId).makeCopy(`${name} - Offer Letter`, folder); const doc = DocumentApp.openById(copy.getId()); const body = doc.getBody(); body.replaceText("{{Name}}", name); body.replaceText("{{Role}}", role); body.replaceText("{{StartDate}}", startDate); body.replaceText("{{Duration}}", duration); body.replaceText("{{Location}}", location); doc.saveAndClose(); } SpreadsheetApp.getUi().alert("Offer Letters Created!"); }
- Replace
PASTE_YOUR_TEMPLATE_DOC_ID_HERE
with your Google Doc template ID. - Your template should have placeholders like:
Dear {{Name}},
We are pleased to offer you the position of {{Role}} starting on {{StartDate}} for a duration of {{Duration}} months at our {{Location}} office.
- Click the disk icon to save, then press ▶️ Run to test it.
- Authorize the script when prompted.
Key Benefits
- Time-saving: Create dozens (or hundreds) of documents in seconds.
- Custom output: Each document is personalized using row data.
- Free & native: No add-ons or subscriptions required.
Pro Tips
- Store all generated files in a dedicated Google Drive folder.
- Add a “Status” column in your sheet to mark which rows have been processed.
- Schedule this script with a trigger to run daily or weekly.
- Use Google Drive file links in the sheet for quick access to each generated Doc.
Optional: Add Generated Document Links Back to the Sheet
You can modify the code to paste the Google Doc link into the next column:
sheet.getRange(i + 1, 6).setValue(copy.getUrl());
Quick Cheat Sheet
Term | What It Means |
---|---|
{{Placeholder}} |
Text in a Doc that gets replaced with spreadsheet data |
DocumentApp |
The Apps Script service that lets you edit Google Docs |
DriveApp |
Used to copy and manage Google Drive files and folders |
getDataRange().getValues() |
Grabs all rows and columns with data in a sheet |
This Google Apps Script solution is a powerful, flexible alternative to traditional mail merge tools. It turns your spreadsheet into a document-generation machine — perfect for sending out offer letters, notices, and any kind of personalized form.
The best part? Once set up, it’s just one click (or trigger) away. So go ahead — give it a spin and let Google Docs write itself!