Allow for copying to HeaderSection and FooterSection, as well as Body

This commit is contained in:
Adam Goldsmith 2020-03-18 14:38:34 -04:00
parent c8840a817a
commit 862a1d9f63

13
Code.ts
View File

@ -5,9 +5,14 @@ function onOpen() {
.addToUi();
}
type DocSection =
| GoogleAppsScript.Document.Body
| GoogleAppsScript.Document.HeaderSection
| GoogleAppsScript.Document.FooterSection;
function copyElement(
source_element: GoogleAppsScript.Document.Element,
dest: GoogleAppsScript.Document.Body,
dest: DocSection,
index?: number
) {
const element = source_element.copy();
@ -31,11 +36,7 @@ function copyElement(
);
}
function copyBody(
source: GoogleAppsScript.Document.Body,
dest: GoogleAppsScript.Document.Body,
index?: number
) {
function copySection(source: DocSection, dest: DocSection, index?: number) {
const totalElements = source.getNumChildren();
for (let j = 0; j < totalElements; ++j) {
if (index) copyElement(source.getChild(j), dest, index + j);