如何在 Word 文檔中加入 Group 形狀

Contents
[ ]

有時你需要在一個 Word 文檔中加上一個 group shape。 這樣的 group shape 包含多個圖形。

在Microsoft Word中,您可以用Group命令/按鈕快速加上一個group shape。 一組中的獨立形狀可以分開移動。

在 Aspose.Words 中,使用 GroupShape 類別非常容易加入 group shape。 Shape 透過 Shape 類別獨立建立,然後透過 AppendChild 方法加入 GroupShape 物件。

以下範例展示如何在 Word 文檔中加入 group shape:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
Document doc = new Document();
doc.EnsureMinimum();
GroupShape gs = new GroupShape(doc);
Shape shape = new Shape(doc, Drawing.ShapeType.AccentBorderCallout1);
shape.Width = 100;
shape.Height = 100;
gs.AppendChild(shape);
Shape shape1 = new Shape(doc, Drawing.ShapeType.ActionButtonBeginning);
shape1.Left = 100;
shape1.Width = 100;
shape1.Height = 200;
gs.AppendChild(shape1);
gs.Width = 200;
gs.Height = 200;
gs.CoordSize = new System.Drawing.Size(200, 200);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(gs);
dataDir = dataDir + "groupshape-doc_out.doc";
// Save the document to disk.
doc.Save(dataDir);