Skip to content

Instantly share code, notes, and snippets.

@phillypb
Created December 18, 2018 19:15
Show Gist options
  • Save phillypb/6a0484b366f4cac564548817ef69e028 to your computer and use it in GitHub Desktop.
Save phillypb/6a0484b366f4cac564548817ef69e028 to your computer and use it in GitHub Desktop.
function copyDoc_Paragraphs() {
// document ID of the file to be copied
var docId = 'insert your file ID';
// instruct DriveApp to get this document
var templateDoc = DriveApp.getFileById(docId);
// folder ID of where the copied file is to be saved
var folderId = 'insert your folder ID';
// instruct DriveApp to get this folder
var destinationFolder = DriveApp.getFolderById(folderId);
// copy the file to the destination and get the Url
var newDocUrl = templateDoc.makeCopy('new doc', destinationFolder).getUrl();
// open the file by the Url
var newDoc = DocumentApp.openByUrl(newDocUrl);
// get the body of the document
var docBody = newDoc.getBody();
// replace the tag with 'Eric'
docBody.replaceText('<<Name>>', 'Eric');
// add 5 paragraph lines
for (var i=1; i<6; i++) {
docBody.appendParagraph('this is paragraph ' + i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment