C # Add OLE to PPT slide

This article describes how to add OLE objects to PPT slides through C # program code. Here, the Excel document is inserted into the specified position of the PPT slide; when adding, the range of cells in Excel is saved as a picture, and the picture is added to the slide in an embedded manner. After successful addition, double-click the picture To edit, open and other actions to operate on the Excel source document.

Use tool: Free Spire.Office for .NET (free version)

Obtain and add references: Download the package through the official website . After downloading, unzip and install to the specified path. After the installation is completed, add Spire.XLS.dll and Spire.Presentation.dll in the Bin folder under the installation path to the VS program. Quote the effect as follows:

 

C # code

using Spire.Xls;
 using Spire.Presentation;
 using System.Drawing;
 using Spire.Presentation.Drawing;
 using System.IO; 

namespace AddOLE 
{ 
    class Program 
    { 
        static  void Main ( string [] args) 
        { 
            // Load Excel document 
            Workbook book = new new the Workbook (); 
            book.LoadFromFile ( " WorkBook.xlsx " ); 

            // selected range of cells and save it as an image 
            image image book.worksheets = [ 0 ] .ToImage (1 , 1 , 4 , 3 ); 

            // Create a new PowerPoint document 
            Presentation ppt = new Presentation (); 

            // Insert image into PowerPoint document 
            IImageData oleImage = ppt.Images.Append (image); 
            Rectangle rec = new Rectangle ( 60 , 60 , image.Width, image.Height); 

            using (MemoryStream ms = new MemoryStream ()) 
            { 
                // Save Excel data to stream 
                book.SaveToStream (ms); 
                ms.Position = 0; 

                // Insert the OLE object into the first slide in the PPT 
                Spire.Presentation.IOleObject oleObject = ppt.Slides [ 0 ] .Shapes.AppendOleObject ( " excel " , ms.ToArray (), rec); 
                oleObject.SubstituteImagePictureFillFormat .Picture.EmbedImage = oleImage; 
                oleObject.ProgId = " Excel.Sheet.12 " ; 
            } 

            // save the document 
            ppt.SaveToFile ( " AddOLE.pptx " , Spire.Presentation.FileFormat.Pptx2013); 
            System.Diagnostics.Process.Start ( " AddOLE.pptx ");
        }
    }
}

OLE added effect:

Guess you like

Origin www.cnblogs.com/Yesi/p/12690985.html