Insert OLE object into Visio via .NET
Insert objects using server-side APIs without any software like Microsoft or Visio, Adobe PDF, etc.
How to Insert OLE object into Visio File Using C#
In order to insert OLE object into Visio file, we’ll use
API which is a feature-rich, powerful and easy to use document manipulation and splitter API for C# platform. Open
package manager, search for Aspose.Diagram and install. You may also use the following command from the Package Manager Console.
Command
PM> Install-Package Aspose.Diagram
Steps to insert OLE object to Visio file via C#
You need the aspose.diagram.dll to try the following workflow in your own environment.
- Instantiating a Diagram object.(or->Load the Vsdx file with full path.)
- Select Page via its index.
- Use the AddShape method to insert an OLE object in the selected page
- Save diagram in vsdx format.
System Requirements
Aspose.Diagram for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Mono or Xamarin Platforms
- Development environment like Microsoft Visual Studio
- Add reference to the Aspose.Diagram for .NET DLL in your project - Install from NuGet using the Download button above
Insert OLE object - C#
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_VisioPages(); | |
//New diagram | |
Diagram diagram = new Diagram(); | |
// Get page object by index | |
Aspose.Diagram.Page page0 = diagram.Pages[0]; | |
// set pinX, pinY, width and height | |
double pinX = 2, pinY = 2, width = 4, hieght = 3; | |
//Import ole as Visio shape word | |
page0.AddShape(pinX, pinY, width, hieght, new FileStream("imagedoc.emf", FileMode.OpenOrCreate), new FileStream( "sequence.doc", FileMode.OpenOrCreate)); | |
diagram.Save(dataDir + "out.vsdx", SaveFileFormat.VSDX); | |