How can I add line and connect two simple image using Aspose.Cells for Java?

How can I add line and connect two simple image using Aspose.Cells for Java?
For Example :
Screenshot 2026-02-13 104948.jpg (8.8 KB)

@hklee70
Hi,
You can refer to the following code to achieve your expected result. For more types, please refer to: AutoShapeType | Aspose.Cells for Java API Reference

1 Calculation via existing API

Workbook workbook = new Workbook();
ShapeCollection shapes = workbook.getWorksheets().get(0).getShapes();

// Insert rectangle
Shape shape = shapes.addAutoShape(AutoShapeType.RECTANGLE, 1, 0, 1, 0, 100, 100);
float[][] points = shape.getConnectionPoints();
float x1 = shape.getX() + points[3][0];
float y1 = shape.getY() + points[3][1];

// Insert diamond
shape = shapes.addAutoShape(AutoShapeType.DIAMOND, 7, 30, 3, 0, 100, 100);
points = shape.getConnectionPoints();
float x2 = shape.getX() + points[0][0];
float y2 = shape.getY() + points[0][1];

// Insert connecting wire
shape = shapes.addAutoShape(AutoShapeType.BENT_CONNECTOR_2, 1, 0, 1, 0, 0, 0);
shape.setX((int)x1);
shape.setY((int)y1);
shape.setWidth((int)(x2 - x1));
shape.setHeight((int)(y2 - y1));
shape.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW);
workbook.save("result.xlsx");

2 Calculate it entirely yourself

Workbook workbook = new Workbook();
ShapeCollection shapes = workbook.getWorksheets().get(0).getShapes();

// Insert rectangle
Shape shape = shapes.addAutoShape(AutoShapeType.RECTANGLE, 1, 0, 1, 0, 100, 100);

// Insert connecting wire
float dx = shape.getX() + shape.getWidth();
float dy = shape.getY() + shape.getHeight() / 2;
shape = shapes.addAutoShape(AutoShapeType.BENT_CONNECTOR_2, 1, 0, 1, 0, 100, 100);
shape.setX((int)dx);
shape.setY((int)dy);
shape.getLine().setEndArrowheadStyle(MsoArrowheadStyle.ARROW);

// Insert diamond
dx = shape.getX() + shape.getWidth();
dy = shape.getY() + shape.getHeight();
shape = shapes.addAutoShape(AutoShapeType.DIAMOND, 1, 0, 1, 0, 100, 100);
shape.setX((int)(dx - shape.getWidth() / 2));
shape.setY((int)dy);

workbook.save("result.xlsx");
1 Like