alexa
menu

MAUI

  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Search Results for

    Show / Hide Table of Contents

    Interface IShapes

    Represents shapes collection in the workbook.

    Inherited Members
    IEnumerable.GetEnumerator()
    IParentApplication.Application
    IParentApplication.Parent
    Namespace: Syncfusion.XlsIO
    Assembly: Syncfusion.XlsIO.NET.dll
    Syntax
    public interface IShapes : IParentApplication, IEnumerable

    Properties

    Count

    Returns the number of IShape objects in the IShapes collection. Read-only Long.

    Declaration
    int Count { get; }
    Property Value
    Type
    int
    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

    this[int]

    Returns single IShape from the IShapes collection by its index.

    Declaration
    IShape this[int index] { get; }
    Parameters
    Type Name Description
    int 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();
    }

    this[string]

    Returns single IShape from the IShapes collection by its name or null when cannot find. Read-only.

    Declaration
    IShape this[string strShapeName] { get; }
    Parameters
    Type Name Description
    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, int, int, int, int)

    Adds new IShape to the IShapes collection

    Declaration
    IShape AddAutoShapes(AutoShapeType autoShapeType, int topRow, int leftColumn, int height, int width)
    Parameters
    Type Name Description
    AutoShapeType autoShapeType

    AutoShape type

    int topRow

    One-based index of the top row of the shape to be placed.

    int leftColumn

    One-based index of the left column of the shape to be placed.

    int height

    Height of the auto shapes.

    int 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
    string commentText

    Text of the comment.

    Returns
    Type Description
    ICommentShape

    Newly added shape.

    AddComment(string, bool)

    Adds new Comment shape to the collection.

    Declaration
    ICommentShape AddComment(string commentText, bool bIsParseOptions)
    Parameters
    Type Name Description
    string commentText

    Text of the comment.

    bool 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<int>)

    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.

    Dictionary<string, string> hashNewNames

    Dictionary with new names of worksheets.

    List<int> 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.

    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, bool)

    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.

    bool 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();
    }
    In this article
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved