public static void Run() { //ExStart:SubstitutePictureTitleOfOLEObjectFrame // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Shapes(); string oleSourceFile = dataDir + "ExcelObject.xlsx"; string oleIconFile = dataDir + "Image.png"; using (Presentation pres = new Presentation()) { IPPImage image = null; ISlide slide = pres.Slides[0]; // Add Ole objects byte[] allbytes = File.ReadAllBytes(oleSourceFile); IOleObjectFrame oof = slide.Shapes.AddOleObjectFrame(20, 20, 50, 50, "Excel.Sheet.12", allbytes); oof.IsObjectIcon = true; // Add image object byte[] imgBuf = File.ReadAllBytes(oleIconFile); using (MemoryStream ms = new MemoryStream(imgBuf)) { image = pres.Images.AddImage(new Bitmap(ms)); } oof.SubstitutePictureFormat.Picture.Image = image; // Set caption to OLE icon oof.SubstitutePictureTitle = "Caption example"; } //ExEnd:SubstitutePictureTitleOfOLEObjectFrame }
public static void Run() { //ExStart:SetFileTypeForAnEmbeddingObject using (Presentation pres = new Presentation()) { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Shapes(); // Add known Ole objects byte[] fileBytes = File.ReadAllBytes(dataDir + "test.zip"); // Create Ole embedded file info IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(fileBytes, "zip"); // Create OLE object IOleObjectFrame oleFrame = pres.Slides[0].Shapes.AddOleObjectFrame(150, 20, 50, 50, dataInfo); oleFrame.IsObjectIcon = true; pres.Save(dataDir + "SetFileTypeForAnEmbeddingObject.pptx", SaveFormat.Pptx); } //ExEnd:SetFileTypeForAnEmbeddingObject }
public static void Run() { //ExStart:AddOLEObjectFrame // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Shapes(); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } // Instantiate Prseetation class that represents the PPTX Presentation pres = new Presentation(); // Access the first slide ISlide sld = pres.Slides[0]; // Load an cel file to stream FileStream fs = new FileStream(dataDir + "book1.xlsx", FileMode.Open, FileAccess.Read); MemoryStream mstream = new MemoryStream(); byte[] buf = new byte[4096]; while (true) { int bytesRead = fs.Read(buf, 0, buf.Length); if (bytesRead <= 0) { break; } mstream.Write(buf, 0, bytesRead); } // Add an Ole Object Frame shape IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(mstream.ToArray(), "xlsx"); IOleObjectFrame oof = sld.Shapes.AddOleObjectFrame(0, 0, pres.SlideSize.Size.Width, pres.SlideSize.Size.Height, dataInfo); //Write the PPTX to disk pres.Save(dataDir + "OleEmbed_out.pptx", SaveFormat.Pptx); //ExEnd:AddOLEObjectFrame }