Hi, Yegor
This is my code:
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Connect two shapes");
XSSFDrawing patriarch = (XSSFDrawing)
sheet.createDrawingPatriarch();
// Initialize first shape
XSSFClientAnchor a = new XSSFClientAnchor(152400, 123825,
542925, 57150,
1, 4, 3, 11);
XSSFSimpleShape clould = patriarch.createSimpleShape(a);
clould.setShapeType(ShapeTypes.CLOUD);
clould.getCTShape().getNvSpPr().getCNvPr().setId(2);
// Initialize second shape
XSSFClientAnchor a2 = new XSSFClientAnchor(104775, 9525,
190500, 28575, 8,
13, 11, 19);
XSSFSimpleShape rect = patriarch.createSimpleShape(a2);
rect.getCTShape().getNvSpPr().getCNvPr().setId(3);
rect.setShapeType(ShapeTypes.RECT);
// Initialize connector between shapes
XSSFConnector shape1Connector = patriarch.createConnector(
new XSSFClientAnchor(541584, 185738, 452438,
9525, 3, 7, 9, 13));
*// When I set id of the connector everything works
correctly. Here is my problem.
//shape1Connector.getCTConnector().getNvCxnSpPr().getCNvPr().setId(45);*
CTConnector ctConnector = shape1Connector.getCTConnector();
ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.STRAIGHT_CONNECTOR_1);
CTNonVisualConnectorProperties cx =
ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
CTConnection stCxn = cx.addNewStCxn();
stCxn.setId(clould.getCTShape().getNvSpPr().getCNvPr().getId());
stCxn.setIdx(0);
CTConnection end = cx.addNewEndCxn();
end.setId(rect.getCTShape().getNvSpPr().getCNvPr().getId());
end.setIdx(3);
FileOutputStream fileOut;
try {
fileOut = new
FileOutputStream("xls/XLDrawingShape.xlsx");
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
I missed explanation about how the code is work. I hope you will understand
it. If you don't, please write me. Thank you in advance.
Regards,
Stefan
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/How-to-add-connector-between-two-shapes-in-Excel-tp5711187p5711266.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]