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

Free Support Forum - aspose.com

Insert and manipulate basic shapes in Excel

dear support,

thank you for this great product.

Question. Can Aspose.cells add shapes ( eg a circle ) in a spreadsheet, place them in the spreadsheer, modify properties ( such as colors and text ) and add connectors between various shapes ?

I have appended a spreadsheet with what i want to achieve.

Thanks for your feedback.

guido

Hi,


Thanks for your sample file.

Please see the document on how to create different drawing objects and controls using Aspose.Cells APIs, so you could create your desired shapes accordingly:

I have written a sample code for your reference on how to create a circle (oval shape) and connector, you may refer to it and create your desired controls accordingly:

e.g
Sample code:

  //Instantiate a new Workbook.
            Workbook excelbook = new Workbook();

            //Add another oval (circle) shape.
            Aspose.Cells.Drawing.Oval oval2 = excelbook.Worksheets[0].Shapes.AddOval(11, 0, 4, 17, 40, 40);

            //Set the placement of the oval.
            oval2.Placement = PlacementType.FreeFloating;

            //Set the line style.
            oval2.LineFormat.Style = MsoLineStyle.Single;

            oval2.FillFormat.ForeColor = Color.LightBlue;

            //Set the line weight.
            oval2.LineFormat.Weight = 2;

            //Set the color of the oval line.
            oval2.LineFormat.ForeColor = Color.Blue;

            //Set the dash style of the oval.
            oval2.LineFormat.DashStyle = MsoLineDashStyle.Solid;

            //Add a line to the worksheet
            Aspose.Cells.Drawing.LineShape line2 = excelbook.Worksheets[0].Shapes.AddLine(9, 0, 2, 0, 45, 150);

            //Set the line color
            line2.LineFormat.ForeColor = Color.Blue;

            //Set the line style.
            line2.LineFormat.DashStyle = MsoLineDashStyle.Solid;

            //Set the weight of the line.
            line2.LineFormat.Weight = 1;

            //Set the placement.
            line2.Placement = PlacementType.FreeFloating;

            //Set the line arrows.
            line2.EndArrowheadWidth = MsoArrowheadWidth.Narrow;
            line2.EndArrowheadStyle = MsoArrowheadStyle.Arrow;
            line2.EndArrowheadLength = MsoArrowheadLength.Short;

            // line2.BeginArrowheadStyle = MsoArrowheadStyle.Arrow;
           // line2.BeginArrowheadLength = MsoArrowheadLength.Medium;



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

Thank you.

thanks for your suggested code.


However, it seems to me the command AddLine creates a line in Excel, and not a connector.
I have not found any support for a connector ? Or am i wrong ?

guido

Hi,


Well, my code will create an arrow line basically, there is no support to create connectors directly so you have to use Aspose.Cells APIs to create shapes (e.g Arrow line, ovals etc.) for your needs.

Please run my sample code and get the output file and review/ check the output shapes for your reference.

Thank you.

thanks for your code.

is there any support for connectors planned ?

Thank you

guido

Hi,


Please try the following sample code for your reference on how to create different shapes including connectors with latest version/fix:
e.g
Sample code:

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
ShapeCollection shapes = sheet.Shapes;
Shape shape = shapes.AddAutoShape(AutoShapeType.StraightConnector, 1, 0, 3, 0, 50, 50);
workbook.Save(“e:\test2\outputconnect2.xlsx”);

Thank you.

ok, thank you.


Great functionality - thnaks for teh code - you’re too kind.

I see now how to add a connector.

But how do you connect the connector to one of the 9 connection points in a circle ??

guido

Hi,


Well, there may not be a defined rule to do that as you have to use your own codes to try to create circles and line connectors to accomplish your tasks. Also could you explain which 9 connection points you are talking about, we may check it soon.

Thank you.

I think you are missing the point.


Just like in Visio, Excel offers the possibility to connect shapes together, If you move the source or destination, the connected connector moves along. Excel offer straight, elbow and curved connectors.

Each shape has different connection points onto which the connector can connect. For a circle, there are 8 connection points ( and not 9 as i said before ). I believe a triangle only has 6 connection points.

I have attached a sheet with some shapes connected together through connectors.

I worked with Aspose.Diagram before. There is support for this inside this module.

I believe this would be a great feature for aspose.cells ( and I would benefit from it in my project ).

guido


Hi,


Thanks for the sample file.

We observed and understand you now. Well, it looks like a new feature (i.e. “If you move the source or destination, the connected connector moves along. Excel offer straight, elbow and curved connectors”). We may log a ticket into our database and look into it. Could you also provide more details and steps involved on how to create shapes that are connected by connectors which are bound to them.

Thank you.

I guess you will need to extend the aspose.cells.drawing.shape class with the notion of connector points.



Hi,


Thanks for your suggestion.

We will investigate it if we could enhance the Aspose.Cells.Drawing.Shape class or include some relevant APIs to support your needs or even provide some workaround with the current set of APIs. I have logged an investigation ticket with an id “CELLSNET-42486” into our database for your issue/ needs. We will analyze it and look into it soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi Amjad,


can you please give me an update of the ticket CELLSNET-42486? I am interested too in this functionality.

Thanks,
Jens

Hi,


I have checked the status of the ticket logged as “CELLSNET-42486” into our database, I am afraid, it is not resolved yet. I have asked the relevant developer to update on it (if possible).

Once we have any update on it, we will let you know here.

Thank you.

Hi Amjad,


any news?

Thanks,
Jens

Hi,


I am afraid, there is still no update on it. Probably, we could not get enough time to look into it thoroughly due to other priority tasks and busy schedule. I have again asked the relevant developer to update on it.
Once we have any update on it, we will let you know here.

Sorry for any inconvenience caused!