
These act as margins from worksheet's respective edges, with being the upper-left corner. Their placement is defined by the left and top property. nnectEndShape(shapes.getItem("RightShape"), 3) nnectBeginShape(shapes.getItem("LeftShape"), 0) Let line = shapes.getItem("MyLine").line This sample connects a line between two shapes at connection points '0' and '3'.
#HOW TO ADD SHAPES IN EXCEL CODE#
The following code sample connects the "MyLine" line to two shapes named "LeftShape" and "RightShape". A line is disconnected from any attached shapes using the disconnectBeginShape and disconnectEndShape methods. The locations of these points vary by shape, but the nnectionSiteCount can be used to ensure your add-in does not connect to a point that's out-of-bounds. The connectBeginShape and connectEndShape methods attach the beginning and ending of a line to shapes at the specified connection points. Lines can be connected to other Shape objects. This sample creates a straight line from to on the worksheet.

The following code sample creates a straight line on the worksheet. It also takes a ConnectorType enum to specify how the line contorts between endpoints. That method needs the left and top margins of the line's start and end points. Let image = (myBase64) Ī line is created with ShapeCollection.addLine. Let myBase64 = ().substr(startIndex + 7) Let myFile = document.getElementById("selectedFile") This sample creates an image as a Shape object in the worksheet. The string has the metadata "base64," removed before the shape is created. The following code sample shows an image file being loaded by a FileReader as a string. ShapeCollection.addSvg also takes in a string, though this argument is XML that defines the graphic. This is either a JPEG or PNG image in string form. The ShapeCollection.addImage method takes a base64-encoded string as an argument. JPEG, PNG, and SVG images can be inserted into a worksheet as shapes. Let rectangle = shapes.addGeometricShape() of the worksheet and is 150x150 pixels. This sample creates a rectangle positioned 100 pixels from the top and left sides

The following code sample creates a 150x150-pixel rectangle named "Square" that is positioned 100 pixels from the top and left sides of the worksheet. That method takes a GeometricShapeType enum as an argument.

ShapeĪddGeometricShape(geometricShapeType: Excel.GeometricShapeType): Excel.ShapeĪddImage(base64ImageString: string): Excel.ShapeĪddLine(startLeft: number, startTop: number, endLeft: number, endTop: number, connectorType?: Excel.ConnectorType): Excel.ShapeĪ geometric shape is created with ShapeCollection.addGeometricShape. The following types of shapes are added using the associated method. name can be set by your add-in for easy retrieval with the ShapeCollection.getItem(name) method. These are the name and id properties, respectively.

All shapes have names and IDs generated for them when they are added to the collection. Shapes are created through and stored in a worksheet's shape collection ( Worksheet.shapes). The following image shows shapes which form a thermometer. Charts are covered in their own article, Work with charts using the Excel JavaScript API.
#HOW TO ADD SHAPES IN EXCEL HOW TO#
This article describes how to use geometric shapes, lines, and images in conjunction with the Shape and ShapeCollection APIs. That means anything outside of a cell is a shape. Excel defines shapes as any object that sits on the drawing layer of Excel.
