Find Replace Visio Java

Visio files can include shapes, connectors, images, or text to depict different diagrams which are used to create diagrams like organizational charts, flow charts, etc. In certain scenarios, you might want to find and replace some text in a VSD or VSDX format Visio diagram. Accordingly, this article explains how to find and replace text in Visio drawings programmatically in Java.

Search and Replace Text in Visio Diagram – Java API Installation

Aspose.Diagram for Java API supports working with different Visio file-formats including VSD, VSDX, VSDM, VSSX, etc. You can download the JAR files from the Downloads section, or use the following configurations in the pom.xml file of your project in order to access the API from the Aspose Repository:

Repository:

 <repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>http://repository.aspose.com/repo/</url>
    </repository>
</repositories>

Dependency:

 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-diagram</artifactId>
        <version>22.4</version>
        <classifier>jdk16</classifier>
    </dependency>
</dependencies>

Find and Replace Text in Visio Diagram Programmatically in Java

You may find and replace text in a VSD VSDX format Visio file with the steps below:

  1. Create a collection of the strings to search and replace text.
  2. Load the source Visio diagram file and loop through text in each shape.
  3. Write the output Visio diagram file.

The code sample below shows how to find and replace text in a Visio file programmatically using Java:

Conclusion

In conclusion, you have understood how to find and replace text in Visio diagrams. You can also improvise the code snippet to work with other overloads of the replace method. For instance, replacing all instances of matching text or only the first occurrence of the search term in the Visio file. You can visit the documentation space to learn several other features to manipulate or convert MS Visio files. In case you need to discuss any of your concerns or requirements, please reach out to us at the forum.

See Also

Convert Visio VSD or VSDX File to XAML in Java