I'm trying to merge 2 Google doc files using their ids. Below is the code snippet I followed.
var docIDs = ['documentID_1', 'documentID_2', 'documentID_3', 'documentID_4'];
var baseDoc = DocumentApp.openById(docIDs[0]);
var body = baseDoc.getActiveSection();
for (var i = 1; i < docIDs.length; ++i) {
var otherBody = DocumentApp.openById(docIDs[i]).getActiveSection();
var totalElements = otherBody.getNumChildren();
for (var j = 0; j < totalElements; ++j) {
var element = otherBody.getChild(j).copy();
var type = element.getType();
if (type == DocumentApp.ElementType.PARAGRAPH) body.appendParagraph(element);
else if (type == DocumentApp.ElementType.TABLE) body.appendTable(element);
else if (type == DocumentApp.ElementType.LIST_ITEM) body.appendListItem(element);
else throw new Error('Unknown element type: ' + type);
}
}
The merged document looks fine. But the header and footer section is not added in the merged document. I can see there is a header and footer section in the original document. Someone, please help me to fix this.