Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Purpose Summary. What is this page about?
This page demonstrates how to create, modify, and query various shape types in Word documents using Aspose.Words for Python via .NET, providing code examples for inserting shapes, setting properties such as aspect ratio and layout, handling special shapes, and working with OLE objects and Office Math conversion.
This topic discusses how to work programmatically with shapes using Aspose.Words.
The shapes in Aspose.Words represent an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture. A Word document can contain one or more different shapes. Shapes in Aspose.Words are represented by the Shape class.
You can insert inline shape with specified type and size and free-floating shape with the specified position, size and text wrap type into a document using the insert_shape method. The insert_shape method allows inserting DML shape into the document model. The document must be saved in the format, which supports DML shapes, otherwise, such nodes will be converted to VML shape, while document saving.
The following code example shows how to insert these types of shapes into the document:
Using Aspose.Words, you can specify whether the shape’s aspect ratio is locked through the aspect_ratio_locked property.
The following code example shows how to work with the AspectRatioLocked property:
You can also specify whether the shape is displayed inside a table or outside of it using the is_layout_in_cell property.
The following code example shows how to work with the IsLayoutInCell property:
You can create a snip corner rectangle using Aspose.Words. The shape types are SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped, TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, and DiagonalCornersRounded.
The DML shape is created using insert_shape method with these shape types. These types cannot be used to create VML shapes. Attempt to create shape by using the public constructor of the “Shape” class raises the “NotSupportedException” exception.
The following code example shows how to insert these type of shapes into the document:
Using Aspose.Words API, you can get the location and size of the shape containing block in points, relative to the anchor of the topmost shape. To do this, use the bounds_in_points property.
The following code example shows how to work with the BoundsInPoints property:
You can specify the text vertical alignment within a shape using the vertical_anchor property.
The following code example shows how to work with the vertical_anchor property:
Aspose.Words also allows to detect if the Shape has a SmartArt object. To do this, use the has_smart_art property property.
The following code example shows how to work with the HasSmartArt property:
You can insert horizontal rule shape into a document using the insert_horizontal_rule method.
The following code example shows how to do this:
Aspose.Words API provides the horizontal_rule_format property to access the properties of the horizontal rule shape. The HorizontalRuleFormat class exposes basic properties like Height, Color, NoShade etc. for the formatting of a horizontal rule.
The following code example shows how to set HorizontalRuleFormat:
You can use the convert_shape_to_office_math property to convert the shapes with EquationXML to Office Math objects. The default value of this property corresponds to Microsoft Word behavior, i.e. shapes with equation XML are not converted to Office math objects.
The following code example shows how to convert shapes to Office Math objects:
Q: How do I insert a shape with a specific size and position?
A: Use DocumentBuilder.insert_shape(shape_type, width, height) for inline shapes or DocumentBuilder.insert_shape(shape_type, width, height, left, top, wrap_type) for floating shapes. The method creates a DML shape that retains its properties when saved in a format that supports DML.
Q: How can I lock the aspect ratio of a shape?
A: Set the aspect_ratio_locked property of the shape (or ShapeBase object) to True. This prevents the shape from being distorted when its size is changed.
Q: What property controls whether a shape is placed inside a table cell?
A: Use the is_layout_in_cell property. Setting it to True forces the shape to be rendered inside the cell boundaries; False places it outside the cell.
Q: How do I detect if a shape contains a SmartArt diagram?
A: Check the has_smart_art property of the Shape object. It returns True when the shape encapsulates a SmartArt object.
Q: How can I insert an OLE object as an icon with a custom caption?
A: Call Shape.insert_ole_object_as_icon(file_path, icon_file_path, caption). Ensure the icon image is 32 × 32 pixels for correct display.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.