Back to Devexpress

How to: Set Page Margins

officefileapi-12403-spreadsheet-document-api-examples-worksheets-how-to-set-page-margins.md

latest2.5 KB
Original Source

How to: Set Page Margins

  • Sep 19, 2023
  • 2 minutes to read

Important

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these examples in production code.

This example demonstrates how to set margins of worksheet pages via properties of the Margins object. Use the Worksheet.ActiveView.Margins property to return this object. To select units of measure for worksheet page margins, set the Workbook.Unit property to the required DocumentUnit enumeration member.

Note

The WorksheetView.Margins settings are used when worksheet pages are printed. To learn how to specify other worksheet print options, see the How to: Specify Print Settings document.

View Example

csharp
// Select a unit of measure used within the workbook.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;

// Access page margins.
Margins pageMargins = workbook.Worksheets[0].ActiveView.Margins;

// Specify page margins.
pageMargins.Left = 1;
pageMargins.Top = 1.5F;
pageMargins.Right = 1;
pageMargins.Bottom = 0.8F;

// Specify header and footer margins.
pageMargins.Header = 1;
pageMargins.Footer = 0.4F;
vb
' Select a unit of measure used within the workbook.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch

' Access page margins.
Dim pageMargins As Margins = workbook.Worksheets(0).ActiveView.Margins

' Specify page margins.
pageMargins.Left = 1
pageMargins.Top = 1.5F
pageMargins.Right = 1
pageMargins.Bottom = 0.8F

' Specify header and footer margins.
pageMargins.Header = 1
pageMargins.Footer = 0.4F

See Also

How to: Set Page Orientation

How to: Set Paper Size