[]
Adds a new preset shape to the worksheet and returns the created IShape object.
The shape is created at the specified position and size, measured in points relative to the upper-left corner of the document.
IShape AddShape(AutoShapeType type, double left, double top, double width, double height)
Function AddShape(type As AutoShapeType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| AutoShapeType | type | Specifies the type of preset shape to create. |
| double | left | The position, in points, of the upper-left corner of the preset shape's boundary box relative to the upper-left corner of the document. |
| double | top | The position, in points, of the upper-left corner of the preset shape's boundary box relative to the upper-left corner of the document. |
| double | width | The width of the preset shape's boundary box, in points. |
| double | height | The height of the preset shape's boundary box, in points. |
| Type | Description |
|---|---|
| IShape | The created IShape object. |
IShape shape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, 20, 20, 120, 80);
shape.Name = "SalesBox";
shape.TextFrame.TextRange.Text = "Sales";
Returns the IShape object that represents the new preset shape at the specified range on the current sheet.
The sheet of targetRange and the sheet of the shape being added must be the same sheet.
IShape AddShape(AutoShapeType type, IRange targetRange)
Function AddShape(type As AutoShapeType, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| AutoShapeType | type | Specifies the type of preset shape to create. |
| IRange | targetRange | The target range on the current sheet. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new preset shape. |
IRange targetRange = worksheet.Range["B2:D5"];
IShape shape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, targetRange);
shape.TextFrame.TextRange.Text = "Sales";
Returns the IShape object that represents the new preset shape in a worksheet.
Creates a preset shape with the specified name, type, position, and size. The shape name can be used to retrieve the created shape from the worksheet's shape collection.
IShape AddShape(string name, AutoShapeType type, double left, double top, double width, double height)
Function AddShape(name As String, type As AutoShapeType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The shape name. |
| AutoShapeType | type | Specifies the type of preset shape to create. |
| double | left | The position (in points) of the upper-left corner of the preset shape's boundary box relative to the upper-left corner of the document. |
| double | top | The position (in points) of the upper-left corner of the preset shape's boundary box relative to the upper-left corner of the document. |
| double | width | The width of the preset shape's boundary box, in points. |
| double | height | The height of the preset shape's boundary box, in points. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new preset shape. |
IShape shape = worksheet.Shapes.AddShape("ProcessBox", AutoShapeType.Rectangle, 50, 40, 120, 60);
shape.TextFrame.TextRange.Text = "Review";
worksheet.Shapes["ProcessBox"].Fill.Color.RGB = Color.Blue;
Returns the IShape object that represents the new preset shape at the specified range on the current sheet.
The sheet of targetRange and the sheet to which the shape is being added must be the same sheet.
IShape AddShape(string name, AutoShapeType type, IRange targetRange)
Function AddShape(name As String, type As AutoShapeType, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The shape name. |
| AutoShapeType | type | Specifies the type of preset shape to create. |
| IRange | targetRange | The target range on the current sheet. Must belong to the same worksheet as the shape collection. null is not supported. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new preset shape. |
IRange targetRange = worksheet.Range["B2:D4"];
IShape shape = worksheet.Shapes.AddShape("ProcessBox", AutoShapeType.Rectangle, targetRange);
shape.TextFrame.TextRange.Text = "Review";