Shapes, Pictures, Charts

A worksheet may contain embedded drawing objects - shapes, pictures and charts. An image in a worksheet is a Picture object, and an embedded chart is a Chart object. Both these interfaces are inherited from the base Shape interface. Other shape types (ShapeType.Shape, ShapeType.Connector and ShapeType.Group) cannot be currently accessed in code.

Note

Not all methods and properties of the base Shape interface are in effect for pictures and charts.

Accessing Drawing Objects

Drawing objects are contained in the ShapeCollection collection. The collection is accessible using the Worksheet.Shapes property and contains all pictures and charts in a worksheet. The Worksheet.Pictures property gets a collection of all pictures, and the Worksheet.Charts property gets a collection of all charts in a worksheet.

Use the Shape.Rotation property to set the angle to which a drawing object is rotated, and use the Shape.IncrementRotation method to rotate the drawing object by a specified number of degrees.

An end-user can resize or rotate a drawing object with special handles, which are visible for a selected object.

Placement

A drawing object may respond when cells underneath it are moved or resized. This behavior is determined by the FloatingObject.Placement property. A drawing object can be moved and resized with cells, or it can float freely.

When a picture is added to a worksheet, its initial placement depends on the specific overload of the PictureCollection.AddPicture method. If a Cell is passed to the method, the picture will move with cells. If a Range is passed to the method, the picture will move and size with cells. If coordinates are specified when an image is inserted in a worksheet, it will float freely.

To move a drawing object in front of or behind other drawing objects in a worksheet, specify its Shape.ZOrderPosition property relative to other drawing object. When drawing objects are added to the Worksheet.Shapes collection, the ZOrderPosition gets its value incremented by one starting from 1. You can increase the ZOrderPosition property value to move the drawing object in front of all objects with lower ZOrderPosition. The ShapeCollection.NormalizeZOrder method modifies ZOrderPosition values for all drawing objects in a collection, so that they become a series of consecutive integers starting from 1.

Hyperlink

A hyperlink can be associated with a drawing object. When the end-user clicks the drawing object, the link navigates to a certain location on the Internet, to a file, to a place in a workbook, or it sends an email. Use the Shape.InsertHyperlink method to create a hyperlink for a drawing object. Use the Shape.RemoveHyperlink method to delete a hyperlink.