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