copySubDocOne();
copySubDocTwo();
}
function copySubDocOne() {
var mainDocID = ' '; //$Test Main
var mainDocTarget = DocumentApp.openById(mainDocID);
var subOne = ' '
var sourceDocOne = DocumentApp.openById(subOne).getBody();
//var mainDocTarget = DocumentApp.create('CopyOf'+DocumentApp.getActiveDocument().getName());
var mainDocTarget = DocumentApp.openById(mainDocID);
var totalElements = sourceDocOne.getNumChildren();
for (var j = 0; j < totalElements; ++j) {
var body = mainDocTarget.getBody()
var element = sourceDocOne.getChild(j).copy();
var type = element.getType();
//Paragraphs
if (type == DocumentApp.ElementType.PARAGRAPH) {
body.appendParagraph(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Table
else if (type == DocumentApp.ElementType.TABLE) {
body.appendTable(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Bulets Working without Bullets
else if (type == DocumentApp.ElementType.LIST_ITEM) {
body.appendListItem(element).setGlyphType(DocumentApp.GlyphType.BULLET);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Pagebreaks
else if (type == DocumentApp.ElementType.PAGE_BREAK) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Horizontal Rule
else if (type == DocumentApp.ElementType.HORIZONTAL_RULE) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Inline Drawing
else if (type == DocumentApp.ElementType.INLINE_DRAWING) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Inline Image
else if (type == DocumentApp.ElementType.INLINE_IMAGE) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Unsupported
/* else if (type == DocumentApp.ElementType.UNSUPPORTED) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}*/
}
mainDocTarget.saveAndClose();
}
function copySubDocTwo() {
var mainDocID = ' '; //$Test Main
var mainDocTarget = DocumentApp.openById(mainDocID);
var subTwo = ' ' //---Here---
var sourceDocTwo = DocumentApp.openById(subTwo).getBody(); //---Here---Twice--
var totalElements = sourceDocTwo.getNumChildren(); //---Here---
for (var j = 0; j < totalElements; ++j) {
var body = mainDocTarget.getBody()
var element = sourceDocTwo.getChild(j).copy(); //---Here---
var type = element.getType();
//Paragraphs
if (type == DocumentApp.ElementType.PARAGRAPH) {
body.appendParagraph(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Table
else if (type == DocumentApp.ElementType.TABLE) {
body.appendTable(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Bullets
//Bulets Working without Bullets
else if (type == DocumentApp.ElementType.LIST_ITEM) {
body.appendListItem(element).setGlyphType(DocumentApp.GlyphType.BULLET);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Pagebreaks
else if (type == DocumentApp.ElementType.PAGE_BREAK) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Horizontal Rule
else if (type == DocumentApp.ElementType.HORIZONTAL_RULE) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Inline Drawing
else if (type == DocumentApp.ElementType.INLINE_DRAWING) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Inline Image
else if (type == DocumentApp.ElementType.INLINE_IMAGE) {
body.appendListItem(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}
//Unsupported
/*else if (type == DocumentApp.ElementType.UNSUPPORTED) {
body.append(element);
mainDocTarget.saveAndClose();
var mainDocTarget = DocumentApp.openById(mainDocID);
}*/
}
mainDocTarget.saveAndClose();
}