[]
IContainerIBackgroundPictureAn IShape is a member of the IShapes collection and provides the common shape API for positioning, sizing, grouping, formatting, and accessing specialized shape features such as charts, controls, and connectors.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 10, 10, 120, 60);
shape.setName("SalesBox");
shape.setRotation(15);
voiddelete()voidIShape object.IRange object that represents the cell that lies under the lower-right corner of the object.getChart()IChart contained in this shape.booleanIConnectorFormat object that contains connector formatting properties.booleangetFill()IFillFormat object that contains fill formatting properties for the specified chart or shape.IGroupShapes object that represents the individual shapes in the specified group.booleanIShape contains a chart.IHyperlink object that represents the hyperlink for the shape.booleangetLine()ILineFormat object that contains line formatting properties for the specified shape.booleangetName()IShape object that represents the common parent shape of a child shape or a range of child shapes.IPictureFormat object that contains picture formatting properties for the specified shape.doubleITextFrame object that contains the text and font style properties for the specified shape.IThreeDFormat object that contains 3-D effect formatting properties for the specified shape.getTitle()IRange object that represents the cell that lies under the upper-left corner of the specified object.getType()booleanintvoidsetAlternativeText(String alternativeText) voidsetAutoShapeType(AutoShapeType value) IShape object.voidsetDecorative(boolean value) voidsetFormula(String formula) voidsetIsPrintable(boolean value) voidsetLocked(boolean value) voidvoidsetPlacement(Placement value) voidsetRotation(double value) voidvoidsetVisible(boolean value) voidtoImage(OutputStream stream,
ImageType imageType) voidtoImage(OutputStream stream,
ImageType imageType,
ImageSaveOptions options) voidvoidtoImage(String fileName,
ImageSaveOptions options) toJson()ungroup()voidzOrder(ZOrderType zOrderType) getHeight, getHeightInPixel, getLeft, getLeftInPixel, getTop, getTopInPixel, getWidth, getWidthInPixel, setHeight, setHeightInPixel, setLeft, setLeftInPixel, setTop, setTopInPixel, setWidth, setWidthInPixelReturns the control hosted by this shape. If the shape is not a control, this method returns null.
IScrollBar scrollBar = worksheet.getControls().addScrollBar(50, 20, 120, 20);
IShape controlShape = scrollBar.getShapeRange().get(0);
IControl control = controlShape.getControl();
null if the shape is not a control.
IShape rectangle = worksheet.getShapes().addShape("rectangle", AutoShapeType.Rectangle, 20, 20, 80, 50);
IShape oval = worksheet.getShapes().addShape("oval", AutoShapeType.Oval, 40, 40, 80, 50);
IShape groupShape = worksheet.getShapes().getRange(new int[] {0, 1}).group();
IShapeRange ungroupedShapes = groupShape.ungroup();
int count = ungroupedShapes.getCount();
IShapeRange object that represents the ungrouped shapes.Returns the IWorksheet that contains this shape.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
IWorksheet parent = shape.getParent();
String sheetName = parent.getName();
IWorksheet that contains the shape.Use this method to get the current name assigned to the shape.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setName("SalesBox");
String name = shape.getName();
Use this method to assign a name to the shape.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setName("SalesBox");
value - The name of the object.IRange object that represents the cell that lies under the upper-left corner of the specified object. Use this method to identify the worksheet cell beneath the shape's upper-left corner.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
IRange range = shape.getTopLeftCell();
String address = range.getAddress();
IRange object that represents the cell under the upper-left corner of the specified object.IRange object that represents the cell that lies under the lower-right corner of the object. This property can be used to determine which worksheet cell is covered by the shape's lower-right corner.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
IRange range = shape.getBottomRightCell();
String address = range.getAddress();
IRange object that represents the cell that lies under the lower-right corner of the object.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setTitle("SalesBox");
String title = shape.getTitle();
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setTitle("SalesBox");
value - The title of the alternative text associated with the specified shape.Use this method to get the current rotation angle applied to the shape.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setRotation(15);
double rotation = shape.getRotation();
Use this method to update the current rotation angle applied to the shape.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setRotation(15);
value - The rotation of the shape, in degrees.IChart contained in this shape.Use getHasChart() to determine whether this shape contains a chart before calling this method.
IShape shape = worksheet.getShapes().addChart(ChartType.Line, 20, 20, 240, 160);
IChart chart = shape.getChart();
ChartType chartType = chart.getChartType();
IChart contained in this shape.IShape object.This method is available for AutoShapes other than lines, freeform drawings, and connectors.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
AutoShapeType shapeType = shape.getAutoShapeType();
AutoShapeType of the shape.IShape object.This method is available for AutoShapes other than lines, freeform drawings, and connectors.
Use this method to change one AutoShape type to another supported AutoShapeType.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setAutoShapeType(AutoShapeType.RoundedRectangle);
value - The AutoShape type to apply to the shape.Use this method to read the accessibility description currently assigned to the shape. To update the description, use setAlternativeText(String). If the shape is marked as decorative by using getDecorative(), the returned text can be an empty string.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setAlternativeText("Company logo");
String alternativeText = shape.getAlternativeText();
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setAlternativeText("Company logo");
String alternativeText = shape.getAlternativeText();
alternativeText - The alternative text string for the shape.This applies to chart, shape, picture, linked picture, slicer, and group shape objects. A decorative shape is intended for visual presentation rather than screen reader description. Use setDecorative(boolean) to change this flag. When the decorative flag is set to true, the shape's alternative text and title are cleared, so getAlternativeText() and getTitle() can return empty strings.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.RoundedRectangle, 20, 20, 160, 80);
shape.setAlternativeText("Company logo");
shape.setTitle("SalesBox");
shape.setDecorative(true);
boolean decorative = shape.getDecorative();
String alternativeText = shape.getAlternativeText();
String title = shape.getTitle();
true if the specified shape is decorative; otherwise, false.Setting value to true marks the shape as decorative and clears the shape's alternative text and title. Use this when the shape is intended only for visual presentation and should not expose screen reader description text.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.RoundedRectangle, 20, 20, 160, 80);
shape.setAlternativeText("Company logo");
shape.setTitle("SalesBox");
shape.setDecorative(true);
boolean decorative = shape.getDecorative();
String alternativeText = shape.getAlternativeText();
String title = shape.getTitle();
value - True if the specified shape is decorative.Use this method to determine whether connector-specific APIs such as getConnectorFormat() apply to the shape.
IShape shape = worksheet.getShapes().addConnector(ConnectorType.Straight, 20, 20, 120, 60);
boolean isConnector = shape.getConnector();
true if the specified shape is a connector; otherwise, false.IConnectorFormat object that contains connector formatting properties. Applies to IShape objects that represent connectors.
IShape connector = worksheet.getShapes().addConnector(ConnectorType.Straight, 20, 20, 120, 80);
IConnectorFormat connectorFormat = connector.getConnectorFormat();
connectorFormat.setType(ConnectorType.Elbow);
IConnectorFormat object that contains connector formatting properties.IFillFormat object that contains fill formatting properties for the specified chart or shape.Use the returned IFillFormat object to configure fill settings such as solid fill, gradient fill, pattern, texture, color, and transparency.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
IFillFormat fill = shape.getFill();
fill.solid();
fill.getColor().setRGB(Color.GetBlue());
IFillFormat object that contains fill formatting properties for the specified chart or shape.IShape contains a chart.Use this method to determine whether getChart() can be used to access a chart contained in the shape.
IShape shape = worksheet.getShapes().addChart(ChartType.Line, 20, 20, 240, 160);
boolean hasChart = shape.getHasChart();
true if the shape contains a chart; otherwise, false.ILineFormat object that contains line formatting properties for the specified shape.Use the returned object to access and modify the shape's line appearance, such as weight, dash style, color, and transparency.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
ILineFormat line = shape.getLine();
line.setWeight(2);
line.setDashStyle(LineDashStyle.Dash);
ILineFormat object that contains line formatting properties for the specified shape.IShape object that represents the common parent shape of a child shape or a range of child shapes.
IShape rectangle = worksheet.getShapes().addShape("rectangle", AutoShapeType.Rectangle, 20, 20, 80, 50);
IShape oval = worksheet.getShapes().addShape("oval", AutoShapeType.Oval, 40, 40, 80, 50);
IShape groupShape = worksheet.getShapes().getRange(new int[] {0, 1}).group();
IShape childShape = groupShape.getGroupItems().get(0);
IShape parentGroup = childShape.getParentGroup();
null if this shape is not inside a group.IGroupShapes object that represents the individual shapes in the specified group. Use IGroupShapes.get(int) or IGroupShapes.get(String) to retrieve a single shape from the group.
IShape rectangle = worksheet.getShapes().addShape("rectangle", AutoShapeType.Rectangle, 20, 20, 80, 50);
IShape oval = worksheet.getShapes().addShape("oval", AutoShapeType.Oval, 40, 40, 80, 50);
IShape groupShape = worksheet.getShapes().getRange(new int[] {0, 1}).group();
IGroupShapes groupItems = groupShape.getGroupItems();
IShape shape = groupItems.get("oval");
IGroupShapes object that contains the individual shapes in the group.IPictureFormat object that contains picture formatting properties for the specified shape. Use the returned object to access picture-specific settings such as transparency, brightness, contrast, and cropping.
worksheet.getRange("A1:B2").setValue(new Object[][] {
{"Name", "Value"},
{"Test", 100}
});
IShape picture = worksheet.getShapes().addCameraPicture("=$A$1:$B$2", 20, 20);
IPictureFormat pictureFormat = picture.getPictureFormat();
pictureFormat.setTransparency(0.5);
IPictureFormat object that contains picture formatting properties for the specified shape.ITextFrame object that contains the text and font style properties for the specified shape. Use the returned text frame to access and modify the shape's text content, font formatting, and text layout settings.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextRange().setText("Sales");
textFrame.getTextRange().getFont().setBold(true);
ITextFrame object for the specified shape.The returned value indicates whether the shape moves and sizes with cells, moves with cells only, or remains free floating.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setPlacement(Placement.Move);
Placement placement = shape.getPlacement();
Placement value that specifies how the object is attached to the cells below it.Use a Placement value to control whether the shape moves and resizes with cells, moves with cells, or remains free floating.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setPlacement(Placement.MoveAndSize);
value - The Placement value that specifies how the object is attached to cells.IThreeDFormat object that contains 3-D effect formatting properties for the specified shape.Use the returned object to read or modify settings such as extrusion depth, rotation, perspective, and 3-D visibility for the shape.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
IThreeDFormat threeD = shape.getThreeD();
threeD.setDepth(12);
IThreeDFormat object that contains the shape's 3-D effect formatting properties.Use this method to determine the general category of the shape, such as preset shape ( ShapeType.AutoShape), ShapeType.Chart, ShapeType.Picture, ShapeType.TextBox, or ShapeType.Line.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
ShapeType type = shape.getType();
ShapeType that identifies the general category of the shape.This property indicates whether the shape is displayed on the worksheet.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setVisible(false);
boolean visible = shape.getVisible();
true if the object is visible; otherwise, false.This property indicates whether the shape is displayed on the worksheet.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setVisible(false);
value - true if the object is visible; otherwise, false.This property indicates whether the shape is included when the worksheet is printed or exported to a printable output such as PDF.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setIsPrintable(false);
boolean isPrintable = shape.getIsPrintable();
true if the object should be printed; otherwise, false.This property indicates whether the shape is included when the worksheet is printed or exported to a printable output such as PDF.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setIsPrintable(false);
value - true if the object should be printed; otherwise, false.Returns true if the object is locked, or false if the object can be modified when the worksheet is protected.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setLocked(true);
boolean locked = shape.getLocked();
true if the object is locked; otherwise, false.Sets true if the object is locked, or false if the object can be modified when the worksheet is protected.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setLocked(true);
value - true if the object is locked; otherwise, false.Use this method to retrieve the current stacking position of a shape relative to other shapes in the same worksheet. This is typically used after calling zOrder(ZOrderType) to inspect the updated order.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
int zOrderPosition = shape.getZOrderPosition();
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setFormula("=A1");
String formula = shape.getFormula();
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setFormula("=A1");
formula - The formula to set.Use this method to remove a shape object from the worksheet drawing layer.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.getTextFrame().getTextRange().setText("Hello");
shape.delete();
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.getTextFrame().getTextRange().setText("Hello");
IShape copiedShape = shape.duplicate();
copiedShape.getTextFrame().getTextRange().setText("Hello Copy");
Use getZOrderPosition() to determine the current z-order position of a shape. If the z-order of a shape is changed, the index of the shape in the worksheet's shapes collection also changes.
IShape rectangle = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
IShape oval = worksheet.getShapes().addShape(AutoShapeType.Oval, 40, 30, 120, 60);
rectangle.zOrder(ZOrderType.BringForward);
zOrderType - The z-order command that specifies where to move the shape relative to the other shapes. This value is required.Adjustment values control editable geometry points for shapes that support adjustments. The available adjustment points depend on the current shape type.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Chevron, 10, 10, 120, 80);
IAdjustments adjustments = shape.getAdjustments();
double value = adjustments.get(0);
adjustments.set(0, value * 0.8);
IAdjustments collection that provides access to the shape's adjustment values.IHyperlink object that represents the hyperlink for the shape.Use this method to access the hyperlink attached to the shape and inspect or update properties such as its address, subaddress, screen tip, or display text.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Oval, 1, 1, 200, 100);
shape.getTextFrame().getTextRange().getParagraphs().add("Open Mescius");
worksheet.getHyperlinks().add(shape, "https://developer.mescius.com/", null, "Click to Open", "MESCIUS");
IHyperlink hyperlink = shape.getHyperlink();
String address = hyperlink.getAddress();
IHyperlink object that represents the hyperlink for the shape.The generated image displays the rectangular worksheet area enclosed by the shape. This method can be used with shapes such as AutoShapes, pictures, slicers, and charts.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Oval, 20, 20, 160, 80);
String imagePath = "ShapeToImage.png";
shape.toImage(imagePath);
fileName - The output image file.The generated image displays the rectangular worksheet area enclosed by the shape. This method can be used with shapes such as AutoShapes, pictures, slicers, and charts. Use options to control how the output image is generated.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Oval, 20, 20, 160, 80);
ImageSaveOptions options = new ImageSaveOptions();
options.setScaleX(2.0);
String imagePath = "ShapeToImage.png";
shape.toImage(imagePath, options);
fileName - The output image file.options - The options for output image.Use imageType to control the output format of the generated image. To customize the exported image, use toImage(OutputStream,ImageType,ImageSaveOptions).
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setName("SalesBox");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
shape.toImage(stream, ImageType.PNG);
stream - The output image stream to receive the generated image. Must not be null.imageType - Specifies the type of image to create. Must not be null.Use this method to export the current shape as an image in the specified format. The generated image is written to the provided OutputStream.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ImageSaveOptions options = new ImageSaveOptions();
shape.toImage(stream, ImageType.PNG, options);
stream - The output image stream.imageType - Specifies the type of image to create.options - The options for output image. Can be null.Use toJson() to generate a JSON string for a shape and apply it to another shape with this method.
IShape sourceShape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
sourceShape.getTextFrame().getTextRange().setText("Hello");
String json = sourceShape.toJson();
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 160, 20, 120, 60);
shape.fromJson(json);
json - The JSON string that represents a shape.The returned JSON can be used with fromJson(String) to create a shape from the serialized shape definition.
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 120, 60);
shape.setName("SalesBox");
String json = shape.toJson();