This topic will give you an overview of the concepts, as well as the use cases related to OLE in Excel with the .NET platform.
IOleObjectinterface, possibly along with a range of other interfaces, depending on the needs of the object.
IOleObjectinterface is required, but we may also need to perform other interfaces if the functionality that is exported by those interfaces is needed. To better understand what is said below, some terms need to be clarified. The view state of the object is whether the object is transparent, opaque, or opaque to a homogeneous background and whether the object supports drawing with a specified aspect. The page of an object is an object that represents the position of the object in its container. A container supports the storage of objects for all objects. The following is a list of interfaces, grouped by the object they usually need to implement. Interfaces often implemented by OLE objects are often called by OLE containers and vice versa. Note that the following indented list indicates the inheritance of the interface.
IUnknownprovide all of the non-indented interfaces.
DataObjectallows embedded objects to store their visual representation, therefore allowing it to be displayed later without having to launch the application that used to create the object.
- Provides more precise control in caching.
- Usually, the implementation will retrieve the content stored in the object.
DataObjectis running. Thus, this will enable it to register notifications of that object's data change and therefore allow it to update the cached presentation properly.
- Called by the outermost container of an object to interact with it while it is active, for example, to handle acceleration keys in the message queue of the container meant for the container object.
- Called by the container to activate or deactivate the object.
verbson the object. These verbs often include
Edit, but can also add other verbs. One of the verbs is defined as the main verb and will perform it when the user double clicks on an object.
Lets an object draw itself directly, without moving a DataObject into the container. For those objects that support both DataObject and this interface, we often share the following deployment commands.
- Allows callers to query the size of the object.
- Add support for flicker-free display of transparent objects, experiment with irregularly shaped objects, and set the size of an object.
Recognizing the outstanding features and necessity of OLE, we are pleased to present the Word Office Component library - an all-powerful library that allows you to perform various complex tasks with Word documents with OLE on the .NET platform.
Note: This example applies to C# platforms. This example will demonstrate how to extract an OLE Object from an existing Excel document that stored on your computer. We have fully installed all of the methods used in this article in the Excel Office Component library, so make sure you have our library installed. First of all, import the libraries needed for this task.
First and foremost, you'll want to create your own Word document for the next steps. We can quickly archive this by taking the advance of the
WordDocument class - which is already fully installed in the Word Office Component library.
WordDocument document = new WordDocument();
Dim document As New WordDocument()
To open a Word document, you can also take advantage of the
WordDocument class as the code snippet below.
WordDocument oleDocument = new WordDocument(CommonDataPath + "\\OLE Objects.docx");
Dim oleDocument As New WordDocument(CommonDataPath & "\OLE Objects.docx")
WordOleObject class allows you to retrieve OLE Objects from the source document.
WordOleObject oleObject = oleDocument.LastParagraph.Items as WordOleObject;
Dim oleObject As WordOleObject = TryCast(oleDocument.LastParagraph.Items(0), WordOleObject)
Paragraph class will represent the paragraphs in the document. It could be a piece of text selected from existing documents or a new piece of writing to be added to the document.
Paragraph para = document.Sections.AddParagraph();
Dim para As Paragraph = document.Sections(0).AddParagraph()
To add new content to an existing paragraph, you can take advantage of the
para.AppendText("Chart OLE Object from the source file");
para.AppendText("Chart OLE Object from the source file")
If the content that you want to add to your document is an OLE object, the
AppendOleObject method is just for you.
para.AppendOleObject(oleObject.Container, (Picture)oleObject.OlePicture.Clone(), OleLinkType.Embed);
para.AppendOleObject(oleObject.Container, CType(oleObject.OlePicture.Clone(), Picture), OleLinkType.Embed)
The full source code of these examples is also available in our Word package.