CustomNodeId
Innehåll
[
Dölj
]Node.CustomNodeId property
Anger anpassad nodidentifierare.
public int CustomNodeId { get; set; }
Anmärkningar
Standard är noll.
Denna identifierare kan ställas in och användas godtyckligt. Till exempel som en nyckel för att få extern data.
Viktig notering, specificerat värde sparas inte i en utdatafil och existerar endast under nodens livslängd.
Exempel
Visar hur man går igenom en sammansatt nods samling av undernoder.
Document doc = new Document();
// Lägg till två körningar och en form som underordnade noder i det första stycket i detta dokument.
Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);
paragraph.AppendChild(new Run(doc, "Hello world! "));
Shape shape = new Shape(doc, ShapeType.Rectangle);
shape.Width = 200;
shape.Height = 200;
// Observera att 'CustomNodeId' inte sparas i en utdatafil och endast existerar under nodens livstid.
shape.CustomNodeId = 100;
shape.WrapType = WrapType.Inline;
paragraph.AppendChild(shape);
paragraph.AppendChild(new Run(doc, "Hello again!"));
// Iterera genom styckets samling av närmaste barn,
// och skriv ut alla körningar eller former som vi hittar inom.
NodeCollection children = paragraph.GetChildNodes(NodeType.Any, false);
Assert.AreEqual(3, paragraph.GetChildNodes(NodeType.Any, false).Count);
foreach (Node child in children)
switch (child.NodeType)
{
case NodeType.Run:
Console.WriteLine("Run contents:");
Console.WriteLine($"\t\"{child.GetText().Trim()}\"");
break;
case NodeType.Shape:
Shape childShape = (Shape)child;
Console.WriteLine("Shape:");
Console.WriteLine($"\t{childShape.ShapeType}, {childShape.Width}x{childShape.Height}");
break;
}
Se även
- class Node
- namnutrymme Aspose.Words
- hopsättning Aspose.Words