Back to Devexpress

How to: Specify Print Settings

wpf-16402-controls-and-libraries-spreadsheet-examples-printing-how-to-specify-print-settings.md

latest5.8 KB
Original Source

How to: Specify Print Settings

  • Oct 08, 2021
  • 3 minutes to read

Use the Worksheet.ActiveView property to specify the following page options:

PropertyDescription
WorksheetView.MarginsDefines page margins.
WorksheetView.OrientationSpecifies page orientation.
WorksheetView.PaperKindSpecifies paper size.
WorksheetView.SetCustomPaperSizeSpecifies custom paper size for a worksheet.

Use the Worksheet.PrintOptions property to configure print options. Print options include the following:

PropertyDescription
WorksheetPrintOptions.FitToPageIndicates whether to scale a worksheet to fit its data within a specified number of pages.
WorksheetPrintOptions.FitToWidthSpecifies the number of pages a worksheet should fit within horizontally.
WorksheetPrintOptions.FitToHeightSpecifies the number of pages a worksheet should fit within vertically.
WorksheetPrintOptions.ScaleSpecifies the percentage by which to scale the worksheet content.
WorksheetPrintOptions.PrintGridlinesSpecifies whether to print worksheet gridlines.
WorksheetPrintOptions.PrintHeadingsSpecifies whether to print row and column headings.
WorksheetPrintOptions.PrintTitlesAllows you to repeat specific rows and columns on the printed pages.
WorksheetPrintOptions.BlackAndWhiteAllows you to print a worksheet in black and white.
WorksheetPrintOptions.PageOrderSpecifies the order of printed pages.
WorksheetPrintOptions.PageNumberingAllows you to specify the first page number.
WorksheetPrintOptions.CenterHorizontallySpecifies whether to center data horizontally on the printed page.
WorksheetPrintOptions.CenterVerticallySpecifies whether to center data vertically on the printed page.
WorksheetPrintOptions.ErrorsPrintModeSpecifies how to print cell errors.

Important

The WorksheetPrintOptions.Draft, WorksheetPrintOptions.NumberOfCopies and WorksheetPrintOptions.CommentsPrintMode options are not supported when you print a workbook from the Spreadsheet control. The Spreadsheet saves these property values to a document, so that you can print the document in Microsoft® Excel® or another spreadsheet application.

View Example

csharp
worksheet.ActiveView.Orientation = PageOrientation.Landscape;
// Display row and column headings.
worksheet.ActiveView.ShowHeadings = true;
// Select paper size.
worksheet.ActiveView.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.A4;
// Access an object that contains print options.
WorksheetPrintOptions printOptions = worksheet.PrintOptions;
// Do not print gridlines.
printOptions.PrintGridlines = false;
// Scale the worksheet to fit within the width of two pages.
printOptions.FitToPage = true;
printOptions.FitToWidth = 2;
// Print in black and white.
printOptions.BlackAndWhite = true;
// Print a dash instead of a cell error message.
printOptions.ErrorsPrintMode = ErrorsPrintMode.Dash;
vb
worksheet.ActiveView.Orientation = PageOrientation.Landscape
' Display row and column headings.
worksheet.ActiveView.ShowHeadings = True
' Select paper size.
worksheet.ActiveView.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.A4
' Access an object that contains print options.
Dim printOptions As WorksheetPrintOptions = worksheet.PrintOptions
' Do not print gridlines.
printOptions.PrintGridlines = False
' Scale the worksheet to fit within the width of two pages.
printOptions.FitToPage = True
printOptions.FitToWidth = 2
' Print in black and white.
printOptions.BlackAndWhite = True
' Print a dash instead of a cell error message.
printOptions.ErrorsPrintMode = ErrorsPrintMode.Dash

See Also

How to: Print a Workbook

How to: Add Headers and Footers to a Worksheet Printout

How to: Print Titles on a Worksheet