How to: Set Page Margins
- 2 min to read
You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.
This example demonstrates how to set margins of worksheet pages via properties of the Margins object. To access this object, use the WorksheetView.Margins property of the worksheet view object that is returned by the Worksheet.ActiveView. To select units of measure for worksheet page margins, set the Workbook.Unit property to the required DocumentUnit enumeration member.
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-api-e4339
// Select a unit of measure used within the workbook. workbook.Unit = DevExpress.Office.DocumentUnit.Inch; // Access page margins. Margins pageMargins = workbook.Worksheets.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;