Skip to main content

PrintSettings

Struct PrintSettings 

Source
pub struct PrintSettings {
Show 13 fields pub print_area: Option<String>, pub repeat_rows: Option<String>, pub repeat_columns: Option<String>, pub fit_to_width: Option<u32>, pub fit_to_height: Option<u32>, pub scale: Option<u32>, pub orientation: Option<PageOrientation>, pub header: Option<String>, pub footer: Option<String>, pub header_first: Option<String>, pub footer_first: Option<String>, pub header_even: Option<String>, pub footer_even: Option<String>,
}
Expand description

A sheet’s print/page-setup settings. PrintSettings::default() (everything None) writes no print-related XML at all.

print_area/repeat_rows/repeat_columns are, despite looking like plain worksheet settings, actually implemented by real Excel as reserved sheet-scoped defined names (_xlnm.Print_Area/ _xlnm.Print_Titles, confirmed via ECMA-376 §18.2.6’s “Print_Area”/“Print_Titles” built-in name table) rather than a <pageSetup> attribute — this crate’s writer synthesizes those DefinedName entries automatically from each sheet’s Sheet.print_settings when writing xl/workbook.xml’s <definedNames> (see writer.rs::synthesized_print_defined_names), the caller never constructs them directly.

Fields§

§print_area: Option<String>

The print area (e.g. "$A$1:$F$30") — implemented via _xlnm.Print_Area.

§repeat_rows: Option<String>

Rows to repeat on every printed page (e.g. "$1:$2") — implemented via _xlnm.Print_Titles.

§repeat_columns: Option<String>

Columns to repeat on every printed page (e.g. "$A:$B") — implemented via _xlnm.Print_Titles (combined with repeat_rows into a single name’s refers_to when both are set, exactly like real Excel’s own “Rows to repeat at top” + “Columns to repeat at left” combined into one Print_Titles name).

§fit_to_width: Option<u32>

Scales the printout to fit within this many pages wide. Setting either this or fit_to_height switches on Excel’s “Fit to” print scaling mode (<sheetPr><pageSetUpPr fitToPage="1"/></sheetPr>); leaving the other None means “as many pages as needed” in that dimension, matching Excel’s own “Fit to: N page(s) wide by (blank) tall” UI behavior (written as fitToWidth="0"/fitToHeight="0", CT_PageSetup’s own convention for “unconstrained”).

§fit_to_height: Option<u32>

Scales the printout to fit within this many pages tall.

§scale: Option<u32>

Scales the printout by this percentage (<pageSetup scale="..">, e.g. 90 for 90%). Distinct from fit_to_width/fit_to_height: real Excel’s “Page Setup” dialog offers either “Adjust to: N%” (scale) or “Fit to: W x H page(s)” (fit_to_width/fit_to_height) as two mutually exclusive radio-button modes (<sheetPr><pageSetUpPr fitToPage> selects which of the two <pageSetup> honors) — setting both here is the caller’s own responsibility to avoid, not validated.

§orientation: Option<PageOrientation>

Page orientation. None uses Excel’s own default (portrait).

§header: Option<String>

The page header text (<oddHeader>), written verbatim — Excel’s own &L/&C/&R section codes and &P/&N/&D/. field codes are the caller’s responsibility to include if wanted, same “storage, not a template engine” posture as a formula’s text.

§footer: Option<String>

The page footer text (<oddFooter>), written verbatim.

§header_first: Option<String>

A different header on the first printed page (<firstHeader>), written verbatim. Setting this (or footer_first) switches on <headerFooter differentFirst="1">.

§footer_first: Option<String>

A different footer on the first printed page (<firstFooter>).

§header_even: Option<String>

A different header on even printed pages (<evenHeader>). Setting this (or footer_even) switches on <headerFooter differentOddEven="1">; the existing header/footer fields become the odd-page header/footer once this is set, same as real Excel’s own <oddHeader>/<oddFooter> meaning “odd, or every page if differentOddEven isn’t set”.

§footer_even: Option<String>

A different footer on even printed pages (<evenFooter>).

Implementations§

Source§

impl PrintSettings

Source

pub fn new() -> PrintSettings

Creates print settings with every field unset (equivalent to PrintSettings::default(), only useful as a starting point for the with_* builders).

Examples found in repository?
examples/xlsx_print_and_views.rs (line 21)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_print_area(self, area: impl Into<String>) -> PrintSettings

Sets the print area and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 22)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_repeat_rows(self, rows: impl Into<String>) -> PrintSettings

Sets the rows to repeat on every printed page and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 23)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_repeat_columns(self, columns: impl Into<String>) -> PrintSettings

Sets the columns to repeat on every printed page and returns the settings for chaining.

Source

pub fn with_fit_to_width(self, pages: u32) -> PrintSettings

Sets the fit-to-width page count and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 24)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_fit_to_height(self, pages: u32) -> PrintSettings

Sets the fit-to-height page count and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 25)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_scale(self, percent: u32) -> PrintSettings

Sets the print scale percentage and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 26)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_orientation(self, orientation: PageOrientation) -> PrintSettings

Sets the page orientation and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 27)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_header(self, header: impl Into<String>) -> PrintSettings

Sets the page header text and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 28)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}

Sets the page footer text and returns the settings for chaining.

Examples found in repository?
examples/xlsx_print_and_views.rs (line 29)
14fn main() -> office_toolkit::Result<()> {
15    let path = output_path("xlsx_print_and_views.xlsx");
16
17    let print_setup_sheet = Sheet::new("Print setup")
18        .with_row(Row::new().with_text("Header").with_text("Header"))
19        .with_row(Row::new().with_text("Data").with_number(1.0))
20        .with_print_settings(
21            PrintSettings::new()
22                .with_print_area("A1:B2")
23                .with_repeat_rows("1:1")
24                .with_fit_to_width(1)
25                .with_fit_to_height(0)
26                .with_scale(100)
27                .with_orientation(PageOrientation::Landscape)
28                .with_header("&CCompany Report")
29                .with_footer("&LPage &P of &N"),
30        );
31
32    let view_options_sheet = Sheet::new("View options")
33        .with_row(Row::new().with_text("Zoomed, colored tab, no gridlines"))
34        .with_zoom_scale(150)
35        .with_tab_color("FFC00000")
36        .with_show_grid_lines(false)
37        .with_show_row_col_headers(false)
38        .with_show_zeros(false)
39        .with_right_to_left(false)
40        .with_active_cell("A1")
41        .with_default_column_width(12.0)
42        .with_default_row_height(18.0);
43
44    let hidden_sheet = Sheet::new("Hidden sheet")
45        .with_row(Row::new().with_text("Not shown in the tab bar unless unhidden."))
46        .with_visibility(SheetVisibility::Hidden);
47
48    let workbook = Workbook::new()
49        .with_sheet(print_setup_sheet)
50        .with_sheet(view_options_sheet)
51        .with_sheet(hidden_sheet);
52
53    workbook.save_to_file(&path)?;
54    println!("Wrote {}", path.display());
55    Ok(())
56}
Source

pub fn with_header_first(self, header: impl Into<String>) -> PrintSettings

Sets the first page’s header text and returns the settings for chaining.

Sets the first page’s footer text and returns the settings for chaining.

Source

pub fn with_header_even(self, header: impl Into<String>) -> PrintSettings

Sets the even pages’ header text and returns the settings for chaining.

Sets the even pages’ footer text and returns the settings for chaining.

Trait Implementations§

Source§

impl Clone for PrintSettings

Source§

fn clone(&self) -> PrintSettings

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 PrintSettings

Source§

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

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

impl Default for PrintSettings

Source§

fn default() -> PrintSettings

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

impl PartialEq for PrintSettings

Source§

fn eq(&self, other: &PrintSettings) -> 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 PrintSettings

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.