How to Print Excel as Fitted Pages Wide and Tall with Python.NET

Introduction

The fit_to_pages_wide and fit_to_pages_tall settings control spreadsheet scaling during printing. These settings ensure printed output fits within specified page dimensions:

  1. fit_to_pages_wide: Specifies horizontal page count for printing
  2. fit_to_pages_tall: Specifies vertical page count for printing

Why Use FitToPagesWide and FitToPagesTall

Key benefits include:

  1. Precise print layout control
  2. Consistent multi-sheet formatting
  3. Professional document presentation

How to Print File as Fitted Pages Wide and Tall in Excel

To configure in Microsoft Excel:

  1. Open workbook and select worksheet
  2. Navigate to Page LayoutPage Setup dialog
  3. In Page tab under Scaling:
    • Select “Fit to”
    • Specify pages wide (horizontal) and tall (vertical)

How to Print Excel as Fitted Pages Wide and Tall Using Aspose.Cells

To configure programmatically:

  1. Load sample file
  2. Access worksheet’s page_setup object
  3. Set fit_to_pages_tall and fit_to_pages_wide properties
from aspose.cells import Workbook

# Instantiating a Workbook object
workbook = Workbook("input.xlsx")

# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]

# Setting the number of pages to which the length of the worksheet will be spanned
worksheet.page_setup.fit_to_pages_tall = 1

# Setting the number of pages to which the width of the worksheet will be spanned
worksheet.page_setup.fit_to_pages_wide = 1

# Save the workbook
workbook.save("out_net.pdf")

Output result:

How to Print Worksheet as One Page

To force single-page output:

  1. Use PdfSaveOptions
  2. Set one_page_per_sheet property
from aspose.cells import Workbook, PdfSaveOptions

# Instantiating a Workbook object
workbook = Workbook("sample.xlsx")

options = PdfSaveOptions()

# Setting OnePagePerSheet option
options.one_page_per_sheet = True

# Save the workbook with options
workbook.save("OnePagePerSheet.pdf", options)

Output result:

How to Print All Columns in One Page

To consolidate columns horizontally:

  1. Configure PdfSaveOptions
  2. Enable all_columns_in_one_page_per_sheet property
from aspose.cells import Workbook, PdfSaveOptions

# Instantiating a Workbook object
workbook = Workbook("sample.xlsx")

options = PdfSaveOptions()

# Setting all columns in one page per sheet
options.all_columns_in_one_page_per_sheet = True

# Save the workbook
workbook.save("AllColumnsInOnePagePerSheet.pdf", options)

Output result: