Insert Shape in Word using Python

This article describes how to insert shape in Word using Python. It has the details to set the development environment, a list of steps, and a sample code showing how to draw a straight line in Word using Python. It will provide guidance to draw inline and floating shapes as per the requirements.

Steps to Insert Shapes in Word using Python

  1. Set the environment to use Aspose.Words for Python via .NET to insert shapes
  2. Create a new Word document for adding shapes
  3. Link a DocumentBuilder object with it
  4. Insert inline shape using the insert_shape() using shape type, size, and rotation angle
  5. Insert a floating shape by using the overloaded method of insert_shape with necessary parameters and rotation angle
  6. Define the output format using the OoxmlSaveOptions class object
  7. Save the output DOCX

These steps summarize how to make a diagram in Word using Python. Create a Word document, instantiate a DocumentBuilder object for it, call the insert_shape() method with shape type and size for creating an inline diagram. Call the other overload of the insert_shape() method providing the shape type, horizontal/vertical relative position, size, and wrap type.

Code for Drawing Diagrams in Word using Python

This sample code demonstrates how to insert a straight line in Word using Python. You may insert any diagram such as IMAGE, ELLIPSE, RECTANGLE, ROUND_RECTANGLE, HEXAGON, THICK_ARROW, TEXT_HEXAGON, and CALLOUT1 to name a very few. The rotation angle parameter is optional and you may skip it if not required.

This article has taught us how to add shapes in Word using Python. For inserting bullets in a paragraph, refer to the article on Insert bullets in Word using Python.

 English