Excel Print Setup
from ironxl import *

# Load the Excel workbook
workbook = WorkBook.Load("sample.xlsx")
worksheet = workbook.DefaultWorkSheet

# Set the print header and footer of the worksheet
worksheet.Header.Center = "My document"
worksheet.Footer.Center = "Page &P of &N"

# Set the header margin
worksheet.PrintSetup.HeaderMargin = 2.33

# Set the size of the paper
# Paper size enum represents different sizes of paper
worksheet.PrintSetup.PaperSize = PaperSize.B4

# Set the print orientation of the worksheet
worksheet.PrintSetup.PrintOrientation = PrintOrientation.Portrait

# Set black and white printing
worksheet.PrintSetup.NoColor = True

workbook.SaveAs("PrintSetup.xlsx")
pip install ironxl
Excel Print Setup

Excel Print Setup

The Excel Print Setup feature in IronXL allows Python developers to configure print settings for Excel worksheets before printing or saving them as PDFs. This is particularly useful when generating reports, invoices, or documents that require specific formatting for print output. Developers can set custom headers and footers with dynamic content such as page numbers and titles, ensuring a professional result. The PrintSetup options also allow fine-tuning of margins, paper size, and orientation, making it possible to adapt the document for various printers and paper types.

IronXL provides full control over the printed layout, including paper sizes such as B4, A4, and letter, as well as portrait and landscape orientation. The option to enable black-and-white printing adds flexibility for cost-effective printing scenarios. This feature streamlines the process of preparing Excel files for high-quality printed output directly from Python.

Learn More About Managing Excel Worksheets in Python

Ready to Get Started?

Version:2026.11just released