IXlPicture.FitToCell(XlCellPosition, Int32, Int32, Boolean) Method
Fits an IXlPicture object in the specified cell.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.2.Core.dll
Declaration
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/excel-export-api-examples
// Insert a picture from a file into the "B2" cell.
using (IXlPicture picture = sheet.CreatePicture())
{
picture.SetImage(Image.FromFile(Path.Combine(imagesPath, "image1.jpg")), ImageFormat.Jpeg);
picture.FitToCell(new XlCellPosition(1, 1), 300, 154, true);
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FitToCell(XlCellPosition, Int32, Int32, Boolean) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.