Skip to main content

Insert Shapes and Images

APIDescriptionExample
Worksheet.ShapesProperty that returns the shape and image management object within the sheetlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;

let shapes = activeSheet.Shapes;
Shapes.CountProperty that returns the number of shapeslet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;

console.log(shapes.Count);
Shapes.AddPictureFunction that adds an imagelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let msotrue = instance.Enums.MsoTriState.msoTrue;

let shape = shapes.AddPicture("/hnc/File/Picture.png", msotrue, msotrue, 0, 0, 100, 100);
Shapes.AddShapeFunction that adds a shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;

let shape = shapes.AddShape(instance.Enums.MsoAutoShapeType.msoShapeRectangle, 0, 0, 100, 100);
Shape.AutoShapeTypeProperty that returns or changes the type of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.AutoShapeType);
shape.AutoShapeType = instance.Enums.MsoAutoShapeType.msoShapeRectangle;
Shape.BottomRightCellProperty that returns a range object corresponding to the bottom-right cell of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

let cell = shape.BottomRightCell;
Shape.FillProperty that returns the fill format object of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

let fillFormat = shape.Fill;
FillFormat.ForeColorProperty that returns an object that manages the foreground color of the fill formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

let colorFormat = fillFormat.ForeColor;
ColorFormat.BrightnessProperty that returns or changes the brightness of the color formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;
let colorFormat = fillFormat.ForeColor;

console.log(colorFormat.Brightness);
colorFormat.Brightness = 0.5;
ColorFormat.ObjectThemeColorProperty that returns or changes the theme color of the color formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;
let colorFormat = fillFormat.ForeColor;

console.log(colorFormat.ObjectThemeColor);
colorFormat.ObjectThemeColor = instance.Enums.MsoThemeColorIndex.msoThemeColorAccent1;
ColorFormat.RGBProperty that returns or changes the color of the color format
Note: RGB numeric value corresponding to the color must be used
function RGBToInteger(rgbText) {
const [r,g,b] = rgbText.match(/\d+/g).map(Number);
return r + g * 256 + b * 65536;
}

let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;
let colorFormat = fillFormat.ForeColor;

console.log(colorFormat.RGB);
colorFormat.RGB = RGBToInteger("RGB(255,199,206)");
ColorFormat.SchemeColorProperty that returns or changes the scheme color of the color formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;
let colorFormat = fillFormat.ForeColor;

console.log(colorFormat.SchemeColor);
colorFormat.SchemeColor = 3;
ColorFormat.TintAndShadeProperty that returns or changes the brightness of the color formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;
let colorFormat = fillFormat.ForeColor;

console.log(colorFormat.TintAndShade);
colorFormat.TintAndShade = 0.3;
ColorFormat.TypeProperty that returns the type of the color formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;
let colorFormat = fillFormat.ForeColor;

console.log(colorFormat.Type);
FillFormat.PatternProperty that returns the pattern type of the fill formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

console.log(fillFormat.Pattern);
FillFormat.RotateWithObjectProperty that returns or changes whether the fill format should rotate with the objectlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

console.log(fillFormat.RotateWithObject);
fillFormat.RotateWithObject = instance.Enums.MsoTriState.msoFalse;
FillFormat.TransparencyProperty that returns or changes the transparency of the fill formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

console.log(fillFormat.Transparency);
fillFormat.Transparency = 0.5;
FillFormat.TypeProperty that returns the type of the fill formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

console.log(fillFormat.Type);
FillFormat.VisibleProperty that returns or changes the visibility state of the fill formatlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

console.log(fillFormat.Visible);
fillFormat.Visible = instance.Enums.MsoTriState.msoTrue;
FillFormat.PatternedFunction to apply a pattern to the fill format.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

fillFormat.Patterned(instance.Enums.MsoPatternType.msoPattern5Percent);
FillFormat.SolidFunction to apply a solid color to the fill format.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

fillFormat.Solid();
FillFormat.TwoColorGradientFunction to apply a gradation to the fill format.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);
let fillFormat = shape.Fill;

fillFormat.TwoColorGradient(instance.Enums.MsoGradientStyle.msoGradientHorizontal, 1);
Shape.HeightProperty that returns or changes the height of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Height);
shape.Height = 100;
Shape.HorizontalFlipReturns an attribute that indicates whether the shape is flipped horizontally.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.HorizontalFlip);
Shape.IDProperty that returns the ID of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.ID);
Shape.LeftAn attribute that returns or changes the shape's X coordinate.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Left);
shape.Left = 100;
Shape.NameProperty that returns or changes the name of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Name);
shape.Name = "Rectangle 1";
Shape.PlacementAn attribute that returns or changes the way a shape is linked to the cell below it.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Placement);
shape.Placement = instance.Enums.XlPlacement.xlMoveAndSize;
Shape.RotationAn attribute that returns or changes the shape's rotation value.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Rotation);
shape.Rotation = 90;
Shape.TitleProperty that returns or changes the title of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Title);
shape.Title = "Shape Title";
Shape.TopAn attribute that returns or changes the shape's Y coordinate.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Top);
shape.Top = 100;
Shape.TopLeftCellAn attribute that returns the range object corresponding to the shape's top-left cell.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

let cell = shape.TopLeftCell
Shape.VerticalFlipAn attribute that returns whether the shape is flipped vertically.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.VerticalFlip);
Shape.VisibleAn attribute that returns or changes the shape's display status.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Visible);
shape.Visible = instance.Enums.MsoTriState.msoTrue;
Shape.WidthProperty that returns or changes the width of the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.Width);
shape.Width = 100;
Shape.ZOrderPositionAn attribute that returns the shape's Z-Order.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

console.log(shape.ZOrderPosition);
Shape.DeleteFunction that removes the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

shape.Delete();
Shape.DuplicateFunction that duplicates the shapelet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

let duplicate = shape.Duplicate();
Shape.ExportAsImageFunction that returns the shape as a Base64 encoded image.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

let base64 = shape.ExportAsImage();
Shape.FlipFunction that flips the shape.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

shape.Flip(instance.Enums.MsoFlipCmd.msoFlipVertical);
Shape.IncrementLeftFunction that changes the shape's X coordinate.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

shape.IncrementLeft(-50);
shape.IncrementLeft(100);
Shape.IncrementRotationFunction that changes the shape's rotation value.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

shape.IncrementRotation(-90);
shape.IncrementRotation(30);
Shape.IncrementTopFunction that changes the shape's Y coordinate.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

shape.IncrementTop(-50);
shape.IncrementTop(100);
Shape.SelectFunction that processes the shape as selectedlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

shape.Select();
Shape.ZOrderFunction that changes the shape's Z-Order.let workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;
let shape = shapes.Item(1);

shape.ZOrder(instance.Enums.MsoZOrderCmd.msoBringToFront);
Shapes.ItemFunction that returns a shape object at a specific indexlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;

let shape = shapes.Item(1);
Shapes.SelectAllAll functions that process the shape as selectedlet workbook = instance.Application.ActiveWorkbook;
let activeSheet = workbook.ActiveSheet;
let shapes = activeSheet.Shapes;

shapes.SelectAll();

Visualization Tools , Chart Creation and Editing , Sparklines