DocumentBuilderInsertOleObject Method (Stream, String, Boolean, Image) |
Namespace: Aspose.Words
public Shape InsertOleObject( Stream stream, string progId, bool asIcon, Image presentation )
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 + "Spreadsheet.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, "OleObject.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 + "Presentation.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, "OleObject.pptx", true, image); } } #endif } } } doc.Save(ArtifactsDir + "DocumentBuilder.InsertOlePowerpoint.docx");