Working with Group Shape in Word Documents

Contents
[ ]

Sometimes you need to add a group shape into a Word document. Such a group shape consists of multiple shapes.

In Microsoft Word, you can quickly add a group shape using the Group command/button. An individual shape in a group can be moved separately.

In Aspose.Words it is very easy to add a group shape using GroupShape class. Shape is created separately using Shape class and then added in GroupShape object using appendChild method.

The following code example shows how to add a group shape into a Word document:


FAQ

  1. Q: How do I create a GroupShape and add individual shapes to it in Aspose.Words for Node.js?
    A: First create a Document and a DocumentBuilder. Use the builder to insert a GroupShape with builder.insertGroupShape(). Then create each Shape (e.g., rectangle, ellipse) and add them to the group using groupShape.appendChild(shape). Finally save the document.

  2. Q: Which shape types can be added to a GroupShape?
    A: Any shape type defined in the ShapeType enumeration can be added, such as Rectangle, RoundRectangle, Ellipse, Diamond, Triangle, RightTriangle, Parallelogram, Trapezoid, Hexagon, Octagon, etc. The full list is available in the Aspose.Words documentation.

  3. Q: Can I set the position and size of shapes inside a GroupShape?
    A: Yes. After creating a Shape, set its left, top, width, and height properties before appending it to the group. These coordinates are relative to the group’s coordinate system.

  4. Q: How do I apply fill color or line style to a shape within a GroupShape?
    A: Use the shape’s fill and stroke objects. For example, shape.fill.foreColor = asposewords.Color.fromRgb(255, 0, 0); sets a red fill, and shape.stroke.color = asposewords.Color.fromRgb(0, 0, 0); sets a black outline.

  5. Q: How can I save the document after adding a GroupShape?
    A: Call the save method on the Document instance, specifying the desired format, e.g., document.save("GroupShape.docx");. The document will contain the group shape with all its child shapes.