officefileapi-120684-spreadsheet-document-api-examples-shapes-how-to-create-a-shape.md
This topic describes how to create a shape and change its form, size, and rotation angle.
The example below shows how to use the ShapeCollection.AddShape method overloads to insert shapes into a worksheet.
// Set the measurement unit to Inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;
// Insert a shape at the specified position in a worksheet.
Shape shape1 = worksheet.Shapes.AddShape(ShapeGeometryPreset.RectangularCallout, 0.68f, 0.22f, 2f, 1.25f);
// Insert a shape so that its top left corner is in the specified cell.
Shape shape2 = worksheet.Shapes.AddShape(ShapeGeometryPreset.RoundedRectangularCallout, worksheet.Cells["F2"], 2f, 1.25f);
// Insert a shape that fits into the specified cell range.
Shape shape3 = worksheet.Shapes.AddShape(ShapeGeometryPreset.OvalCallout, worksheet["J2:L7"]);
' Set the measurement unit to Inches.
workbook.Unit = DevExpress.Office.DocumentUnit.Inch
' Insert a shape at the specified position in a worksheet.
Dim shape1 As Shape = worksheet.Shapes.AddShape(ShapeGeometryPreset.RectangularCallout, 0.68F, 0.22F, 2F, 1.25F)
' Insert a shape so that its top left corner is in the specified cell.
Dim shape2 As Shape = worksheet.Shapes.AddShape(ShapeGeometryPreset.RoundedRectangularCallout, worksheet.Cells("F2"), 2F, 1.25F)
' Insert a shape that fits into the specified cell range.
Dim shape3 As Shape = worksheet.Shapes.AddShape(ShapeGeometryPreset.OvalCallout, worksheet("J2:L7"))
Use the following API to define a shape’s location in a worksheet:
| Member | Description |
|---|---|
| FloatingObject.Move | Moves the shape by the specified offsets. |
| FloatingObject.Top | Specifies the distance between the top edge of the worksheet and the shape’s top left corner. |
| FloatingObject.Left | Specifies the distance between the left edge of the worksheet and the shape’s top left corner. |
| FloatingObject.TopLeftCell | Specifies the cell where the shape’s top left corner is located. |
| FloatingObject.BottomRightCell | Specifies the cell where the shape’s bottom right corner is located. |
| FloatingObject.OffsetX | Specifies the distance between the shape’s top left corner and the left edge of the TopLeftCell cell. |
| FloatingObject.OffsetY | Specifies the distance between the shape’s top left corner and the top edge of the TopLeftCell cell. |
shape2.TopLeftCell = worksheet.Cells["F4"];
shape2.BottomRightCell = worksheet.Cells["H9"];
shape2.TopLeftCell = worksheet.Cells("F4")
shape2.BottomRightCell = worksheet.Cells("H9")
Use the following properties to rotate and resize a shape:
| Property | Description |
|---|---|
| Shape.Rotation | Specifies the shape’s rotation angle. |
| FloatingObject.Width | Specifies the shape’s width. |
| FloatingObject.Height | Specifies the shape’s height. |
shape3.Rotation = 45;
shape3.Width = 2.2f;
shape3.Height = 1.5f;
shape3.Rotation = 45
shape3.Width = 2.2F
shape3.Height = 1.5F
Use the ShapeGeometry.Preset property to change a shape’s geometry type. The example below shows how to transform a rectangular callout into a cloud callout.
shape1.ShapeGeometry.Preset = ShapeGeometryPreset.CloudCallout;
shape1.ShapeGeometry.Preset = ShapeGeometryPreset.CloudCallout
See Also
How to: Change Shape's Fill and Outline Color