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.10
Syntax
public Shape InsertOleObject(
	Stream stream,
	string progId,
	bool asIcon,
	Image presentation
)

Parameters

stream
Type: System.IOStream
Stream containing application data.
progId
Type: SystemString
Programmatic Identifier of OLE object.
asIcon
Type: SystemBoolean
Specifies either Iconic or Normal mode of OLE object being inserted.
presentation
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.
Examples
Shows how to use document builder to embed Ole objects in a document.
[C#]

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);

#if NETSTANDARD2_0 || __MOBILE__
                        SkiaSharp.SKBitmap bitmap = SkiaSharp.SKBitmap.Decode(imgBytes);

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

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