Manipulate Microsoft Visio file format programmatically in Java
Tags: visio, stencil, diagram, connector
Published: 2018-09-27 09:56:07

---
title: Manipulate Microsoft Visio file format programmatically in Java
published: true
description: Manipulate Microsoft Visio file format programmatically in Java
tags: #Visio #Stencil #Diagram #Connector
---

[Aspose.Diagram](https://products.aspose.com/diagram/java) 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. 

**Purpose**

>The purpose of this article is to explain how to manipulate Microsoft Visio file format programmatically in Java. 


**Demonstration**

>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.

* [Install Aspose.Diagram using Maven and Create Microsoft Visio Document in Eclipse IDE](https://medium.com/asposediagram/install-aspose-diagram-using-maven-and-create-microsoft-visio-document-in-eclipse-ide-b556cb0d9a5b)

# 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](https://github.com/AsposeDiagram/AsposeDiagram-Screenshots-and-Sample-Files/blob/master/Manipulate-Microsoft-Visio-file-format-programmatically/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.

![Template Microsoft Visio file to be manipulated using Aspose.Diagram.](https://raw.githubusercontent.com/AsposeDiagram/AsposeDiagram-Screenshots-and-Sample-Files/master/Manipulate-Microsoft-Visio-file-format-programmatically/Template-Microsoft-Visio-file-manipulated-Aspose.Diagram.png "Template Microsoft Visio file to be manipulated using Aspose.Diagram.")

## Stencil Microsoft Visio File Containing Master Shapes

The code uses **Stencil Microsoft Visio File** named as [_SampleMasterShapes.vssx_](https://github.com/AsposeDiagram/AsposeDiagram-Screenshots-and-Sample-Files/blob/master/Manipulate-Microsoft-Visio-file-format-programmatically/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.

* _Rectangle_
* _Ellipse_
* _Hexagon_
* _Dynamic connector_

![Stencil Microsoft Visio file to import Master Shapes using Aspose.Diagram.](https://raw.githubusercontent.com/AsposeDiagram/AsposeDiagram-Screenshots-and-Sample-Files/master/Manipulate-Microsoft-Visio-file-format-programmatically/Stencil-Microsoft-Visio-Master-Shapes-Aspose.Diagram.png "Stencil Microsoft Visio file to import Master Shapes using Aspose.Diagram.")

# Sample Code

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.

{% gist https://gist.github.com/AsposeDiagram/06262743f6fc54d0ebfd8bd9489e18ca %}

# Output Visio File Generated By Aspose.Diagram

After successful execution of sample code, it generates the **Output Microsoft Visio File** named as [_outputManipulateVisioFileUsingAsposeDiagram.vsdx_](https://github.com/AsposeDiagram/AsposeDiagram-Screenshots-and-Sample-Files/blob/master/Manipulate-Microsoft-Visio-file-format-programmatically/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.

![Output Microsoft Visio file generated using Aspose.Diagram.](https://raw.githubusercontent.com/AsposeDiagram/AsposeDiagram-Screenshots-and-Sample-Files/master/Manipulate-Microsoft-Visio-file-format-programmatically/Output-Microsoft-Visio-file-manipulated-by-Aspose.Diagram.png "Output Microsoft Visio file generated using Aspose.Diagram.")

# See also

* [Manipulate Microsoft Visio file format programmatically in C#](https://medium.com/asposediagram/manipulate-microsoft-visio-file-format-programmatically-in-c-84163b579169)
* [Working with Microsoft Visio Diagrams](https://docs.aspose.com/display/diagramjava/Working+with+Diagrams)
* [Code Examples — Aspose.Diagram for Java](https://github.com/aspose-diagram/Aspose.Diagram-for-Java)