Being an IT professional, engineer, or project manager, you may use the MS Visio diagramming tool for your Gantt charts or project plans. At some stage, if your MS Visio expires and you need to display a few shapes on the web from the existing VSDX files, this article may solve your problem. So, let’s discuss how to read and export Visio shapes to HTML using Python.
The following points will be covered in this article:
- Python Visio shapes exporter package installation
- Retrieve Visio shape data list
- Export Visio shape data to HTML
Installing Python Visio shapes exporter package
To export/convert the Visio shapes to an HTML form, we will use a Python Visio shape exporter package, which is precise and easy to use.
Please download or install the package from PyPI using the pip command given below:
pip install aspose-diagram-python
Retrieve Visio shapes list in Python
Without MS Visio, when you can’t open and see the existing shapes of a VSDX file, you may need to know the details of those shapes before exporting the desired one to HTML. So, let’s get the shapes data list using the steps below:
- Load the VSDX file using Diagram class.
- Define the page.
- Loop through the shapes of the defined page and print the shape id and name.
The following code sample shows how to display the Visio shapes list using Python.
Below is the data about existing shapes on the first page of the VSDX file.
Shape ID - 7 Name - FAS62xx rear empty Shape ID - 494 Name - FAS62xx Controller Module Shape ID - 743 Name - Sheet.743 Shape ID - 779 Name - DS14 mk2 FC.70 Shape ID - 795 Name - Sheet.795 Shape ID - 796 Name - Rectangle
Whereas the VSDX file looks like this:
Convert Visio (VSDX) shapes to HTML using Python
After retrieving the list, we got an idea about the existing shapes and their positions. So, we can now choose the desired shape to export.
Please follow the steps given below:
- Load Visio file using Diagram class.
- Define the page.
- Specify the shape.
- Create an instance of HTMLSaveOptions class.
- Call Shape.to_html method to export the shape. It will take the output file path and HTMLSaveOptions as arguments.
The following code snippet shows how to export Visio shape to HTML in Python.
You will see the resultant HTML as follows.
Get a free license
You can get a free temporary license to try the API without evaluation limitations.
To sum up, we hope you have learned how to export a specific Visio shape to HTML. Initially, we generated the shape data list and then exported a single shape to an HTML file.
Finally, we suggest you stay tuned at conholdate.com for regular updates.
Ask a question
You can let us know your questions or queries on our forum.
How do I export a shape in Visio?
In this article, we have discussed how to export a Visio shape to HTML. Please follow this link to explore other exporting options.
Can Visio export to SVG?
You can export your Visio documents to SVG or many other formats using various programming languages. Just follow the links below:
- Microsoft Visio File Format Solution
- Diagramming Library - Free Downloads
- Docs in .NET, Java, Python, Node.js, and more