Page Setup
The sections below look at the sections of the Excel Page Setup dialog and the equivalent rust_xlsxwriter methods.
For more, general, information about the page setup options in Excel see the Microsoft documentation on Page Setup.
Page Setup - Page
The page Setup "Page" dialog looks like this:
The equivalent rust_xlsxwriter methods are:
Worksheet::set_portrait()
Worksheet::set_landscape()
Worksheet::set_print_scale()
Worksheet::set_print_fit_to_pages()
Worksheet::set_print_first_page_number()
Note, for Worksheet::set_print_fit_to_pages()
a common requirement is to fit
the printed output to n
pages wide but have the height be as long as
necessary. To achieve this set the height
to 0:
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright 2022-2024, John McNamara, jmcnamara@cpan.org
//! The following example demonstrates setting the scale of the worksheet to fit
//! a defined number of pages vertically and horizontally. This example shows a
//! common use case which is to fit the printed output to 1 page wide but have
//! the height be as long as necessary.
use rust_xlsxwriter::{Workbook, XlsxError};
fn main() -> Result<(), XlsxError> {
let mut workbook = Workbook::new();
// Add a worksheet to the workbook.
let worksheet = workbook.add_worksheet();
// Set the printed output to fit 1 page wide and as long as necessary.
worksheet.set_print_fit_to_pages(1, 0);
workbook.save("worksheet.xlsx")?;
Ok(())
}
Page Setup - Margins
The page Setup "Margins" dialog looks like this:
The equivalent rust_xlsxwriter methods are:
Worksheet::set_margins()
Worksheet::set_print_center_horizontally()
Worksheet::set_print_center_vertically()
Page Setup - Header/Footer
The page Setup "Header/Footer" dialog looks like this:
The equivalent rust_xlsxwriter methods are:
Worksheet::set_header()
Worksheet::set_footer()
Worksheet::set_header_footer_scale_with_doc()
Worksheet::set_header_footer_align_with_page()
Headers and footers are explained in more detail in the next section on Adding Headers and Footers.
Note, the options for different first, odd and even pages are not supported in rust_xlsxwriter.
Page Setup - Sheet
The page Setup "Sheet" dialog looks like this:
The equivalent rust_xlsxwriter methods are: