Excel shapes

A worksheet can contain various kinds of ExcelShape objects. A shape has some kind of geometry and can have ExcelShape.Fill and/or ExcelShape.Outline.

The text content of a shape is currently supported only through preservation.

The following example shows how you can create and customize shapes and add them to a worksheet using various types of positioning.

Excel shapes added with GemBox.Spreadsheet
Screenshot of Excel shapes added with GemBox.Spreadsheet
using GemBox.Spreadsheet;
using GemBox.Spreadsheet.Drawing;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var workbook = new ExcelFile();
        var worksheet = workbook.Worksheets.Add("Shapes");

        var shape = worksheet.Shapes.Add(%ShapeType%, 100, 100, 200, 150, LengthUnit.Point);
        shape.Fill.SetSolid(DrawingColor.FromName(DrawingColorName.GreenYellow));
        shape.Outline.Fill.SetSolid(DrawingColor.FromName(DrawingColorName.DarkBlue));
        shape.Outline.Width = Length.From(3, LengthUnit.Point);

        var roundedRectangle = worksheet.Shapes.Add(ShapeType.RoundedRectangle, "B2", "D4");
        // Radius of the corners is 35% of the rounded rectangle height (since it is smaller than width).
        roundedRectangle.AdjustValues["adj"] = 35000;

        var rightArrow = worksheet.Shapes.Add(ShapeType.RightArrow, "B6", 100, 40, LengthUnit.Point);
        rightArrow.Fill.SetNone();
        rightArrow.Outline.Fill.SetSolid(DrawingColor.FromRgb(250, 30, 20));
        rightArrow.Outline.Width = Length.From(2, LengthUnit.Point);

        var line = worksheet.Shapes.Add(ShapeType.Line, "B12", "B15");
        line.Outline.Width = Length.From(10, LengthUnit.Pixel);

        worksheet.PrintOptions.PrintGridlines = true;
        worksheet.PrintOptions.PrintHeadings = true;

        workbook.Save("Shapes.%OutputFileType%");
    }
}
Imports GemBox.Spreadsheet
Imports GemBox.Spreadsheet.Drawing

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim workbook = new ExcelFile
        Dim worksheet = workbook.Worksheets.Add("Shapes")

        Dim shape = worksheet.Shapes.Add(%ShapeType%, 100, 100, 200, 150, LengthUnit.Point)
        shape.Fill.SetSolid(DrawingColor.FromName(DrawingColorName.GreenYellow))
        shape.Outline.Fill.SetSolid(DrawingColor.FromName(DrawingColorName.DarkBlue))
        shape.Outline.Width = Length.From(3, LengthUnit.Point)

        Dim roundedRectangle = worksheet.Shapes.Add(ShapeType.RoundedRectangle, "B2", "D4")
        ' Radius of the corners is 35% of the rounded rectangle height (since it is smaller than width).
        roundedRectangle.AdjustValues.Add("adj", 35000)

        Dim rightArrow = worksheet.Shapes.Add(ShapeType.RightArrow, "B6", 100, 40, LengthUnit.Point)
        rightArrow.Fill.SetNone()
        rightArrow.Outline.Fill.SetSolid(DrawingColor.FromRgb(250, 30, 20))
        rightArrow.Outline.Width = Length.From(2, LengthUnit.Point)

        Dim line = worksheet.Shapes.Add(ShapeType.Line, "B12", "B15")
        line.Outline.Width = Length.From(10, LengthUnit.Pixel)

        worksheet.PrintOptions.PrintGridlines = true
        worksheet.PrintOptions.PrintHeadings = true

        workbook.Save("Shapes.%OutputFileType%")
    End Sub
End Module

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Spreadsheet yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.