Effortlessly generate bulk Google Docs with Google Apps Script

Dan Fedick
2 min readDec 28, 2023

If you need to generate a list of Google Drive files based on a template, you can use the Google Apps Script language to quickly generate those files.

To use Google Apps Script, you can go to the following URL, and login with your Google account. Once you are in the Google Apps Script, you have to create a new project and add and run the following function:

function createDocs() {
// File ID:
var templateId = '<TEMPLATE_ID>';
// Folder ID:
var folderId = '<FOLDER_ID>';
var num_files = 250
var template = DriveApp.getFileById(templateId);
var folder = DriveApp.getFolderById(folderId);

for (var i = 1; i <= num_files ; i++) {
var formattedNumber = ("000" + i).slice(-3);
var fileName = "FILE-NAME-" + formattedNumber;
var copy = template.makeCopy(fileName, folder);
}
}

The above function will generate 250 files with the names FILE-NAME-001through FILE-NAME-250 in the directory specified. You can obviously change the name and the number of files you want to generate, the template file, and the output folder in Google Drive.

This uses the makeCopy function to generate these files.

The templateId and the folderId are derived from the URL when you browse to the folder, or the drive document.

Once you have modified your project, just click run and you should start to see your files being generated in the folder.

Let me know if you have any questions, or if this worked for you!

--

--