Uppdatera formegenskaper i VSTO och Aspose.Diagram
Contents
[
Hide
]
VSTO
VSTO låter dig programmera med Microsoft Visio filer. Så här uppdaterar du formegenskaper:
- Skapa ett Visio applikationsobjekt.
- Gör applikationsobjektet osynligt.
- Öppna en befintlig Visio VSD fil.
- Hitta den önskade formen.
- Uppdatera formegenskaperna (text, textstil, position och storlek).
- Spara filen som VDX.
Visio.Application vsdApp = null;
Visio.Document vsdDoc = null;
try
{
//Create Visio Application Object
vsdApp = Application;
//Make Visio Application Invisible
vsdApp.Visible = false;
//Create a document object and load a diagram
vsdDoc = vsdApp.Documents.Open( "Drawing.vsd");
//Create page object to get required page
Visio.Page page = vsdApp.ActivePage;
//Create shape object to get required shape
Visio.Shape shape = page.Shapes["Process1"];
//Set shape text and text style
shape.Text = "Hello World";
shape.TextStyle = "CustomStyle1";
//Set shape's position
shape.get_Cells("PinX").ResultIU = 5;
shape.get_Cells("PinY").ResultIU = 5;
//Set shape's height and width
shape.get_Cells("Height").ResultIU = 2;
shape.get_Cells("Width").ResultIU = 3;
//Save file as VDX
vsdDoc.SaveAs("Drawing1.vdx");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
//Close active document and quit
vsdDoc.Close();
vsdApp.Quit();
}
Aspose.Diagram
Vid programmering med Aspose.Diagram behöver du inte Microsoft Visio på maskinen, och du kan arbeta oberoende av Microsoft Office Automation. Så här uppdaterar du formegenskaper med Aspose.Diagram for .NET:
- Öppna en befintlig Visio VSD fil.
- Hitta den önskade formen.
- Uppdatera formegenskaperna (text, textstil, position och storlek).
- Spara filen som VDX.
//Save the uploaded file as PDF
Diagram diagram = new Diagram("Drawing1.vsd");
//Find a particular shape and update its properties
foreach (Aspose.Diagram.Shape shape in diagram.Pages[0].Shapes)
{
if (shape.Name.ToLower() == "process1")
{
shape.Text.Value.Clear();
shape.Text.Value.Add(new Txt("Hello World"));
//Find custom style sheet and set as shape's text style
foreach (StyleSheet styleSheet in diagram.StyleSheets)
{
if (styleSheet.Name == "CustomStyle1")
{
shape.TextStyle = styleSheet;
}
}
//Set horizontal and vertical position of the shape
shape.XForm.PinX.Value = 5;
shape.XForm.PinY.Value = 5;
//Set height and width of the shape
shape.XForm.Height.Value = 2;
shape.XForm.Width.Value = 3;
}
}
//Save shape as VDX
diagram.Save("Drawing1.vdx", SaveFileFormat.VDX);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}