Lägg till gruppform

Denna handledning förklarar hur man lägger till en gruppform som innehåller flera former till ett Word-dokument med Aspose.Words för .NET. Med gruppformer kan du kombinera och manipulera flera former som en enda enhet.

Förutsättningar

För att följa denna handledning måste du ha följande:

  • Aspose.Words för .NET-biblioteket installerat.
  • Grundläggande kunskaper i C# och ordbehandling med Word-dokument.

Steg 1: Konfigurera dokumentkatalogen

Börja med att ställa in sökvägen till din dokumentkatalog. Byta ut"YOUR DOCUMENT DIRECTORY" med den faktiska sökvägen till katalogen där du vill spara dokumentet.

string dataDir = "YOUR DOCUMENT DIRECTORY";

Steg 2: Skapa ett nytt dokument och GroupShape

Skapa en ny instans avDocument klass ochGroupShape objekt för att arbeta med dokumentet.

Document doc = new Document();
doc.EnsureMinimum();
GroupShape groupShape = new GroupShape(doc);

Steg 3: Skapa och lägg till former i GroupShape

Skapa individuella former som t.exaccentBorderShape ochactionButtonShape användaShape klass. Anpassa deras egenskaper efter önskemål. Lägg till dessa former tillgroupShape objekt.

Shape accentBorderShape = new Shape(doc, ShapeType.AccentBorderCallout1) { Width = 100, Height = 100 };
groupShape.AppendChild(accentBorderShape);

Shape actionButtonShape = new Shape(doc, ShapeType.ActionButtonBeginning)
{
    Left = 100,
    Width = 100,
    Height = 200
};
groupShape.AppendChild(actionButtonShape);

Steg 4: Ställ in mått för GroupShape

Ställ in bredd, höjd och koordinatstorlek förgroupShape.

groupShape.Width = 200;
groupShape.Height = 200;
groupShape.CoordSize = new Size(200, 200);

Steg 5: Infoga GroupShape i dokumentet

Skapa enDocumentBuilder objekt och sätt ingroupShape in i dokumentet med hjälp avInsertNode metod.

DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(groupShape);

Steg 6: Spara dokumentet

Spara dokumentet i den angivna katalogen med hjälp avSavemetod. Ange önskat filnamn med lämplig filtillägg. I det här exemplet sparar vi dokumentet som “WorkingWithShapes.AddGroupShape.docx”.

doc.Save(dataDir + "WorkingWithShapes.AddGroupShape.docx");

Exempel på källkod för Add Group Shape med Aspose.Words för .NET

	// Sökväg till din dokumentkatalog
	string dataDir = "YOUR DOCUMENT DIRECTORY";

	Document doc = new Document();
	doc.EnsureMinimum();
	GroupShape groupShape = new GroupShape(doc);
	Shape accentBorderShape = new Shape(doc, ShapeType.AccentBorderCallout1) { Width = 100, Height = 100 };
	groupShape.AppendChild(accentBorderShape);
	Shape actionButtonShape = new Shape(doc, ShapeType.ActionButtonBeginning)
	{
		Left = 100, Width = 100, Height = 200
	};
	groupShape.AppendChild(actionButtonShape);
	groupShape.Width = 200;
	groupShape.Height = 200;
	groupShape.CoordSize = new Size(200, 200);
	DocumentBuilder builder = new DocumentBuilder(doc);
	builder.InsertNode(groupShape);
	doc.Save(dataDir + "WorkingWithShapes.AddGroupShape.docx");

Det är allt! Du har framgångsrikt lagt till en gruppform som innehåller flera former till ditt Word-dokument med Aspose.W