DocMerge is a Google Apps Script that automatically creates personalized documents by replacing placeholder text with custom values from a spreadsheet. It's perfect for generating multiple customized documents like contracts, letters, or certificates without manual editing.
The script takes a template Google Document containing placeholders (like ${name}
or ${date}
) and replaces them with corresponding values from a Google Spreadsheet. This automation helps:
- Save time when creating multiple personalized documents
- Reduce errors from manual copy-pasting
- Maintain consistency across all generated documents
The script recognizes placeholders in this format: ${placeholder_name}
For example:
${name}
might become "John Smith"${date}
might become "January 4, 2025"
The script is smart enough to handle nested placeholders, meaning it will keep replacing placeholders until no more remain in the document. This is particularly useful when dealing with complex templates where one replacement might reveal another placeholder.
- A Google account
- A template Google Document with placeholders
- A Google Spreadsheet with your replacement values
- The DocMerge script
- Download the repository ZIP file from this page
- Open Google Apps Script by visiting script.google.com
- Create a new project
- Copy the contents of
docmerge.gs
into your new project - Update these variables in the script:
sheetId
: Your Google Spreadsheet IDtemplateDocId
: Your template Google Document IDoutputFolderId
: The Google Drive folder ID where new documents will be saved
- Create a Google Spreadsheet with two rows:
- First row: Your placeholder names (without the ${} symbols)
- Second row: The corresponding values
- Name the spreadsheet tab "docvars"
Imagine creating personalized offer letters:
Template text:
Dear ${candidate_name},
We are pleased to offer you the position of ${job_title} at ${company_name},
starting on ${start_date} with an annual salary of ${salary}.
Best regards,
${manager_name}
Spreadsheet setup:
candidate_name | job_title | company_name | start_date | salary | manager_name
John Smith | Senior Dev | TechCorp | 2025-02-01 | $120,000 | Jane Wilson
The script will generate a new document with all placeholders replaced with the corresponding values.
This repository and its documentation may be updated at any time. While efforts are made to keep documentation accurate, there is no guarantee that this README will be immediately updated to reflect all changes in the repository.
The script requires appropriate Google Drive permissions to:
- Read from the specified spreadsheet
- Access the template document
- Create new documents in the output folder
For better performance, consider limiting the size of your spreadsheet to only the rows and columns you need.