Skip to main content
A newer version of this page is available. .

IXlPicture.FitToCell(XlCellPosition, Int32, Int32, Boolean) Method

Fits an IXlPicture object in the specified cell.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v18.2.Core.dll

Declaration

void FitToCell(
    XlCellPosition position,
    int cellWidth,
    int cellHeight,
    bool center
)

Parameters

Name Type Description
position XlCellPosition

An XlCellPosition object that specifies the position of the cell where the picture should be located.

cellWidth Int32

A Int32 value that is the width of the cell into which the picture fits.

cellHeight Int32

A Int32 value that is the height of the cell into which the picture fits.

center Boolean

A Boolean value specifying whether the picture should be center-aligned in the cell.

Remarks

Use the FitToCell method to rescale the image proportionally to fit the specified cell. If you wish your picture to fill the entire space of a cell, use the IXlPicture.StretchToCell method.

For more information on how to add a picture to a worksheet and specify its location, refer to the How to: Insert and Position a Picture in a Worksheet example.

Example

Note

A complete sample project is available at https://github.com/DevExpress-Examples/xl-export-api-examples-t253492

    // Insert a picture from a file to fit in the cell B2.
    using (IXlPicture picture = sheet.CreatePicture())
    {
        picture.Image = Image.FromFile(Path.Combine(imagesPath, "image1.jpg"));
        picture.FitToCell(new XlCellPosition(1, 1), 300, 154, true);
    }
}
See Also