Skip to main content

How to: Set Paper Size

  • 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.

The Spreadsheet Document API allows you to specify paper size for printed worksheets. Assign a PaperKind enumeration member to the Worksheet.ActiveView.PaperKind property to use one of the standard paper sizes (Letter, Legal, Tabloid, and so on).

The following example specifies paper size for the first worksheet:

using DevExpress.Drawing.Printing;
using DevExpress.Spreadsheet;
// ...

using(Workbook workbook = new Workbook())
{
    // Select paper size.
    workbook.Worksheets[0].ActiveView.PaperKind = DXPaperKind.Letter;
}

Customize Paper Size

Call the Worksheet.ActiveView.SetCustomPaperSize method to specify custom size for printed pages. Use the Workbook.Unit property to specify the measurement unit for the paper size (width and height).

The following example specifies a custom paper size for the first worksheet and exports the document to PDF:

using DevExpress.Office;
using DevExpress.Spreadsheet;
// ...

using(Workbook workbook = new Workbook())
{
    workbook.LoadDocument("Document.xlsx", DocumentFormat.Xlsx);

    // Set measurement unit to inches.
    workbook.Unit = DocumentUnit.Inch;

    // Specify custom paper size (10 inches by 12 inches).
    workbook.Worksheets[0].ActiveView.SetCustomPaperSize(10, 12);

    workbook.ExportToPdf("PdfDocument.pdf");
}

The following image demonstrates the result:

PDF Document with Custom Paper Size

Custom paper dimensions are saved to a file only when you export a workbook to Microsoft Office Open XML formats (XLSX, XLSM, XLTX, and XLTM). Custom size values are lost when you open and resave the document in Microsoft® Excel®.

See Also