Aspose.Diagram API can be used to open, read, update, change, manipulate and construct Microsoft Visio files and its component parts without the need to install or automate Microsoft Visio application.
The purpose of this article is to explain how to manipulate Microsoft Visio file format programmatically in Java.
The article demonstrates how to load Template Microsoft Visio file and import some Master Shapes i.e. Rectangle, Ellipse, Hexagon, Dynamic connector etc. from Stencil Microsoft Visio file and create Normal Shapes out of them and fill them with colors and formatted text and connect them via Connectors and save it as Output Microsoft Visio file.
Install Aspose.Diagram using Maven in Eclipse IDE
In order to execute the sample code, it is recommended that you know how to install Aspose.Diagram using Maven in Eclipse IDE, which has been discussed separately in this article. Please go through it as per your needs.
Microsoft Visio Formats Supported By Aspose.Diagram
Aspose.Diagram supports all of the Microsoft Visio formats. Some of them are listed below.
- VSD — Drawing
- VSS — Stencil
- VST — Template
- VSDX — OPC/XML Drawing
- VSSX — OPC/XML Stencil
- VSTX — OPC/XML Template
- VSDM — OPC/XML Drawing, macro-enabled
- VSSM — OPC/XML Stencil, macro-enabled
- VSTM — OPC/XML Template, macro-enabled
Input Microsoft Visio Files Used Inside Code
This section presents and explains the input Microsoft Visio files that are used inside the sample code.
Template Microsoft Visio File
The sample code manipulates the Template Microsoft Visio File named as templateManipulateVisioFileUsingAsposeDiagram.vsdx using Aspose.Diagram. It is shown in the following screenshot. Please note, you can use any Microsoft Visio file as a template and the code should work fine.
Stencil Microsoft Visio File Containing Master Shapes
The code uses Stencil Microsoft Visio File named as SampleMasterShapes.vssx containing the sample Master Shapes and imports them inside the template file using Aspose.Diagram. As you can see inside the screenshot, it contains 4 master shapes i.e.
- Dynamic connector
Please execute the following Java sample code with the provided input Microsoft Visio files. The code performs the following tasks.
- Load the template Microsoft Visio file inside the Diagram (i.e. com.aspose.diagram.Diagram) object.
- Access the Page-1 inside the template Microsoft Visio file.
- Import Master Shapes from stencil Microsoft Visio file.
- Add Normal Shapes using Master Shapes and assign them names.
- Access Normal Shapes by their assigned names.
- Fill the Normal Shapes with color and add formatted text inside them.
- Connect the Normal Shapes with each other using Connectors.
- Save the Diagram object in Microsoft Visio VSDX format.
Code is explained well with useful comments and blocks of comments which will help you to understand it easily.
Output Visio File Generated By Aspose.Diagram
After successful execution of sample code, it generates the Output Microsoft Visio File named as outputManipulateVisioFileUsingAsposeDiagram.vsdx using Aspose.Diagram as shown in this screenshot.
This implies that you can manipulate Microsoft Visio Documents using Aspose.Diagram efficiently and conveniently.
Top comments (0)