This topic page explains how you can configure the page settings to control the appearance of the printed page.
You can adjust the page margins to fit the worksheet contents on the page to be printed. Use the TopMargin, BottomMargin, LeftMargin, RightMargin, HeaderMargin, and FooterMargin properties of the IPageSetup interface to configure margins for a page.
You can also center the worksheet horizontally or vertically on the page when it's printed using the CenterHorizontally and CenterVertically properties.
The following example code sets the top and left margins of the page.
You can change the page orientation to landscape or portrait to orient it horizontally or vertically. By default, page orientation is portrait. Use the Orientation property of the IPageSetup interface to set the orientation for the page to Portrait or Landscape, as per your preferences.
The following example code sets the orientation for pages.
You can change the order in which worksheet pages are printed. Use the Order property of the IPageSetup interface to set the page order to DownThenOver or OverThenDown.
The following example code shows how to set the print order to OverThenDown.
You can use page breaks in a worksheet to break the data into separate pages for printing. It helps to print the data with the exact number that you want. Page breaks control where a page ends and where a new page starts. You can use the PageBreak property of the IRange interface to apply page breaks on rows and columns in a worksheet.
The below code applies a verticle break in a worksheet.
You can scale the worksheet content to fit the page width by either shrinking or enlarging the content. Use the FitToPages, FitToPagesTall, and FitToPagesWide properties of the IPageSetUp interface to set the size of the paper that will be used for printing.
The following example code sets the page scaling.
Additionally, you can also adjust the zoom percentage of the worksheet for printing by using the Zoom property of the IPageSetUp interface.
The following example code sets the zoom percentage for the page.
You can change the size of the printed paper by using the PaperSize property of IPageSetUp interface.
The following example code sets the paper size.