IXlPicture.SetTwoCellAnchor(XlAnchorPoint, XlAnchorPoint, XlAnchorType) Method
Anchors an IXlPicture object to two cells in a worksheet.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v19.1.Core.dll
Declaration
void SetTwoCellAnchor(
XlAnchorPoint topLeft,
XlAnchorPoint bottomRight,
XlAnchorType behavior
)
Parameters
Name | Type | Description |
---|---|---|
topLeft | XlAnchorPoint | An XlAnchorPoint object that specifies the anchor cell for the top-left corner of the picture and optional offsets from the top and left edges of this cell. This value is assigned to the IXlPicture.TopLeft property. |
bottomRight | XlAnchorPoint | An XlAnchorPoint object that specifies the anchor cell for the bottom-right corner of the picture and optional offsets from the top and left edges of this cell. This value is assigned to the IXlPicture.BottomRight property. |
behavior | XlAnchorType | An XlAnchorType enumeration value that specifies the positioning and resizing behavior of the picture. This value is assigned to the IXlPicture.AnchorBehavior property. |
Remarks
Use the SetTwoCellAnchor method to the specify start and end positions for a picture in a worksheet. The starting and ending anchors are defined by the XlAnchorPoint objects. These objects specify columns and rows containing anchor cells for the top-left and bottom-right corners of the picture and enable you to define possible offsets within these cells to adjust the picture placement. The behavior parameter of the SetTwoCellAnchor method allows you to specify how the picture should be moved and/or resized when the rows and columns between its starting and ending anchors are resized, or when additional rows and columns are added.
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
The example below demonstrates how to use the IXlPicture.SetTwoCellAnchor
method to anchor a picture to two cells in a worksheet. The starting anchor for a picture is located at the intersection of the second column (“B”) and the second row, with no offsets. The final anchor is located at the intersection of the seventh column (“G”) and the twelfth row, with offsets from both the column and row. The IXlPicture.AnchorBehavior is set to XlAnchorType.TwoCell, so that the picture moves and resizes with its underlying cells.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/xl-export-api-examples-t253492
// Create a worksheet.
using (IXlSheet sheet = document.CreateSheet())
{
// Insert a picture from a file and anchor it to cells.
using (IXlPicture picture = sheet.CreatePicture())
{
picture.Image = Image.FromFile(Path.Combine(imagesPath, "image1.jpg"));
picture.SetTwoCellAnchor(new XlAnchorPoint(1, 1, 0, 0), new XlAnchorPoint(6, 11, 2, 15), XlAnchorType.TwoCell);
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetTwoCellAnchor(XlAnchorPoint, XlAnchorPoint, XlAnchorType) 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.