Interface IShape
Represents a shape.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Base.dll
Syntax
public interface IShape : IParentApplication
Properties
AlternativeText
Alternative text.
Declaration
string AlternativeText { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Examples
The following code illustrates how to set AlternativeText
for the shape.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set alternate text
shape.AlternativeText = "Rectangle Shape";
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Fill
Represents fill properties. Read-only.
Declaration
IFill Fill { get; }
Property Value
Type | Description |
---|---|
IFill |
Examples
The following code illustrates how to access Fill
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set fill
IFill fill = shape.Fill;
//Set fill color
fill.ForeColorIndex = ExcelKnownColors.Red;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Height
Height of the shape.
Declaration
int Height { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to set and get shape's height using Height
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shapes
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
IComboBoxShape comboBox = worksheet.Shapes.AddComboBox();
//Set dimensions
comboBox.Left = 140;
comboBox.Top = 150;
comboBox.Height = 20;
comboBox.Width = 100;
//Get dimensions
Console.WriteLine(shape.Width);
Console.WriteLine(shape.Height);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//70
//20
Hyperlink
Get object that represents the IHyperLink for the shape.
Declaration
IHyperLink Hyperlink { get; }
Property Value
Type | Description |
---|---|
IHyperLink |
Remarks
To know more about HyperLinks
refer Hyperlinks on Shapes.
Examples
The following code illustrates how to set and access HyperLink
in Shapes
.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Add hyperlink
IHyperLink hyperLink = worksheet.HyperLinks.Add(shape, ExcelHyperLinkType.Url, "http://www.syncfusion.com", "Syncfusion");
//Set hyperlink
IHyperLink link = shape.Hyperlink;
//Get address
Console.Write(link.Address);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//http://www.syncfusion.com
Id
Shape id.
Declaration
int Id { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to access Id
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shapes
IShape checkBox = worksheet.Shapes.AddCheckBox();
//Set dimensions
checkBox.Left = 150;
checkBox.Top = 150;
checkBox.Width = 70;
checkBox.Height = 20;
//Get ID
Console.WriteLine(checkBox.Id);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//0
IsMoveWithCell
Indicates whether shape must be moved with cells.
Declaration
bool IsMoveWithCell { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Examples
By default IsMoveWithCell
property is set to "true" so the shape will be moving along the cell if the cell's width is increased or decreased.
Here for example, we set IsMoveWithCell
to "false".
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
//Set move with cells
shape.IsMoveWithCell = false;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
IsShapeVisible
Indicates whether shape is visible.
Declaration
bool IsShapeVisible { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Examples
The following code illustrates how to set visibility of the shape.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set shape visibility
shape.IsShapeVisible = false;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
IsSizeWithCell
Indicates whether shape must be sized with cells.
Declaration
bool IsSizeWithCell { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Examples
By default IsSizeWithCell
property is set to "false" so the shape's size will is not changed if the cell's height and width are changed.
Here for example, we set IsSizeWithCell
to "true".
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
//Set size with cells
shape.IsSizeWithCell = true;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Left
Left position of the shape.
Declaration
int Left { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to set and get left side spacing for the shape using Left
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shapes
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
IComboBoxShape comboBox = worksheet.Shapes.AddComboBox();
//Set dimensions
comboBox.Left = 140;
comboBox.Top = 150;
comboBox.Height = 20;
comboBox.Width = 100;
//Get dimensions
Console.WriteLine(shape.Width);
Console.WriteLine(shape.Height);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//70
//20
Line
Represents line format properties. Read-only.
Declaration
IShapeLineFormat Line { get; }
Property Value
Type | Description |
---|---|
IShapeLineFormat |
Examples
The following code illustrates how to access Line
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set line format
IShapeLineFormat lineFormat = shape.Line;
//Set line color
lineFormat.ForeColorIndex = ExcelKnownColors.Red;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Name
Name of the shape.
Declaration
string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Examples
The following code illustrates how to access Name
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shapes
IShape checkBox = worksheet.Shapes.AddCheckBox();
//Set dimensions
checkBox.Left = 150;
checkBox.Top = 150;
checkBox.Width = 70;
checkBox.Height = 20;
//Get name
Console.WriteLine(checkBox.Name);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//CheckBox1
OnAction
Gets or sets macro associated with this shape
Declaration
string OnAction { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Shadow
Gets the Shadow
of the shape
Declaration
IShadow Shadow { get; }
Property Value
Type | Description |
---|---|
IShadow |
Examples
The following code illustrates how to access Shadow
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set shadow
IShadow shadow = shape.Shadow;
//Set shadow properties
shadow.Distance = 40;
shadow.Size = 150;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
ShapeRotation
Returns or sets the rotation of the shape, in degrees.
Declaration
int ShapeRotation { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to set ShapeRotation
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set shape rotation
shape.ShapeRotation = 35;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
ShapeType
Shape type.
Declaration
ExcelShapeType ShapeType { get; }
Property Value
Type | Description |
---|---|
ExcelShapeType |
Examples
The following code illustrates how to access ShapeType
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Get shape type
Console.WriteLine(shape.ShapeType);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//AutoShape
TextFrame
Returns a ITextFrame object that contains the alignment and anchoring properties for the specified shape. Read-only.
Declaration
ITextFrame TextFrame { get; }
Property Value
Type | Description |
---|---|
ITextFrame |
Examples
The following code illustrates how to access TextFrame
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set text frame
ITextFrame textFrame = shape.TextFrame;
//Set text range
ITextRange textRange = textFrame.TextRange;
//Set text
textRange.Text = "Sample";
//Set alignment
textFrame.HorizontalAlignment = ExcelHorizontalAlignment.Right;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
ThreeD
Gets the Three dimensional format of the shape.
Declaration
IThreeDFormat ThreeD { get; }
Property Value
Type | Description |
---|---|
IThreeDFormat |
Examples
The following code illustrates how to access ThreeD
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set 3D format
IThreeDFormat format = shape.ThreeD;
//Set material
format.Material = Excel2007ChartMaterialProperties.TranslucentPowder;
//Save and dispose
workbook.SaveAs("Shapes3D.xlsx");
workbook.Close();
}
Top
Top position of the shape.
Declaration
int Top { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to set and get top spacing for the shape using Top
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shapes
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
IComboBoxShape comboBox = worksheet.Shapes.AddComboBox();
//Set dimensions
comboBox.Left = 140;
comboBox.Top = 150;
comboBox.Height = 20;
comboBox.Width = 100;
//Get dimensions
Console.WriteLine(shape.Width);
Console.WriteLine(shape.Height);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//70
//20
Width
Width of the shape.
Declaration
int Width { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
The following code illustrates how to set and get the width of the shape using Width
property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shapes
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 70);
IComboBoxShape comboBox = worksheet.Shapes.AddComboBox();
//Set dimensions
comboBox.Left = 140;
comboBox.Top = 150;
comboBox.Height = 20;
comboBox.Width = 100;
//Get dimensions
Console.WriteLine(shape.Width);
Console.WriteLine(shape.Height);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//70
//20
Methods
Remove()
Declaration
void Remove()
Examples
The following code illustrates how to remove a IShape from the IShapes collection.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 100);
worksheet.Shapes.AddAutoShapes(AutoShapeType.Cube, 5, 5, 20, 100);
//Remove a shape
worksheet.Shapes[0].Remove();
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Scale(Int32, Int32)
Scales the shape.
Declaration
void Scale(int scaleWidth, int scaleHeight)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | scaleWidth | Width scale in percents. |
System.Int32 | scaleHeight | Height scale in percents. |
Examples
The following code illustrates how to scale a shape after adding it.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Add shape
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 20, 100);
//Set scaling
shape.Scale(50, 50);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}