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

Free Support Forum - aspose.com

How to group objects in Aspose.cell

Hi,

I am trying to group images and changing property setting using Aspose. Please find the screen shot of the steps we perform in excel.

Please let me know if it is possible to group multiple images into single object.

-Aniket

Hi,


It is very simple to group shapes in the worksheet, see the sample code on how to group the shapes. I used a simple template file that I created in MS Excel manually, I inserted a rectangle shape and a picture on the first worksheet in the workbook. I grouped the shapes and saved the file.
e.g
Sample code:

//Instantiate a new Workbook.
Workbook excelbook = new Workbook(“e:\test2\Bk_groupshapes1.xlsx”);


Aspose.Cells.Drawing.Picture pic = (Aspose.Cells.Drawing.Picture)excelbook.Worksheets[0].Shapes[“Picture 2”];

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

//Get the shapes.
Aspose.Cells.Drawing.Shape[] shapeobjects = new Aspose.Cells.Drawing.Shape[] {pic, rectangle1};

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

//Save the excel file.
excelbook.Save(“e:\test2\outgroupshapes1.xlsx”);

I have also attached the template file for your reference.

Let us know if I can be of any further help.

Thank you.



Hi Amjad,

Thanks for the reply.

I still see in the file provided by you that the rectangle and image are separate and not part of the single group.

Also how to make sure that the resulting single object position property is set to "Don't move or size with cells".

Attach the snapshot of what is currently displayed in your file and what we intend to see...

-Aniket

Hi,


I used the following sample code and it works fine, see the sample screen shot attached taken in MS Excel here:
http://prntscr.com/517mvm
(You can see the it groups the shapes and “Don’t move or size with cells” option is selected)
e.g
Sample code:

//Instantiate a new Workbook.
Workbook excelbook = new Workbook(“e:\test2\Bk_groupshapes1.xlsx”);

Aspose.Cells.Drawing.Picture pic = (Aspose.Cells.Drawing.Picture)excelbook.Worksheets[0].Shapes[“Picture 2”];


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

//Get the shapes.
Aspose.Cells.Drawing.Shape[] shapeobjects = new Aspose.Cells.Drawing.Shape[] {pic, rectangle1};

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

group.Placement = PlacementType.FreeFloating;

//Save the excel file.
excelbook.Save(“e:\test2\outgroupshapes1.xlsx”);



Thank you.