//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["F7:G8"].Interior.Color = Color.FromArgb(59, 92, 170); worksheet.Range["F7:G8"].Font.Color = Color.White; worksheet.Range["F7"].Value = "Input:"; worksheet.Range["G7"].Value = 300; worksheet.Range["F8"].Value = "Output:"; worksheet.Range["G8"].Formula = "=IF(G7<=250, \"A result\", \"B result\")"; worksheet.Range["H8"].Value = "=IF(G7<=250, \"A result\", \"B result\")"; worksheet.Range["H8"].Font.Color = Color.Red; IShape shapeStart = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["B3:D4"]); shapeStart.TextFrame.TextRange.Text = "Start"; shapeStart.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle; shapeStart.TextFrame.HorizontalAnchor = HorizontalAnchor.Center; // set shape formula to G8 IShape shapeResult = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range["B7:D8"]); shapeResult.Formula = "=G8"; shapeResult.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle; shapeResult.TextFrame.HorizontalAnchor = HorizontalAnchor.Center; double startX = shapeStart.LeftInPixel + shapeStart.WidthInPixel / 2; double startY = shapeStart.TopInPixel + shapeStart.HeightInPixel; double endX = shapeResult.LeftInPixel + shapeResult.WidthInPixel / 2; double endY = shapeResult.TopInPixel; IShape connector = worksheet.Shapes.AddConnectorInPixel(ConnectorType.Straight, startX, startY, endX, endY); connector.Line.EndArrowheadStyle = ArrowheadStyle.Triangle;
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("F7:G8").Interior.Color = Color.FromArgb(59, 92, 170) worksheet.Range("F7:G8").Font.Color = Color.White worksheet.Range("F7").Value = "Input:" worksheet.Range("G7").Value = 300 worksheet.Range("F8").Value = "Output:" worksheet.Range("G8").Formula = "=IF(G7<=250, ""A result"", ""B result"")" worksheet.Range("H8").Value = "=IF(G7<=250, ""A result"", ""B result"")" worksheet.Range("H8").Font.Color = Color.Red Dim shapeStart = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range("B3:D4")) shapeStart.TextFrame.TextRange.Text = "Start" shapeStart.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle shapeStart.TextFrame.HorizontalAnchor = HorizontalAnchor.Center ' set shape formula to G8 Dim shapeResult = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, worksheet.Range("B7:D8")) shapeResult.Formula = "=G8" shapeResult.TextFrame.VerticalAnchor = VerticalAnchor.AnchorMiddle shapeResult.TextFrame.HorizontalAnchor = HorizontalAnchor.Center Dim startX = shapeStart.LeftInPixel + shapeStart.WidthInPixel / 2 Dim startY = shapeStart.TopInPixel + shapeStart.HeightInPixel Dim endX = shapeResult.LeftInPixel + shapeResult.WidthInPixel / 2 Dim endY = shapeResult.TopInPixel Dim connector = worksheet.Shapes.AddConnectorInPixel(ConnectorType.Straight, startX, startY, endX, endY) connector.Line.EndArrowheadStyle = ArrowheadStyle.Triangle ' save to an excel file workbook.Save("SetShapeFormula.xlsx")