Add document to Diagram via OLE

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Merger MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-merger -- dnx GroupDocs.Merger.Mcp --yes
Folders, licensing and more →

What is an OLE object?

OLE stands for “Object Linking and Embedding”, a Microsoft technology that lets one document carry content produced by another application. For example, an Excel spreadsheet or a PowerPoint presentation can be embedded into a document edited in a word processor. All the related data then stays in one document, which is easy to share.

How to add an OLE object to a diagram

GroupDocs.Merger for Python via .NET embeds a document into a page of a Visio diagram in three steps:

  1. Create an OleDiagramOptions with the path to the file to embed and the number of the diagram page to put it on.
  2. Create a Merger with the path to the diagram, and call merger.import_document() with the options.
  3. Call merger.save() with the path of the result.

The following example embeds a PowerPoint presentation into a Visio diagram:

from groupdocs.merger import Merger
from groupdocs.merger.domain.options import OleDiagramOptions

def add_document_to_diagram_via_ole():
    # Embed the presentation on page 2 of the diagram, in a 2 x 1 inch shape centred at (1, 1) inch
    page_number = 2
    ole_options = OleDiagramOptions("./embedded.pptx", page_number)
    ole_options.x = 1
    ole_options.y = 1
    ole_options.width = 2
    ole_options.height = 1

    with Merger("./input.vsdx") as merger:
        merger.import_document(ole_options)
        merger.save("./output.vsdx")

if __name__ == "__main__":
    add_document_to_diagram_via_ole()

input.vsdx is a sample file used in this example. Click here to download it.

embedded.pptx is a sample file used in this example. Click here to download it.

Binary file (VSDX, 464 KB)

Download full output

Explanation

  • OleDiagramOptions("./embedded.pptx", page_number): the file to embed and the diagram page to put it on, counting from 1.
  • x and y: the position of the shape’s pin, its centre of rotation, on the page; width and height set the shape’s size. All four are in inches.

API reference

See also