Class ShapeCollection
Namespace: Aspose.Cells.Drawing
Assembly: Aspose.Cells.dll (25.2.0)
Represents all the shape in a worksheet/chart.
public class ShapeCollection : CollectionBase<shape>, IList<shape>, ICollection<shape>, IEnumerable<shape>, ICollection, IEnumerable
Inheritance
object ← CollectionBase<shape> ← ShapeCollection
Implements
IList<shape>, ICollection<shape>, IEnumerable<shape>, ICollection, IEnumerable
Inherited Members
CollectionBase<shape>.BinarySearch(Shape), CollectionBase<shape>.BinarySearch(Shape, IComparer<shape>), CollectionBase<shape>.BinarySearch(int, int, Shape, IComparer<shape>), CollectionBase<shape>.Contains(Shape), CollectionBase<shape>.CopyTo(Shape[]), CollectionBase<shape>.CopyTo(Shape[], int), CollectionBase<shape>.CopyTo(int, Shape[], int, int), CollectionBase<shape>.Exists(Predicate<shape>), CollectionBase<shape>.Find(Predicate<shape>), CollectionBase<shape>.FindAll(Predicate<shape>), CollectionBase<shape>.FindIndex(Predicate<shape>), CollectionBase<shape>.FindIndex(int, Predicate<shape>), CollectionBase<shape>.FindIndex(int, int, Predicate<shape>), CollectionBase<shape>.FindLast(Predicate<shape>), CollectionBase<shape>.FindLastIndex(Predicate<shape>), CollectionBase<shape>.FindLastIndex(int, Predicate<shape>), CollectionBase<shape>.FindLastIndex(int, int, Predicate<shape>), CollectionBase<shape>.IndexOf(Shape), CollectionBase<shape>.IndexOf(Shape, int), CollectionBase<shape>.IndexOf(Shape, int, int), CollectionBase<shape>.LastIndexOf(Shape), CollectionBase<shape>.LastIndexOf(Shape, int), CollectionBase<shape>.LastIndexOf(Shape, int, int), CollectionBase<shape>.GetEnumerator(), CollectionBase<shape>.Clear(), CollectionBase<shape>.RemoveAt(int), CollectionBase<shape>.OnClearComplete(), CollectionBase<shape>.OnClear(), CollectionBase<shape>.Capacity, CollectionBase<shape>.Count, CollectionBase<shape>.InnerList, CollectionBase<shape>.this[int], object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
csharp
[C#]
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//get ShapeCollection
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
//do your business
//Save the excel file.
workbook.Save("result.xlsx");
Properties
this[int]
Gets the Aspose.Cells.Drawing.Shape object at the specific index in the list.
public Shape this[int index] { get; }
Property Value
Examples
csharp
[C#]
//get the first shape
Shape shape = shapes[0];
this[string]
Gets the Aspose.Cells.Drawing.Shape object by the name of the shape.
public Shape this[string name] { get; }
Property Value
Examples
csharp
[C#]
//add a shape
shapes.AddRectangle(2, 0, 2, 0, 130, 130);
//get the shape by the name.
Shape shape1 = shapes["Rectangle 1"];
if(shape1 != null)
{
//Got the shape named 'Rectangle 1'.
}
Methods
AddActiveXControl(ControlType, int, int, int, int, int, int)
Creates an Activex Control.
public Shape AddActiveXControl(ControlType type, int topRow, int top, int leftColumn, int left, int width, int height)
Parameters
type
ControlType
The type of the control.
topRow
int
Upper left row index.
top
int
Represents the vertical offset of Shape from its left row, in unit of pixel.
leftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Shape from its left column, in unit of pixel.
width
int
Represents the width of Shape, in unit of pixel.
height
int
Represents the height of Shape, in unit of pixel.
Returns
Examples
csharp
[C#]
//add an ActiveX control
Shape activeXControl = shapes.AddActiveXControl(Aspose.Cells.Drawing.ActiveXControls.ControlType.CheckBox, 1, 0, 1, 0, 100, 50);
AddArc(int, int, int, int, int, int)
Adds a ArcShape to the worksheet.
public ArcShape AddArc(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of ArcShape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of ArcShape from its left column, in unit of pixel.
height
int
Represents the height of ArcShape, in unit of pixel.
width
int
Represents the width of ArcShape, in unit of pixel.
Returns
A ArcShape object.
Examples
csharp
[C#]
//add a arc
ArcShape arcShape = shapes.AddArc(1, 0, 1, 0, 100, 50);
AddAutoShape(AutoShapeType, int, int, int, int, int, int)
Adds a AutoShape to the worksheet.
public Shape AddAutoShape(AutoShapeType type, int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
type
AutoShapeType
Auto shape type.
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of Shape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Shape from its left column, in unit of pixel.
height
int
Represents the height of Shape, in unit of pixel.
width
int
Represents the width of Shape, in unit of pixel.
Returns
A Shape object.
Examples
csharp
[C#]
//Adds a AutoShape to the worksheet.
Shape autoShape = shapes.AddAutoShape(AutoShapeType.Cube, 1, 0, 1, 0, 100, 50);
Remarks
The type could not be Chart/Comment/Picture/OleObject/Polygon/DialogBox
AddAutoShapeInChart(AutoShapeType, int, int, int, int)
Adds a AutoShape to the chart.
public Shape AddAutoShapeInChart(AutoShapeType type, int top, int left, int height, int width)
Parameters
type
AutoShapeType
Auto shape type.
top
int
Represents the vertical offset of textbox from the upper left corner in units of 1/4000 of the chart area.
left
int
Represents the vertical offset of textbox from the upper left corner in units of 1/4000 of the chart area.
height
int
Represents the height of textbox, in units of 1/4000 of the chart area.
width
int
Represents the width of textbox, in units of 1/4000 of the chart area.
Returns
Returns a shape object.
Remarks
The type could not be Chart/Comment/Picture/OleObject/Polygon/DialogBox
AddButton(int, int, int, int, int, int)
Adds a Button to the worksheet.
public Button AddButton(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of Button from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Button from its left column, in unit of pixel.
height
int
Represents the height of Button, in unit of pixel.
width
int
Represents the width of Button, in unit of pixel.
Returns
A Button object.
Examples
csharp
[C#]
//add a button
Button button = shapes.AddButton(1, 0, 1, 0, 100, 50);
AddCheckBox(int, int, int, int, int, int)
Adds a checkbox to the worksheet.
public CheckBox AddCheckBox(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of checkbox from its top row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of textbox from its left column, in unit of pixel.
height
int
Height of textbox, in unit of pixel.
width
int
Width of textbox, in unit of pixel.
Returns
The new CheckBox object index.
Examples
csharp
[C#]
//add a CheckBox
CheckBox checkBox = shapes.AddCheckBox(1, 0, 1, 0, 100, 50);
AddComboBox(int, int, int, int, int, int)
Adds a ComboBox to the worksheet.
public ComboBox AddComboBox(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of ComboBox from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of ComboBox from its left column, in unit of pixel.
height
int
Represents the height of ComboBox, in unit of pixel.
width
int
Represents the width of ComboBox, in unit of pixel.
Returns
A ComboBox object.
Examples
csharp
[C#]
//add a combo box
ComboBox comboBox = shapes.AddComboBox(1, 0, 1, 0, 100, 50);
AddCopy(Shape, int, int, int, int)
Adds and copy a shape to the worksheet.
public Shape AddCopy(Shape sourceShape, int topRow, int top, int leftColumn, int left)
Parameters
sourceShape
Shape
Source shape.
topRow
int
The top row index.
top
int
Represents the vertical offset from its top row, in unit of pixel.
leftColumn
int
The left column index.
left
int
Represents the horizontal offset from its left column, in unit of pixel.
Returns
The new Aspose.Cells.Drawing.Shape object.
Examples
csharp
[C#]
//add a shape
RectangleShape rectangle = shapes.AddRectangle(2, 0, 2, 0, 130, 130);
//Adds and copies a shape.
shapes.AddCopy(rectangle, 7, 0, 7, 0);
AddEquation(int, int, int, int, int, int)
Add an equation object to the worksheet.
public TextBox AddEquation(int topRow, int top, int leftColumn, int left, int height, int width)
Parameters
topRow
int
The top row index.
top
int
The vertical offset its top row, in unit of pixel.
leftColumn
int
The left column index.
left
int
The horizontal offset from its left column, in unit of pixel.
height
int
The height of equation, in unit of pixel.
width
int
The width of equation, in unit of pixel.
Returns
AddFreeFloatingShape(MsoDrawingType, int, int, int, int, byte[], bool)
Adds a free floating shape to the worksheet.Only applies for line/image shape.
public Shape AddFreeFloatingShape(MsoDrawingType type, int top, int left, int height, int width, byte[] imageData, bool isOriginalSize)
Parameters
type
MsoDrawingType
The shape type.
top
int
Represents the vertical offset of shape from the worksheet’s top row, in unit of pixel.
left
int
Represents the horizontal offset of shape from the worksheet’s left column, in unit of pixel.
height
int
Represents the height of LineShape, in unit of pixel.
width
int
Represents the width of LineShape, in unit of pixel.
imageData
byte[]
The image data,only applies for the picture.
isOriginalSize
bool
Whether the shape use original size if the shape is image.
Returns
Examples
csharp
[C#]
//add a line
Shape floatingShape_Line = shapes.AddFreeFloatingShape(MsoDrawingType.Line, 100, 100, 100, 50, null, false);
//add a picture
byte[] imageData = null;
using(FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
int len = (int)fs.Length;
imageData = new byte[len];
fs.Read(imageData, 0, len);
}
Shape floatingShape_Picture = shapes.AddFreeFloatingShape(MsoDrawingType.Picture, 200, 100, 100, 50, imageData, false);
AddFreeform(int, int, int, int, int, int, ShapePath[])
Adds a freeform shape to the worksheet.
public Shape AddFreeform(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width, ShapePath[] paths)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of Polygon from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Polygon from its left column, in unit of pixel.
height
int
Represents the height of Polygon, in unit of pixel.
width
int
Represents the width of Polygon, in unit of pixel.
paths
ShapePath[]
Represents a user-defined path
Returns
A freeform shape.
Examples
csharp
[C#]
//Custom figure
ShapePath shapePath = new ShapePath();
shapePath.MoveTo(60, 45);
shapePath.ArcTo(25, 25, 0, 270);
shapePath.Close();
shapePath.MoveTo(60, 20);
shapePath.LineTo(110, 70);
shapePath.LineTo(125, 155.5f);
shapePath.ArcTo(35.5f, 35.5f, 0, 270);
shapePath.Close();
shapePath.MoveTo(150, 45);
shapePath.ArcTo(25, 25, 0, 270);
ShapePath shapePath1 = new ShapePath();
shapePath1.MoveTo(0, 0);
shapePath1.CubicBezierTo(48.24997f, 0.6844f,
96.5f, -7.148871f,
130, 11.517795f);
shapePath1.CubicBezierTo(163.5f, 30.18446f,
182.24997f, 75.351f,
201, 120.517795f);
shapePath1.MoveTo(150, 80);
shapePath1.ArcTo(25, 25, 0, 270);
//Insert custom figure into worksheet
shapes.AddFreeform(1, 0, 1, 0, 200, 200, new ShapePath[] { shapePath, shapePath1});
AddGroupBox(int, int, int, int, int, int)
Adds a GroupBox to the worksheet.
public GroupBox AddGroupBox(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of GroupBox from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of GroupBox from its left column, in unit of pixel.
height
int
Represents the height of GroupBox, in unit of pixel.
width
int
Represents the width of GroupBox, in unit of pixel.
Returns
A GroupBox object.
Examples
csharp
[C#]
//add a group box
GroupBox groupBox = shapes.AddGroupBox(1, 0, 1, 0, 100, 50);
AddIcons(int, int, int, int, int, int, byte[], byte[])
Adds svg image.
public Picture AddIcons(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width, byte[] imageByteData, byte[] compatibleImageData)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of shape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
The horizontal offset of shape from its left column, in unit of pixel.
height
int
The height of shape, in unit of pixel.
width
int
The width of shape, in unit of pixel.
imageByteData
byte[]
The image byte data.
compatibleImageData
byte[]
Converted image data from svg in order to be compatible with Excel 2016 or lower versions.
Returns
Examples
csharp
[C#]
//add icon
using (FileStream fs = new FileStream("icon.svg", FileMode.Open))
{
int len = (int)fs.Length;
byte[] imageData = new byte[len];
fs.Read(imageData, 0, len);
Picture picture = shapes.AddIcons(4, 0, 5, 0, -1, -1, imageData, null);
}
AddLabel(int, int, int, int, int, int)
Adds a Label to the worksheet.
public Label AddLabel(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of Label from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Label from its left column, in unit of pixel.
height
int
Represents the height of Label, in unit of pixel.
width
int
Represents the width of Label, in unit of pixel.
Returns
A Label object.
Examples
csharp
[C#]
//add a label
Label label = shapes.AddLabel(1, 0, 1, 0, 100, 50);
AddLabelInChart(int, int, int, int)
Adds a label to the chart.
public Label AddLabelInChart(int top, int left, int height, int width)
Parameters
top
int
Represents the vertical offset of label from the upper left corner in units of 1/4000 of the chart area.
left
int
Represents the vertical offset of label from the upper left corner in units of 1/4000 of the chart area.
height
int
Represents the height of label, in units of 1/4000 of the chart area.
width
int
Represents the width of label, in units of 1/4000 of the chart area.
Returns
A new Label object.
AddLine(int, int, int, int, int, int)
Adds a LineShape to the worksheet.
public LineShape AddLine(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of LineShape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of LineShape from its left column, in unit of pixel.
height
int
Represents the height of LineShape, in unit of pixel.
width
int
Represents the width of LineShape, in unit of pixel.
Returns
A LineShape object.
Examples
csharp
[C#]
// add a line object
LineShape lineShape = shapes.AddLine(1, 0, 1, 0, 100, 50);
AddLinkedPicture(int, int, int, int, string)
Add a linked picture.
public Picture AddLinkedPicture(int upperLeftRow, int upperLeftColumn, int height, int width, string sourceFullName)
Parameters
upperLeftRow
int
Upper left row index.
upperLeftColumn
int
Upper left column index.
height
int
The height of the shape. In unit of pixels
width
int
The width of the shape. In unit of pixels
sourceFullName
string
The path and name of the source file for the linked image
Returns
Aspose.Cells.Drawing.Picture Picture object.
AddListBox(int, int, int, int, int, int)
Adds a ListBox to the worksheet.
public ListBox AddListBox(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of ListBox from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of ListBox from its left column, in unit of pixel.
height
int
Represents the height of ListBox, in unit of pixel.
width
int
Represents the width of ListBox, in unit of pixel.
Returns
A ListBox object.
Examples
csharp
[C#]
//add a list box
ListBox listBox = shapes.AddListBox(1, 0, 1, 0, 100, 50);
AddOleObject(int, int, int, int, int, int, byte[])
Adds an OleObject.
public OleObject AddOleObject(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width, byte[] imageData)
Parameters
upperLeftRow
int
top
int
upperLeftColumn
int
left
int
height
int
width
int
imageData
byte[]
Returns
Examples
csharp
[C#]
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
int len = (int)fs.Length;
byte[] imageData = new byte[len];
fs.Read(imageData, 0, len);
OleObject oleObject = shapes.AddOleObject(4, 0, 5, 0, 300, 500, imageData);
}
AddOleObjectWithLinkedImage(int, int, int, int, string)
Add a linked picture.
public OleObject AddOleObjectWithLinkedImage(int upperLeftRow, int upperLeftColumn, int height, int width, string sourceFullName)
Parameters
upperLeftRow
int
Upper left row index.
upperLeftColumn
int
Upper left column index.
height
int
The height of the shape. In unit of pixels
width
int
The width of the shape. In unit of pixels
sourceFullName
string
The path and name of the source file for the linked image
Returns
Aspose.Cells.Drawing.Picture Picture object.
AddOval(int, int, int, int, int, int)
Adds a Oval to the worksheet.
public Oval AddOval(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of Oval from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Oval from its left column, in unit of pixel.
height
int
Represents the height of Oval, in unit of pixel.
width
int
Represents the width of Oval, in unit of pixel.
Returns
A Oval object.
Examples
csharp
[C#]
//add a oval
Oval oval = shapes.AddOval(1, 0, 1, 0, 50, 50);
AddPicture(int, int, int, int, Stream)
Adds a picture to the collection.
public Picture AddPicture(int upperLeftRow, int upperLeftColumn, int lowerRightRow, int lowerRightColumn, Stream stream)
Parameters
upperLeftRow
int
Upper left row index.
upperLeftColumn
int
Upper left column index.
lowerRightRow
int
Lower right row index
lowerRightColumn
int
Lower right column index
stream
Stream
Stream object which contains the image data.
Returns
Aspose.Cells.Drawing.Picture Picture object.
Examples
csharp
[C#]
//add a picture
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
Picture picture = shapes.AddPicture(1, 0, 1, 0, fs);
}
AddPicture(int, int, Stream, int, int)
Adds a picture to the collection.
public Picture AddPicture(int upperLeftRow, int upperLeftColumn, Stream stream, int widthScale, int heightScale)
Parameters
upperLeftRow
int
Upper left row index.
upperLeftColumn
int
Upper left column index.
stream
Stream
Stream object which contains the image data.
widthScale
int
Scale of image width, a percentage.
heightScale
int
Scale of image height, a percentage.
Returns
Aspose.Cells.Drawing.Picture Picture object.
Examples
csharp
[C#]
//add a picture
using (FileStream fs = new FileStream("image.jpg", FileMode.Open))
{
Picture picture = shapes.AddPicture(1, 1, fs, 50, 60);
}
AddPictureInChart(int, int, Stream, int, int)
Adds a picture to the chart.
public Picture AddPictureInChart(int top, int left, Stream stream, int widthScale, int heightScale)
Parameters
top
int
Represents the vertical offset of shape from the upper left corner in units of 1/4000 of the chart area.
left
int
Represents the horizontal offset of shape from the upper left corner in units of 1/4000 of the chart area.
stream
Stream
Stream object which contains the image data.
widthScale
int
Scale of image width, a percentage.
heightScale
int
Scale of image height, a percentage.
Returns
Returns a Picture object.
AddRadioButton(int, int, int, int, int, int)
Adds a RadioButton to the worksheet.
public RadioButton AddRadioButton(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of RadioButton from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of RadioButton from its left column, in unit of pixel.
height
int
Represents the height of RadioButton, in unit of pixel.
width
int
Represents the width of RadioButton, in unit of pixel.
Returns
A RadioButton object.
Examples
csharp
[C#]
//add a radio button
RadioButton radioButton = shapes.AddRadioButton(1, 0, 1, 0, 100, 50);
AddRectangle(int, int, int, int, int, int)
Adds a RectangleShape to the worksheet.
public RectangleShape AddRectangle(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of RectangleShape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of RectangleShape from its left column, in unit of pixel.
height
int
Represents the height of RectangleShape, in unit of pixel.
width
int
Represents the width of RectangleShape, in unit of pixel.
Returns
A RectangleShape object.
Examples
csharp
[C#]
// add a rectangle
RectangleShape rectangleShape = shapes.AddRectangle(2, 0, 2, 0, 130, 130);
AddScrollBar(int, int, int, int, int, int)
Adds a ScrollBar to the worksheet.
public ScrollBar AddScrollBar(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of ScrollBar from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of ScrollBar from its left column, in unit of pixel.
height
int
Represents the height of ScrollBar, in unit of pixel.
width
int
Represents the width of ScrollBar, in unit of pixel.
Returns
A ScrollBar object.
Examples
csharp
[C#]
//add a scroll bar
ScrollBar scrollBar = shapes.AddScrollBar(1, 0, 1, 0, 100, 20);
AddShape(MsoDrawingType, int, int, int, int, int, int)
Adds a Shape to the worksheet.
public Shape AddShape(MsoDrawingType type, int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
type
MsoDrawingType
Mso drawing type.
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of Shape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Shape from its left column, in unit of pixel.
height
int
Represents the height of Shape, in unit of pixel.
width
int
Represents the width of Shape, in unit of pixel.
Returns
A Shape object.
Examples
csharp
[C#]
//Add a shape of the specified type
Shape shapeByType = shapes.AddShape(MsoDrawingType.CellsDrawing, 1, 0, 1, 0, 100, 50);
Remarks
The type could not be Chart/Comment/Picture/OleObject/Polygon/DialogBox
AddShapeInChart(MsoDrawingType, PlacementType, int, int, int, int, byte[])
Add a shape to chart .All unit is 1/4000 of chart area.
public Shape AddShapeInChart(MsoDrawingType type, PlacementType placement, int left, int top, int right, int bottom, byte[] imageData)
Parameters
type
MsoDrawingType
The drawing type.
placement
PlacementType
the placement type.
left
int
In unit of 1/4000 chart area width.
top
int
In unit of 1/4000 chart area height.
right
int
In unit of 1/4000 chart area width.
bottom
int
In unit of 1/4000 chart area height.
imageData
byte[]
If the shape is not a picture or ole object,imageData should be null.
Returns
AddShapeInChart(MsoDrawingType, PlacementType, int, int, int, int)
Add a shape to chart .All unit is 1/4000 of chart area.
public Shape AddShapeInChart(MsoDrawingType type, PlacementType placement, int left, int top, int right, int bottom)
Parameters
type
MsoDrawingType
The drawing type.
placement
PlacementType
the placement type.
left
int
In unit of 1/4000 chart area width.
top
int
In unit of 1/4000 chart area height.
right
int
In unit of 1/4000 chart area width.
bottom
int
In unit of 1/4000 chart area height.
Returns
AddShapeInChartByScale(MsoDrawingType, PlacementType, double, double, double, double)
Add a shape to chart. All unit is percent scale of chart area.
public Shape AddShapeInChartByScale(MsoDrawingType type, PlacementType placement, double left, double top, double right, double bottom)
Parameters
type
MsoDrawingType
The drawing type.
placement
PlacementType
the placement type.
left
double
Unit is percent scale of chart area width.
top
double
Unit is percent scale of chart area height.
right
double
Unit is percent scale of chart area width.
bottom
double
Unit is percent scale of chart area height.
Returns
AddShapeInChartByScale(MsoDrawingType, PlacementType, double, double, double, double, byte[])
Add a shape to chart .All unit is 1/4000 of chart area.
public Shape AddShapeInChartByScale(MsoDrawingType type, PlacementType placement, double left, double top, double right, double bottom, byte[] imageData)
Parameters
type
MsoDrawingType
The drawing type.
placement
PlacementType
the placement type.
left
double
Unit is percent scale of chart area width.
top
double
Unit is percent scale of chart area height.
right
double
Unit is percent scale of chart area width.
bottom
double
Unit is percent scale of chart area height.
imageData
byte[]
If the shape is not a picture or ole object,imageData should be null.
Returns
AddSignatureLine(int, int, SignatureLine)
Adds a Signature Line to the worksheet.
public Picture AddSignatureLine(int upperLeftRow, int upperLeftColumn, SignatureLine signatureLine)
Parameters
upperLeftRow
int
Upper left row index.
upperLeftColumn
int
Upper left column index.
signatureLine
SignatureLine
Represents a signature line object.
Returns
Examples
csharp
[C#]
SignatureLine wSignatureLine = new SignatureLine();
wSignatureLine.AllowComments = true;
wSignatureLine.Email = "example@example.com";
wSignatureLine.Instructions = "Sign to confirm the excel content.";
wSignatureLine.IsLine = true;
wSignatureLine.ShowSignedDate = true;
wSignatureLine.Signer = "User";
wSignatureLine.Title = "tester";
//wSignatureLine.SignatureLineType = SignatureType.Stamp;
Picture signatureLine1 = shapes.AddSignatureLine(0, 0, wSignatureLine);
AddSpinner(int, int, int, int, int, int)
Adds a Spinner to the worksheet.
public Spinner AddSpinner(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of Spinner from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of Spinner from its left column, in unit of pixel.
height
int
Represents the height of Spinner, in unit of pixel.
width
int
Represents the width of Spinner, in unit of pixel.
Returns
A Spinner object.
Examples
csharp
[C#]
//add a spinner
Spinner spinner = shapes.AddSpinner(1, 0, 1, 0, 100, 50);
AddSvg(int, int, int, int, int, int, byte[], byte[])
Adds svg image.
public Picture AddSvg(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width, byte[] svgData, byte[] compatibleImageData)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of shape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
The horizontal offset of shape from its left column, in unit of pixel.
height
int
The height of shape, in unit of pixel.
width
int
The width of shape, in unit of pixel.
svgData
byte[]
The svg image data.
compatibleImageData
byte[]
Converted image data from svg in order to be compatible with Excel 2016 or lower versions.
Returns
Examples
csharp
[C#]
// add a svg
using (FileStream fs = new FileStream("image.svg", FileMode.Open))
{
int len = (int)fs.Length;
byte[] imageData = new byte[len];
fs.Read(imageData, 0, len);
Picture picture = shapes.AddSvg(4, 0, 5, 0, -1, -1, imageData, null);
}
AddTextBox(int, int, int, int, int, int)
Adds a text box to the worksheet.
public TextBox AddTextBox(int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of textbox from its top row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of textbox from its left column, in unit of pixel.
height
int
Represents the height of textbox, in unit of pixel.
width
int
Represents the width of textbox, in unit of pixel.
Returns
A Aspose.Cells.Drawing.TextBox object.
Examples
csharp
[C#]
//add a TextBox
TextBox textBox = shapes.AddTextBox(1, 0, 1, 0, 100, 50);
AddTextBoxInChart(int, int, int, int)
Adds a textbox to the chart.
public TextBox AddTextBoxInChart(int top, int left, int height, int width)
Parameters
top
int
Represents the vertical offset of textbox from the upper left corner in units of 1/4000 of the chart area.
left
int
Represents the vertical offset of textbox from the upper left corner in units of 1/4000 of the chart area.
height
int
Represents the height of textbox, in units of 1/4000 of the chart area.
width
int
Represents the width of textbox, in units of 1/4000 of the chart area.
Returns
A TextBox object.
AddTextEffect(MsoPresetTextEffect, string, string, int, bool, bool, int, int, int, int, int, int)
Inserts a WordArt object.
public Shape AddTextEffect(MsoPresetTextEffect effect, string text, string fontName, int size, bool fontBold, bool fontItalic, int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
effect
MsoPresetTextEffect
The mso preset text effect type.
text
string
The WordArt text.
fontName
string
The font name.
size
int
The font size
fontBold
bool
Indicates whether font is bold.
fontItalic
bool
Indicates whether font is italic.
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of shape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of shape from its left column, in unit of pixel.
height
int
Represents the height of shape, in unit of pixel.
width
int
Represents the width of shape, in unit of pixel.
Returns
Returns a Shape object that represents the new WordArt object.
Examples
csharp
[C#]
//add a WordArt
Shape wordArt1 = shapes.AddTextEffect(MsoPresetTextEffect.TextEffect10, "WordArt", "arial", 18, false, false, 3, 0, 3, 0, 200, 50);
AddTextEffectInChart(MsoPresetTextEffect, string, string, int, bool, bool, int, int, int, int)
Inserts a WordArt object to the chart
public Shape AddTextEffectInChart(MsoPresetTextEffect effect, string text, string fontName, int size, bool fontBold, bool fontItalic, int top, int left, int height, int width)
Parameters
effect
MsoPresetTextEffect
The mso preset text effect type.
text
string
The WordArt text.
fontName
string
The font name.
size
int
The font size
fontBold
bool
Indicates whether font is bold.
fontItalic
bool
Indicates whether font is italic.
top
int
Represents the vertical offset of shape from the upper left corner in units of 1/4000 of the chart area.
left
int
Represents the vertical offset of shape from the upper left corner in units of 1/4000 of the chart area.
height
int
Represents the height of shape, in units of 1/4000 of the chart area.
width
int
Represents the width of shape, in units of 1/4000 of the chart area.
Returns
Returns a Shape object that represents the new WordArt object.
AddWordArt(PresetWordArtStyle, string, int, int, int, int, int, int)
Adds preset WordArt since Excel 2007.s
public Shape AddWordArt(PresetWordArtStyle style, string text, int upperLeftRow, int top, int upperLeftColumn, int left, int height, int width)
Parameters
style
PresetWordArtStyle
The preset WordArt Style.
text
string
The text.
upperLeftRow
int
Upper left row index.
top
int
Represents the vertical offset of shape from its left row, in unit of pixel.
upperLeftColumn
int
Upper left column index.
left
int
Represents the horizontal offset of shape from its left column, in unit of pixel.
height
int
Represents the height of shape, in unit of pixel.
width
int
Represents the width of shape, in unit of pixel.
Returns
Examples
csharp
[C#]
//add a WordArt
Shape wordArt2 = shapes.AddWordArt(PresetWordArtStyle.WordArtStyle1, "WordArt", 3, 0, 3, 0, 50, 200);
Clear()
Clear all shapes in the worksheet.
public void Clear()
Examples
csharp
[C#]
if (shapes.Count > 0)
{
shapes.Clear();
}
CopyCommentsInRange(ShapeCollection, CellArea, int, int)
Copy all comments in the range.
public void CopyCommentsInRange(ShapeCollection shapes, CellArea ca, int destRow, int destColumn)
Parameters
shapes
ShapeCollection
The source shapes.
ca
CellArea
The source range.
destRow
int
The dest range start row.
destColumn
int
The dest range start column.
Examples
csharp
[C#]
CommentCollection comments = workbook.Worksheets[0].Comments;
//Add comment to cell A1
int commentIndex = comments.Add(0, 0);
Comment comment = comments[commentIndex];
comment.Note = "First note.";
comment.Font.Name = "Times New Roman";
//Add comment to cell B2
comments.Add("B2");
comment = comments["B2"];
comment.Note = "Second note.";
CellArea area1 = new CellArea();
area1.StartColumn = 1;
area1.StartRow = 1;
area1.EndColumn = 5;
area1.EndRow = 4;
//copy
shapes.CopyCommentsInRange(shapes, area1, 5, 1);
CopyInRange(ShapeCollection, CellArea, int, int, bool)
Copy shapes in the range to destination range.
public void CopyInRange(ShapeCollection sourceShapes, CellArea ca, int destRow, int destColumn, bool isContained)
Parameters
sourceShapes
ShapeCollection
Source shapes.
ca
CellArea
The source range.
destRow
int
The dest row index of the dest range.
destColumn
int
The dest column of the dest range.
isContained
bool
Whether only copy the shapes which are contained in the range. If true,only copies the shapes in the range. Otherwise,it works as MS Office.
Examples
csharp
[C#]
//add a shape
shapes.AddRectangle(2, 0, 2, 0, 130, 130);
CellArea area2 = new CellArea();
area2.StartColumn = 1;
area2.StartRow = 1;
area2.EndColumn = 5;
area2.EndRow = 11;
//copy
shapes.CopyInRange(shapes, area2, 12, 1, false);
DeleteInRange(CellArea)
Delete shapes in the range.Comment shapes will not be deleted.
public void DeleteInRange(CellArea ca)
Parameters
ca
CellArea
The range.If the shapes are contained in the range, they will be removed.
Examples
csharp
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
CellArea area3 = new CellArea();
area3.StartColumn = 0;
area3.StartRow = 5;
area3.EndColumn = 5;
area3.EndRow = 8;
//del
shapes.DeleteInRange(area3);
DeleteShape(Shape)
Delete a shape. If the shape is in the group or is a comment shape, it will not be deleted.
public void DeleteShape(Shape shape)
Parameters
shape
Shape
Examples
csharp
[C#]
//add first shape
Shape firstShape = shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
Shape secondShape = shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//del
shapes.DeleteShape(firstShape);
Group(Shape[])
Group the shapes.
public GroupShape Group(Shape[] groupItems)
Parameters
groupItems
Shape[]
the group items.
Returns
Return the group shape.
Examples
csharp
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
Shape[] shapesArr = new Shape[] { shapes[0], shapes[1] };
GroupShape groupShape = shapes.Group(shapesArr);
Remarks
The shape in the groupItems should not be grouped. The shape must be in this Shapes collection.
Remove(Shape)
Remove the shape.
public void Remove(Shape shape)
Parameters
shape
Shape
Examples
csharp
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//get the shape
Shape s = shapes["Rectangle 1"];// or shapes[0];
if (s != null)
{
//remove
shapes.Remove(s);
}
RemoveAt(int)
Remove the shape.
public void RemoveAt(int index)
Parameters
index
int
The index of the shape.
Examples
csharp
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//remove
shapes.RemoveAt(0);
Ungroup(GroupShape)
Ungroups the shape items.
public void Ungroup(GroupShape group)
Parameters
group
GroupShape
The group shape.
Examples
csharp
[C#]
//add first shape
shapes.AddRectangle(2, 0, 2, 0, 50, 50);
//add second shape
shapes.AddRectangle(6, 0, 2, 0, 30, 30);
//group
Shape[] shapesArr = new Shape[] { shapes[0], shapes[1] };
GroupShape groupShape = shapes.Group(shapesArr);
//ungroup
shapes.Ungroup(groupShape);
Remarks
If the group shape is grouped by another group shape,nothing will be done.
UpdateSelectedValue()
Update the selected value by the value of the linked cell or range of the shape.
public void UpdateSelectedValue()
</shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape></shape>