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.
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">.
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”.
A different footer on even printed pages (<evenFooter>).
Implementations§
Source§impl PrintSettings
impl PrintSettings
Sourcepub fn new() -> PrintSettings
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?
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}Sourcepub fn with_print_area(self, area: impl Into<String>) -> PrintSettings
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?
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}Sourcepub fn with_repeat_rows(self, rows: impl Into<String>) -> PrintSettings
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?
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}Sourcepub fn with_repeat_columns(self, columns: impl Into<String>) -> PrintSettings
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.
Sourcepub fn with_fit_to_width(self, pages: u32) -> PrintSettings
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?
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}Sourcepub fn with_fit_to_height(self, pages: u32) -> PrintSettings
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?
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}Sourcepub fn with_scale(self, percent: u32) -> PrintSettings
pub fn with_scale(self, percent: u32) -> PrintSettings
Sets the print scale percentage and returns the settings for chaining.
Examples found in repository?
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}Sourcepub fn with_orientation(self, orientation: PageOrientation) -> PrintSettings
pub fn with_orientation(self, orientation: PageOrientation) -> PrintSettings
Sets the page orientation and returns the settings for chaining.
Examples found in repository?
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}Sourcepub fn with_header(self, header: impl Into<String>) -> PrintSettings
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?
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?
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}Sourcepub fn with_header_first(self, header: impl Into<String>) -> PrintSettings
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.
Sourcepub fn with_header_even(self, header: impl Into<String>) -> PrintSettings
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
impl Clone for PrintSettings
Source§fn clone(&self) -> PrintSettings
fn clone(&self) -> PrintSettings
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more