We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Grouping charts and shapes in Excel file using Aspose.Cells for .NET in C#

I’ve seen an example of how to group shapes as below:

//define the shapes
Aspose.Cells.Drawing.RectangleShape shape1
Aspose.Cells.Drawing.RectangleShape shapeN

//get the shapes
Aspose.Cells.Drawing.Shape[] shapeObjects = new Aspose.Cells.Drawing.Shape[] {shape1, shapeN};

//group the shapes.
Aspose.Cells.Drawing.GroupShape group = excelbook.Worksheets[0].Shapes.Group(shapeObjects);

What I’m wondering is can I group charts and shapes together?



Thanks for your query with sample code snippet.

See the following sample code for your reference:
Sample code:

//Instantiate a
new Workbook.<o:p></o:p>

Workbook excelbook = new Workbook("e:\\test2\\Bk_groupsh1.xlsx");


//Get the first rectangle shape.

Aspose.Cells.Drawing.RectangleShape rectangle1 = (Aspose.Cells.Drawing.RectangleShape)excelbook.Worksheets[0].Shapes[0];

//Get the second oval shape.

Aspose.Cells.Drawing.Oval oval1 = (Aspose.Cells.Drawing.Oval)excelbook.Worksheets[0].Shapes[1];

//Get the third chart shape.

Aspose.Cells.Drawing.ChartShape chart1 = (Aspose.Cells.Drawing.ChartShape)excelbook.Worksheets[0].Shapes[2];

//Get the shapes.

Aspose.Cells.Drawing.Shape[] shapeobjects = new Aspose.Cells.Drawing.Shape[] { rectangle1, oval1, chart1 };

//Group the shapes.

Aspose.Cells.Drawing.GroupShape group = excelbook.Worksheets[0].Shapes.Group(shapeobjects);

group.Placement = PlacementType.FreeFloating;

//Save the excel file.


Let us know if you still have any issue.

Thank you.