Skip to main content

HeaderFooter

Struct HeaderFooter 

Source
pub struct HeaderFooter {
    pub blocks: Vec<Block>,
}
Expand description

The content of a header or footer: a sequence of block-level content (paragraphs and tables) — the same content model WordprocessingML gives the document body (CT_HdrFtr reuses EG_BlockLevelElts, the exact group w:body uses), just without a w:body wrapper or section properties of its own.

Fields§

§blocks: Vec<Block>

The blocks that make up this header/footer’s content, in order.

Implementations§

Source§

impl HeaderFooter

Source

pub fn new() -> HeaderFooter

Creates an empty header/footer.

Examples found in repository?
examples/docx_page_layout.rs (line 27)
15fn main() -> office_toolkit::Result<()> {
16    let path = output_path("docx_page_layout.docx");
17
18    let page_setup = PageSetup::new()
19        .with_size_twips(16_838, 11_906) // A4 landscape, in twentieths of a point
20        .with_orientation(Orientation::Landscape)
21        .with_margins_twips(1_440, 1_440, 1_800, 1_800) // top, bottom, left, right
22        .with_header_footer_margins_twips(720, 720)
23        .with_gutter_twips(0)
24        .with_columns(2);
25
26    let default_header =
27        HeaderFooter::new().with_paragraph(Paragraph::with_text("Default header — every page"));
28    let default_footer =
29        HeaderFooter::new().with_paragraph(Paragraph::with_text("Default footer — every page"));
30    let first_header = HeaderFooter::new()
31        .with_paragraph(Paragraph::with_text("First-page header — cover page only"));
32    let even_header = HeaderFooter::new().with_paragraph(Paragraph::with_text("Even-page header"));
33
34    let document = Document::new()
35        .with_page_setup(page_setup)
36        .with_header(default_header)
37        .with_footer(default_footer)
38        .with_header_first(first_header)
39        .with_header_even(even_header)
40        .with_paragraph(heading("Page setup: A4 landscape, custom margins, two columns", false))
41        .with_paragraph(Paragraph::with_text(
42            "This document is landscape A4, with wider left/right margins than top/bottom, and its body text \
43             flows in two columns. Look at the page in Word's Layout view to see the effect.",
44        ))
45        .with_paragraph(heading("Headers and footers", true))
46        .with_paragraph(Paragraph::with_text(
47            "Page 1 (this page) uses the first-page header, since \"different first page\" headers are set. \
48             Every other page uses the default header shown above, and every page uses the default footer.",
49        ))
50        .with_paragraph(heading("A third page, to see the default header again", true))
51        .with_paragraph(Paragraph::with_text(
52            "If Word is configured to show even/odd pages differently, this page alternates between the \
53             default and even-page header depending on whether it lands on an even or odd page number.",
54        ));
55
56    document.save_to_file(&path)?;
57    println!("Wrote {}", path.display());
58    Ok(())
59}
Source

pub fn with_paragraph(self, paragraph: Paragraph) -> HeaderFooter

Appends a paragraph block and returns it for chaining.

Examples found in repository?
examples/docx_page_layout.rs (line 27)
15fn main() -> office_toolkit::Result<()> {
16    let path = output_path("docx_page_layout.docx");
17
18    let page_setup = PageSetup::new()
19        .with_size_twips(16_838, 11_906) // A4 landscape, in twentieths of a point
20        .with_orientation(Orientation::Landscape)
21        .with_margins_twips(1_440, 1_440, 1_800, 1_800) // top, bottom, left, right
22        .with_header_footer_margins_twips(720, 720)
23        .with_gutter_twips(0)
24        .with_columns(2);
25
26    let default_header =
27        HeaderFooter::new().with_paragraph(Paragraph::with_text("Default header — every page"));
28    let default_footer =
29        HeaderFooter::new().with_paragraph(Paragraph::with_text("Default footer — every page"));
30    let first_header = HeaderFooter::new()
31        .with_paragraph(Paragraph::with_text("First-page header — cover page only"));
32    let even_header = HeaderFooter::new().with_paragraph(Paragraph::with_text("Even-page header"));
33
34    let document = Document::new()
35        .with_page_setup(page_setup)
36        .with_header(default_header)
37        .with_footer(default_footer)
38        .with_header_first(first_header)
39        .with_header_even(even_header)
40        .with_paragraph(heading("Page setup: A4 landscape, custom margins, two columns", false))
41        .with_paragraph(Paragraph::with_text(
42            "This document is landscape A4, with wider left/right margins than top/bottom, and its body text \
43             flows in two columns. Look at the page in Word's Layout view to see the effect.",
44        ))
45        .with_paragraph(heading("Headers and footers", true))
46        .with_paragraph(Paragraph::with_text(
47            "Page 1 (this page) uses the first-page header, since \"different first page\" headers are set. \
48             Every other page uses the default header shown above, and every page uses the default footer.",
49        ))
50        .with_paragraph(heading("A third page, to see the default header again", true))
51        .with_paragraph(Paragraph::with_text(
52            "If Word is configured to show even/odd pages differently, this page alternates between the \
53             default and even-page header depending on whether it lands on an even or odd page number.",
54        ));
55
56    document.save_to_file(&path)?;
57    println!("Wrote {}", path.display());
58    Ok(())
59}
Source

pub fn with_table(self, table: Table) -> HeaderFooter

Appends a table block and returns it for chaining.

Source

pub fn with_structured_document_tag( self, sdt: StructuredDocumentTag, ) -> HeaderFooter

Appends a structured document tag block and returns it for chaining.

Source

pub fn paragraphs(&self) -> impl Iterator<Item = &Paragraph>

Iterates over this header/footer’s paragraphs only, skipping tables.

Source

pub fn tables(&self) -> impl Iterator<Item = &Table>

Iterates over this header/footer’s tables only, skipping paragraphs.

Trait Implementations§

Source§

impl Clone for HeaderFooter

Source§

fn clone(&self) -> HeaderFooter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HeaderFooter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for HeaderFooter

Source§

fn default() -> HeaderFooter

Returns the “default value” for a type. Read more
Source§

impl PartialEq for HeaderFooter

Source§

fn eq(&self, other: &HeaderFooter) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HeaderFooter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.