Excel Print Setup
The Excel Print Setup feature in IronXL allows developers to easily configure print settings for Excel worksheets before printing or saving them. This feature is particularly useful when generating reports, invoices, or documents that need specific formatting for printing. Developers can set custom headers and footers to include dynamic content like page numbers, titles, and other details, ensuring a professional output. The PrintSetup options also allow fine-tuning of print margins, paper size, and orientation, making it possible to adapt the document for various printers and paper types.
IronXL gives developers full control over how the printed document will appear with the ability to specify paper sizes such as B4, A4, or letter sizes, as well as orientation options (portrait or landscape). Additionally, the ability to switch to black-and-white printing or disable color adds flexibility, especially for cost-effective printing scenarios. This feature streamlines the process of preparing Excel files for high-quality printed output.
How to use Excel NumberFormat
in C#
var workBook = WorkBook.Load("sample.xlsx");
var workSheet = workBook.DefaultWorkSheet
workSheet.Header.Center = "My Document"
workSheet.PrintSetup.PaperSize = PaperSize.B4
workSheet.PrintSetup.PrintOrientation = PrintOrientation.Portrait;
workBook.Save();
This code demonstrates how to load an Excel file, modify the print settings, and then save the workbook with those changes. It begins by loading the "sample.xlsx" file into a WorkBook
object using the WorkBook.Load
method. The default worksheet is accessed via the DefaultWorkSheet
property, which allows the script to modify its content and settings. Specifically, the code sets the header of the worksheet to display "My Document" in the center using the Header.Center
property.
The second part of the code focuses on configuring the print setup. The paper size is set to B4 using the PrintSetup.PaperSize
property, while the print orientation is set to portrait mode through the PrintSetup.PrintOrientation
property. Finally, the workbook is saved using the workBook.Save()
method, applying all the changes made, including the updated print settings. This process is useful for automating the preparation of Excel documents with customized print formats, ensuring consistent printing output.