Back to Devexpress

SheetView.SetCustomPaperSize(Single, Single) Method

officefileapi-devexpress-dot-spreadsheet-dot-sheetview-dot-setcustompapersize-x28-system-dot-single-system-dot-single-x29.md

latest4.0 KB
Original Source

SheetView.SetCustomPaperSize(Single, Single) Method

Specifies custom paper size for a worksheet or chart sheet.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void SetCustomPaperSize(
    float width,
    float height
)
vb
Sub SetCustomPaperSize(
    width As Single,
    height As Single
)

Parameters

NameTypeDescription
widthSingle

The paper width in measurement units defined by the Unit property.

| | height | Single |

The paper height in measurement units defined by the Unit property.

|

Exceptions

TypeDescription
ArgumentException

Occurs if the paper width or height is less than or equal to 0.

|

Remarks

When you call the SetCustomPaperSize method to define paper size, the PaperKind property value changes to Custom. Custom paper dimensions are saved to a file only if 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®.

If PaperKind is Custom for a loaded workbook, but the document does not contain custom paper dimensions, the Spreadsheet attempts to retrieve paper size from the printerSettings binary files stored in the workbook. If printer settings are not found, the Spreadsheet uses the Letter paper size (8.5 inches by 11 inches) to print the document or export it to PDF.

Define Custom Paper Size

The following example specifies custom paper size for the first worksheet in the document:

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

// 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);
vb
Imports DevExpress.Office
Imports DevExpress.Spreadsheet
' ...

' 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)

Reset Custom Paper Size

Assign a PaperKind enumeration member to the SheetView.PaperKind property to use one of the standard paper sizes (Letter, Legal, Tabloid, and so on) to print a worksheet or chart sheet.

csharp
// Use standard paper size.
workbook.Worksheets[0].ActiveView.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.Letter;
vb
' Use standard paper size.
workbook.Worksheets(0).ActiveView.PaperKind = DevExpress.Drawing.Printing.DXPaperKind.Letter

See Also

SheetView Interface

SheetView Members

DevExpress.Spreadsheet Namespace