Insert Shapes and Images
| API | Description | Example |
|---|---|---|
| Worksheet.Shapes | Property that returns the shape and image management object within the sheet | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; |
| Shapes.Count | Property that returns the number of shapes | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; console.log(shapes.Count); |
| Shapes.AddPicture | Function that adds an image | let 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.AddShape | Function that adds a shape | let 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.AutoShapeType | Property that returns or changes the type of the shape | let 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.BottomRightCell | Property that returns a range object corresponding to the bottom-right cell of the shape | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; let shape = shapes.Item(1); let cell = shape.BottomRightCell; |
| Shape.Fill | Property that returns the fill format object of the shape | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; let shape = shapes.Item(1); let fillFormat = shape.Fill; |
| FillFormat.ForeColor | Property that returns an object that manages the foreground color of 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; let colorFormat = fillFormat.ForeColor; |
| ColorFormat.Brightness | Property that returns or changes the brightness of the color format | 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.Brightness); colorFormat.Brightness = 0.5; |
| ColorFormat.ObjectThemeColor | Property that returns or changes the theme color of the color format | 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.ObjectThemeColor); colorFormat.ObjectThemeColor = instance.Enums.MsoThemeColorIndex.msoThemeColorAccent1; |
| ColorFormat.RGB | Property 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.SchemeColor | Property that returns or changes the scheme color of the color format | 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.SchemeColor); colorFormat.SchemeColor = 3; |
| ColorFormat.TintAndShade | Property that returns or changes the brightness of the color format | 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.TintAndShade); colorFormat.TintAndShade = 0.3; |
| ColorFormat.Type | Property that returns the type of the color format | 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.Type); |
| FillFormat.Pattern | Property that returns the pattern type of 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; console.log(fillFormat.Pattern); |
| FillFormat.RotateWithObject | Property that returns or changes whether the fill format should rotate with the object | let 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.Transparency | Property that returns or changes the transparency of 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; console.log(fillFormat.Transparency); fillFormat.Transparency = 0.5; |
| FillFormat.Type | Property that returns the type of 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; console.log(fillFormat.Type); |
| FillFormat.Visible | Property that returns or changes the visibility state of 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; console.log(fillFormat.Visible); fillFormat.Visible = instance.Enums.MsoTriState.msoTrue; |
| FillFormat.Patterned | Function 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.Solid | Function 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.TwoColorGradient | Function 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.Height | Property that returns or changes the height of the shape | let 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.HorizontalFlip | Returns 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.ID | Property that returns the ID of the shape | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; let shape = shapes.Item(1); console.log(shape.ID); |
| Shape.Left | An 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.Name | Property that returns or changes the name of the shape | let 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.Placement | An 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.Rotation | An 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.Title | Property that returns or changes the title of the shape | let 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.Top | An 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.TopLeftCell | An 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.VerticalFlip | An 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.Visible | An 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.Width | Property that returns or changes the width of the shape | let 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.ZOrderPosition | An 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.Delete | Function that removes the shape | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; let shape = shapes.Item(1); shape.Delete(); |
| Shape.Duplicate | Function that duplicates the shape | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; let shape = shapes.Item(1); let duplicate = shape.Duplicate(); |
| Shape.ExportAsImage | Function 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.Flip | Function 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.IncrementLeft | Function 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.IncrementRotation | Function 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.IncrementTop | Function 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.Select | Function that processes the shape as selected | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; let shape = shapes.Item(1); shape.Select(); |
| Shape.ZOrder | Function 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.Item | Function that returns a shape object at a specific index | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; let shape = shapes.Item(1); |
| Shapes.SelectAll | All functions that process the shape as selected | let workbook = instance.Application.ActiveWorkbook; let activeSheet = workbook.ActiveSheet; let shapes = activeSheet.Shapes; shapes.SelectAll(); |
Related Features
Visualization Tools , Chart Creation and Editing , Sparklines