DocumentBuilderInsertOleObject Method (Stream, String, Boolean, Image)
Inserts an embedded OLE object from a stream into the document.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
public Shape InsertOleObject(
	Stream stream,
	string progId,
	bool asIcon,
	Image presentation


Type: System.IOStream
Stream containing application data.
Type: SystemString
Programmatic Identifier of OLE object.
Type: SystemBoolean
Specifies either Iconic or Normal mode of OLE object being inserted.
Type: System.DrawingImage
Image presentation of OLE object. If value is null Aspose.Words will use one of the predefined images.

Return Value

Type: Shape
Shape node containing Ole object and inserted at the current Builder position.
Shows how to use document builder to embed Ole objects in a document.
Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Let's take a spreadsheet from our system and insert it into the document
            using (Stream spreadsheetStream = File.Open(MyDir + "MySpreadsheet.xlsx", FileMode.Open))
                // The spreadsheet can be activated by double clicking the panel that you'll see in the document immediately under the text we will add
                // We did not set the area to double click as an icon nor did we change its appearance so it looks like a simple panel
                builder.Writeln("Spreadsheet Ole object:");
                builder.InsertOleObject(spreadsheetStream, "MyOleObject.xlsx", false, null);

                // A powerpoint presentation is another type of object we can embed in our document
                // This time we'll also exercise some control over how it looks 
                using (Stream powerpointStream = File.Open(MyDir + "MyPresentation.pptx", FileMode.Open))
                    // If we insert the Ole object as an icon, we are still provided with a default icon
                    // If that is not suitable, we can make the icon to look like any image
                    using (WebClient webClient = new WebClient())
                        byte[] imgBytes = webClient.DownloadData(AsposeLogoUrl);

                        SkiaSharp.SKBitmap bitmap = SkiaSharp.SKBitmap.Decode(imgBytes);

                        builder.Writeln("Powerpoint Ole object:");
                        builder.InsertOleObject(powerpointStream, "MyOleObject.pptx", true, bitmap);
                        using (MemoryStream stream = new MemoryStream(imgBytes))
                            using (Image image = Image.FromStream(stream))
                                // If we double click the image, the powerpoint presentation will open
                                builder.Writeln("Powerpoint Ole object:");
                                builder.InsertOleObject(powerpointStream, "MyOleObject.pptx", true, image);

            doc.Save(ArtifactsDir + "DocumentBuilder.InsertOleObject.docx");
See Also