// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.getRange("F7:G8").getInterior().setColor(Color.FromArgb(59, 92, 170)); worksheet.getRange("F7:G8").getFont().setColor(Color.GetWhite()); worksheet.getRange("F7").setValue("Input:"); worksheet.getRange("G7").setValue(300); worksheet.getRange("F8").setValue("Output:"); worksheet.getRange("G8").setFormula("=IF(G7<=250, \"A result\", \"B result\")"); worksheet.getRange("H8").setValue("=IF(G7<=250, \"A result\", \"B result\")"); worksheet.getRange("H8").getFont().setColor(Color.GetRed()); IShape shapeStart = worksheet.getShapes().addShape(AutoShapeType.Rectangle, worksheet.getRange("B3:D4")); shapeStart.getTextFrame().getTextRange().setText("Start"); shapeStart.getTextFrame().setVerticalAnchor(VerticalAnchor.AnchorMiddle); shapeStart.getTextFrame().setHorizontalAnchor(HorizontalAnchor.Center); // set shape formula to G8 IShape shapeResult = worksheet.getShapes().addShape(AutoShapeType.Rectangle, worksheet.getRange("B7:D8")); shapeResult.setFormula("=G8"); shapeResult.getTextFrame().setVerticalAnchor(VerticalAnchor.AnchorMiddle); shapeResult.getTextFrame().setHorizontalAnchor(HorizontalAnchor.Center); double startX = shapeStart.getLeftInPixel() + shapeStart.getWidthInPixel() / 2; double startY = shapeStart.getTopInPixel() + shapeStart.getHeightInPixel(); double endX = shapeResult.getLeftInPixel() + shapeResult.getWidthInPixel() / 2; double endY = shapeResult.getTopInPixel(); IShape connector = worksheet.getShapes().addConnectorInPixel(ConnectorType.Straight, (float)(startX), (float)(startY), (float)(endX), (float)(endY)); connector.getLine().setEndArrowheadStyle(ArrowheadStyle.Triangle); // Save to an excel file workbook.save("SetShapeFormula.xlsx");