IXlPicture.AnchorBehavior Property

Gets or sets the positioning and resizing behavior of a picture which is anchored to two cells in a worksheet.

Namespace: DevExpress.Export.Xl

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

Declaration

XlAnchorType AnchorBehavior { get; set; }

Property Value

Type Description
XlAnchorType

One of the XlAnchorType enumeration values.

Available values:

Name Description
TwoCell

Two Cell Anchoring. The picture moves and/or resizes with the underlying cells as specified by the IXlPicture.AnchorBehavior property.

OneCell

One Cell Anchoring. The picture moves with the anchor cell, but its size remains the same.

Absolute

Absolute Anchoring. The picture does not move or resize with the underlying cells.

Remarks

Use the AnchorBehavior property to specify how a picture should be moved and resized when a two cell anchoring type is used to position the picture in a worksheet. The XlAnchorType.Absolute value specifies that the picture does not move or resize with the underlying rows and columns, instead the picture’s anchors should be moved to maintain the same absolute position and size. The XlAnchorType.OneCell specifies that the picture should move with the cell to which the top-left corner of the picture is anchored, but its size does not change. And lastly, use the XlAnchorType.TwoCell value to move and resize the picture with its underlying cells.

Call the IXlPicture.SetTwoCellAnchor method to anchor a picture to two cells in a worksheet and specify how the picture should behave when columns and rows underneath are resized and moved.

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.

// 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);
    }
}
See Also