HeadersAndFooters
HeadersAndFooters:
Provides access to both headers and footers for a section.
Remarks
Section titled “Remarks”HeadersAndFooters is a container that provides access to both the headers and footers
for a section. It’s obtained via Section.headersAndFooters and acts as a gateway
to the HeadersFooters collections for headers and footers separately.
Headers appear at the top of pages, footers at the bottom. Both can have different content for:
- Default pages (typically odd pages)
- First page (often different for title pages)
- Even pages (for two-sided printing)
Examples
Section titled “Examples”Access headers and footers:
const hf = section.headersAndFooters();const headers = hf.headers();const footers = hf.footers();
// Work with default headerconst defaultHeader = headers.default();if (defaultHeader) { const para = defaultHeader.addParagraph(); para.asTextView().setText('Document Title');}
// Work with default footerconst defaultFooter = footers.default();if (defaultFooter) { const para = defaultFooter.addParagraph(); para.asTextView().setText('Page ');}Replace text in all headers and footers:
const hf = section.headersAndFooters();
// Replace across all headers and footers (default, first, even)const count = hf.replaceText(/Company Name/g, 'Acme Corporation');console.log(`Updated ${count} occurrences in headers/footers`);Add content to different header/footer types:
const hf = section.headersAndFooters();
const firstHeader = hf.headers().first();if (firstHeader) { const para = firstHeader.addParagraph(); para.asTextView().setText('Title Page Header');}
const defaultHeader = hf.headers().default();if (defaultHeader) { const para = defaultHeader.addParagraph(); para.asTextView().setText('Chapter 1');}Properties
Section titled “Properties”replaceText
Section titled “replaceText”replaceText:
ReplaceTextSignature
Replaces all occurrences of a pattern in all headers and footers.
Remarks
Section titled “Remarks”Convenience method that searches and replaces text across all headers and footers for this section, including default, first page, and even page variants.
See ReplaceTextSignature for detailed parameter and usage information.
Examples
Section titled “Examples”const count = headersAndFooters.replaceText('Draft', 'Final');console.log(`Updated ${count} occurrences`);headersAndFooters.replaceText(/\(c\)/gi, { text: '©', formatting: { fontSize: 10 }});Methods
Section titled “Methods”headers()
Section titled “headers()”headers():
HeadersFooters
Gets the headers collection for this section.
Returns
Section titled “Returns”A HeadersFooters object providing access to header variants
Remarks
Section titled “Remarks”Returns the headers collection, which provides access to default, first page, and even page headers. Headers appear at the top of pages.
Example
Section titled “Example”const headers = headersAndFooters.headers();const defaultHeader = headers.default();const firstPageHeader = headers.first();const evenPageHeader = headers.even();footers()
Section titled “footers()”footers():
HeadersFooters
Gets the footers collection for this section.
Returns
Section titled “Returns”A HeadersFooters object providing access to footer variants
Remarks
Section titled “Remarks”Returns the footers collection, which provides access to default, first page, and even page footers. Footers appear at the bottom of pages.
Example
Section titled “Example”const footers = headersAndFooters.footers();const defaultFooter = footers.default();const firstPageFooter = footers.first();const evenPageFooter = footers.even();