Back to Devexpress

How to: Specify Print Settings

officefileapi-12398-spreadsheet-document-api-examples-printing-how-to-specify-print-settings.md

latest5.3 KB
Original Source

How to: Specify Print Settings

  • Sep 19, 2023
  • 2 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 component. 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
// Set page orientation to landscape.
worksheet.ActiveView.Orientation = PageOrientation.Landscape;
// 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 one page.
printOptions.FitToPage = true;
printOptions.FitToWidth = 1;
// Print in black and white.
printOptions.BlackAndWhite = true;
// Print a dash instead of a cell error message.
printOptions.ErrorsPrintMode = ErrorsPrintMode.Dash;
vb
' Set page orientation to landscape.
worksheet.ActiveView.Orientation = PageOrientation.Landscape
' 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 one page.
printOptions.FitToPage = True
printOptions.FitToWidth = 1
' Print in black and white.
printOptions.BlackAndWhite = True
' Print a dash instead of a cell error message.
printOptions.ErrorsPrintMode = ErrorsPrintMode.Dash