Autofill Google Docs with Google Sheets in just one click using Google Apps Script. This free guide will show you how to automate document creation quickly and efficiently.



What You'll Need


  • A Google account
  • A Google Doc template
  • A Google Sheet with your data

Create a Google Doc Template


First, create a Google Doc template. This is the document you will fill with data. Use placeholders where you want the data to go. Placeholders are words or phrases inside double curly braces, like this: {{Name}}, {{Address}}, {{Email}}.


For example, your template might look like this:



Set Up Your Google Sheet


Next, create a Google Sheet. This sheet will hold the data that you want to put into your Google Doc template. Make sure the column headers in your sheet match the placeholders in your document. For example, if you have a placeholder called {{Name}}, you need a column in your sheet with the header "Name".


Add the Google Apps Script Code


Now, it's time to add the code that makes the magic happen. Google Apps Script is a tool that lets you automate tasks in Google Workspace.


  1. Open your Google Sheet.
  2. Click "Extensions" and choose "Apps Script." This will open a new tab with the Apps Script editor.
  3. Copy the Google Apps Script code.
  4. Paste the code into the Apps Script editor.
  5. Click the "Save" icon to save the script.

Run the Script


Before you can use the script, you need to run it once to give it permission to access your Google Docs and Google Sheets.


  • In the Apps Script editor, click the "Run" button. It looks like a play button.
  • A popup will ask you to authorize the script. Click "Review Permissions."
  • Choose your Google account.
  • Click "Allow" to give the script the necessary permissions.

Use the Sidebar Form


After you run the script, a new menu will appear in your Google Sheet.


  1. Go back to your Google Sheet
    .
  2. You should now see a menu named "Outright Store." Click on it.
  3. Choose "Show sidebar." A sidebar form will open on the right side of the screen.

Enter the Document ID and Headers


The sidebar form has two fields: "Template Document ID" and "Header."


  1. Get the Template Document ID: Open your Google Doc template. Look at the URL in the address bar. The Document ID is a long string of letters, numbers, and symbols between /d/ and /edit. Copy this ID.
  2. Paste the Document ID into the "Template Document ID" field in the sidebar form.
  3. Enter the Headers: In the "Header" field, type the column headers from your Google Sheet, separated by commas. Make sure the order of the headers matches the order of the placeholders in your Google Doc template. For example, if your template has {{Name}}, {{Address}}, and {{Email}}, you would type "Name,Address,Email" in the "Header" field.
  4. Click "Create Header."

Autofill Your Documents!


Now you're ready to autofill your documents!


  1. Enter the data for each row in your Google Sheet.
  2. Click the "Submit" button in the sidebar form.
  3. A new Google Doc will be created. It will be filled with the data from the first row of your Google Sheet.

Repeat these steps for each row of data in your sheet. Each time you click "Submit," a new Google Doc will be created with the data from that row.


Tips for Success


  • Make sure your headers match. The column headers in your Google Sheet must exactly match the placeholders in your Google Doc template. Even a small difference in spelling or capitalization will cause the script to fail.
  • Check your permissions. If the script isn't working, make sure you have given it the necessary permissions to access your Google Docs and Google Sheets.
  • Use clear placeholders. Choose placeholders that are easy to understand and remember. This will help you avoid mistakes when you're setting up your template and your sheet.


Conclusion


Using Google Apps Script to autofill Google Docs can save you a lot of time and effort. By following these steps, you can quickly and easily create personalized documents from data in a Google Sheet.