Aggregate content from multiple documents

Stay organized with collections Save and categorize content based on your preferences.

Coding level: Beginner
Duration: 15 minutes
Project type: Automation with a custom menu

About this solution

To save time and reduce errors from manually copy and pasting, you can automatically import content from multiple documents into one main document. This solution focuses on aggregating project status reports, but you can edit it to fit your needs.

Screenshot of imported project summaries

How it works

The script creates a folder to store the documents from which you want to import content and a template document to start importing from. The script also includes functions that create sample documents to demo this solution.

When a user selects Import summaries from the custom menu, the script gets all the Docs files in the folder and iterates through each. The script looks for a specific string and heading type to identify the summary text it needs to copy. After the text is copied, the script changes the text color of the identifier string to mitigate duplication. The script pastes the summaries into the main document, each in its own single-cell table.

Apps Script services

This solution uses the following services:

  • Document Service: Creates the template and sample source documents. Iterates through each source document looking for new project summaries to import. Imports the summaries to the main document. Updates the source documents to prevent summaries from being imported more than once.
  • Drive Service: Creates a folder to store the source documents. Adds the template document and sample source documents to the folder.
  • Utilities Service: Formats the date that the script adds to the main document each time the script imports summaries from the source documents.
  • Base Service: Uses the Session class to get the script's time zone. The script uses the time zone when adding the date of the import to the main document.

Before you begin

To use this sample, you need the following prerequisites:

  • A Google Account (Google Workspace accounts might require administrator approval)
  • A web browser with access to the internet

Try it

Step 1: Set up the Apps Script project

Click the button below to make a copy of the Aggregate content document.
Make a copy

Step 2: Run a demo

  1. Click Import summaries > Configure > Run demo setup with sample documents. You might need to refresh the page for this custom menu to appear.
  2. When prompted, authorize the script.
  3. Click Import summaries > Configure > Run demo setup with sample documents again.
  4. When prompted, copy the URL of the Drive folder for use in a later step.
  5. Click OK.
  6. Click Import summaries > Import summaries.
  7. When prompted, click OK.
  8. Review the project summaries that were imported from the sample documents.

Step 3: Add and import a summary

  1. In a new browser tab, paste the folder URL to open the Project status folder.
  2. Open the Project ABC file.
  3. Create a new summary to import by adding the following content to the end of the document:
    1. Type Summary and set the text style to Heading 3.
    2. Directly underneath Summary, insert a 1x1 table. Make sure there are no blank lines in between Summary and the table.
    3. In the table, type Hello world!.
  4. Switch back to the main document and click Import summaries > Import summaries.
  5. When prompted, click OK.
  6. View your latest import at the end of the document.

Open the Apps Script project

The sample script's code includes in-line comments to help you understand how it works. To access the code, in the document, click Extensions > Apps Script.


This sample is maintained by Google with the help of Google Developer Experts.