Interface IShapes
Represents shapes collection in the workbook.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.UWP.dll
Syntax
public interface IShapes : IParentApplication, IEnumerable
Properties
Count
Declaration
int Count { get; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to access Count
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);
//Add copy
IShape copiedShape = worksheet.Shapes.AddCopy(shape);
//Get count
Console.Write(worksheet.Shapes.Count);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//2
Item[Int32]
Declaration
IShape this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Property Value
Type |
---|
IShape |
Examples
The following code illustrates how to access 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, 40, 100);
//Add copy
IShape copiedShape = worksheet.Shapes.AddCopy(worksheet.Shapes[0]);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Item[String]
Declaration
IShape this[string strShapeName] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.String | strShapeName |
Property Value
Type |
---|
IShape |
Examples
The following code illustrates how to access 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
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Set name
shape.Name = "Shape1";
//Add copy
worksheet.Shapes.AddCopy(worksheet.Shapes["Shape1"]);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Methods
AddAutoShapes(AutoShapeType, Int32, Int32, Int32, Int32)
Declaration
IShape AddAutoShapes(AutoShapeType autoShapeType, int topRow, int leftColumn, int height, int width)
Parameters
Type | Name | Description |
---|---|---|
AutoShapeType | autoShapeType | AutoShape type |
System.Int32 | topRow | One-based index of the top row of the shape to be placed. |
System.Int32 | leftColumn | One-based index of the left column of the shape to be placed. |
System.Int32 | height | Height of the auto shapes. |
System.Int32 | width | Width of the auto shapes. |
Returns
Type | Description |
---|---|
IShape | Returns newly added shape. |
Examples
The following code illustrates how to add a IShape to 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
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
AddChart()
Adds new chart shape to the collection.
Declaration
IChartShape AddChart()
Returns
Type | Description |
---|---|
IChartShape | Newly added shape. |
AddCheckBox()
Adds new ICheckBoxShape to the IShapes collection.
Declaration
ICheckBoxShape AddCheckBox()
Returns
Type | Description |
---|---|
ICheckBoxShape | Newly created checkbox. |
Examples
The following code illustrates how to add a ICheckBoxShape to 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 checkbox
ICheckBoxShape checkbox = worksheet.Shapes.AddCheckBox();
//Set dimensions
checkbox.Top = 1;
checkbox.Left = 1;
checkbox.Height = 20;
checkbox.Width = 100;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
AddComboBox()
Adds new IComboBoxShape to the IShapes collection.
Declaration
IComboBoxShape AddComboBox()
Returns
Type | Description |
---|---|
IComboBoxShape | Newly created checkbox. |
Examples
The following code illustrates how to add a IComboBoxShape to 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 combobox
IComboBoxShape combobox = worksheet.Shapes.AddComboBox();
//Set dimensions
combobox.Top = 1;
combobox.Left = 1;
combobox.Height = 20;
combobox.Width = 100;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
AddComment()
Adds new Comment shape with empty comment text to the collection.
Declaration
ICommentShape AddComment()
Returns
Type | Description |
---|---|
ICommentShape | Newly added shape. |
AddComment(String)
Adds new Comment shape to the collection.
Declaration
ICommentShape AddComment(string commentText)
Parameters
Type | Name | Description |
---|---|---|
System.String | commentText | Text of the comment. |
Returns
Type | Description |
---|---|
ICommentShape | Newly added shape. |
AddComment(String, Boolean)
Adds new Comment shape to the collection.
Declaration
ICommentShape AddComment(string commentText, bool bIsParseOptions)
Parameters
Type | Name | Description |
---|---|---|
System.String | commentText | Text of the comment. |
System.Boolean | bIsParseOptions | Indicates is parse comment fill line options. |
Returns
Type | Description |
---|---|
ICommentShape | Newly added shape. |
AddCopy(IShape)
Adds shape copy to the collection.
Declaration
IShape AddCopy(IShape sourceShape)
Parameters
Type | Name | Description |
---|---|---|
IShape | sourceShape | Shape to copy. |
Returns
Type | Description |
---|---|
IShape | Added shape. |
Examples
The following code illustrates how to add a copy of the source shape to 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
IShape shape = worksheet.Shapes.AddAutoShapes(AutoShapeType.Rectangle, 2, 2, 40, 100);
//Add copy
IShape copiedShape = worksheet.Shapes.AddCopy(shape);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
AddCopy(IShape, Dictionary<String, String>, List<Int32>)
Adds shape copy to shapes collection.
Declaration
IShape AddCopy(IShape sourceShape, Dictionary<string, string> hashNewNames, List<int> arrFontIndexes)
Parameters
Type | Name | Description |
---|---|---|
IShape | sourceShape | Shape to copy. |
System.Collections.Generic.Dictionary<System.String, System.String> | hashNewNames | Dictionary with new names of worksheets. |
System.Collections.Generic.List<System.Int32> | arrFontIndexes | List with new font indexes. |
Returns
Type | Description |
---|---|
IShape | Added shape. |
AddOptionButton()
Adds new IOptionButtonShape to the IShapes collection.
Declaration
IOptionButtonShape AddOptionButton()
Returns
Type | Description |
---|---|
IOptionButtonShape | Newly created checkbox. |
Examples
The following code illustrates how to add a IOptionButtonShape to 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 option button
IOptionButtonShape optionButton = worksheet.Shapes.AddOptionButton();
//Set dimensions
optionButton.Top = 1;
optionButton.Left = 1;
optionButton.Height = 20;
optionButton.Width = 100;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
AddPicture(Image, String, ExcelImageFormat)
Adds new IPictureShape to the IShapes collection.
Declaration
IPictureShape AddPicture(Image image, string pictureName, ExcelImageFormat imageFormat)
Parameters
Type | Name | Description |
---|---|---|
Image | image | Image to add. |
System.String | pictureName | File name with the image. |
ExcelImageFormat | imageFormat | Image format to use for picture storing. |
Returns
Type | Description |
---|---|
IPictureShape | Newly created picture shape. |
Examples
The following code illustrates how to add a IPictureShape to 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];
//Get image
System.Drawing.Image image = System.Drawing.Image.FromFile("image.png");
//Add picture shape
IPictureShape picture = worksheet.Shapes.AddPicture(image, "Image1", ExcelImageFormat.Jpeg);
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
AddTextBox()
Adds new ITextBoxShapeEx to the IShapes collection.
Declaration
ITextBoxShapeEx AddTextBox()
Returns
Type | Description |
---|---|
ITextBoxShapeEx | Newly created textbox. |
Examples
The following code illustrates how to add a ITextBoxShapeEx to 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 textbox
ITextBoxShapeEx textbox = worksheet.Shapes.AddTextBox();
//Set dimensions
textbox.Top = 1;
textbox.Left = 1;
textbox.Height = 40;
textbox.Width = 300;
//Save and dispose
workbook.SaveAs("Shapes.xlsx");
workbook.Close();
}
Group(IShape[])
Create a IGroupShape for selected items.
Declaration
IGroupShape Group(IShape[] groupItems)
Parameters
Type | Name | Description |
---|---|---|
IShape[] | groupItems | AutoShapeType |
Returns
Type | Description |
---|---|
IGroupShape | Newly created group shape |
Examples
The following code illustrates how to ungroup a specified IGroupShape.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("GroupShapes.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IShapes shapes = worksheet.Shapes;
IShape[] groupItems = new IShape[] { shapes[0], shapes[1] };
// Create group shape for selected items.
IGroupShape GroupShape = shapes.Group(groupItems);
//Save and dispose
workbook.SaveAs("GroupShapes.xlsx");
workbook.Close();
}
Ungroup(IGroupShape)
Ungroup the specified group shape.
Declaration
void Ungroup(IGroupShape groupShape)
Parameters
Type | Name | Description |
---|---|---|
IGroupShape | groupShape | Group shape to ungroup. |
Examples
The following code illustrates how to ungroup a specified IGroupShape.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("GroupShapes.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IShapes shapes = worksheet.Shapes;
// Ungroup the group shape.
shapes.Ungroup(shapes[0] as IGroupShape);
//Save and dispose
workbook.SaveAs("GroupShapes.xlsx");
workbook.Close();
}
Ungroup(IGroupShape, Boolean)
Ungroup the group shape and its inner shapes.
Declaration
void Ungroup(IGroupShape groupShape, bool isAll)
Parameters
Type | Name | Description |
---|---|---|
IGroupShape | groupShape | Group shape to ungroup. |
System.Boolean | isAll | Boolean value which indicates whether the inner shapes will be ungrouped. |
Examples
The following code illustrates how to ungroup a specified IGroupShape.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Open("GroupShapes.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IShapes shapes = worksheet.Shapes;
// Ungroup the group shape and its inner shapes.
shapes.Ungroup(shapes[0] as IGroupShape, true);
//Save and dispose
workbook.SaveAs("GroupShapes.xlsx");
workbook.Close();
}