Section
Section:
{}Properties handle for a section within a document body.
Remarks
Section titled “Remarks”Section is a properties handle for a contiguous range of body content. It exposes:
- Page setup (size, margins, orientation) via
pageSetup - Headers and footers via
headersAndFooters
Sections are emergent: a section’s range is delimited by paragraphs carrying a
section break (Paragraph.hasSectionBreak). The trailing section has no
closing break, so Body.sections always returns N + 1 entries where
N is the number of paragraphs carrying a break.
Block-level content (paragraphs and tables) is owned by Body, not by
Section. To read or mutate block-level content, get the container via
Body.content and call BlockLevelContainer.blocklevels,
BlockLevelContainer.addParagraph, BlockLevelContainer.addTable,
or BlockLevelContainer.removeElement. To navigate from a block to the
section it belongs to, use Paragraph.findSection or
Table.findSection.
Examples
Section titled “Examples”Configure a section’s page setup and headers/footers:
const section = document.body().sections()[0];
const size = section.pageSetup().pageSize();console.log(`Page size: ${size.width} x ${size.height}`);
const headers = section.headersAndFooters().headers();const defaultHeader = headers.default();if (defaultHeader) { defaultHeader.addParagraph().asTextView().setText('Document Title');}Find the section a block belongs to:
const block = body.content().blocklevels()[5];const section = block.findSection();section?.pageSetup().setPageMargins({ top: 36, bottom: 36, left: 72, right: 72 });Methods
Section titled “Methods”pageSetup()
Section titled “pageSetup()”pageSetup():
PageSetup
Gets the page setup configuration for this section.
Returns
Section titled “Returns”The PageSetup for this section
Remarks
Section titled “Remarks”Returns the page setup object that controls the physical page properties for this section, including page size (width/height) and margins. Each section can have different page setup settings.
Example
Section titled “Example”const pageSetup = section.pageSetup();const size = pageSetup.pageSize();const margins = pageSetup.pageMargins();
console.log(`Page: ${size.width}x${size.height}`);console.log(`Margins: T:${margins.top} B:${margins.bottom}`);headersAndFooters()
Section titled “headersAndFooters()”headersAndFooters():
HeadersAndFooters
Gets the headers and footers configuration for this section.
Returns
Section titled “Returns”The HeadersAndFooters container for this section
Remarks
Section titled “Remarks”Returns an object that provides access to headers and footers for this section. Headers and footers can have different content for the first page, even pages, and default (odd) pages.
Example
Section titled “Example”const hf = section.headersAndFooters();const headers = hf.headers();const footers = hf.footers();
// Access default headerconst defaultHeader = headers.default();if (defaultHeader) { const para = defaultHeader.addParagraph(); para.asTextView().setText('Document Title');}