PPT中插入 OLE 对象

 时间:2026-02-15 02:16:06

1、下载Spire.Office 3.9.1, 并将其中的Spire.XLS.dll文件和Spire.Presentation.dll文件引用到项目中。

2、 将代码放入Visual Studio中:

【C#】

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Spire.Xls;

using System.Drawing;

using Spire.Presentation;

using Spire.Presentation.Drawing;

using System.IO;

namespace Insert_OLE_to_PPT

{   

    class Program   

        {       

             static void Main(string[] args)      

               {           

                 //加载Excel文档          

                 Workbook book = new Workbook();           

                 book.LoadFromFile("Sample.xlsx");           

                //选择单元格范围并将其保存为图像           

                Image image = book.Worksheets[0].ToImage(1, 1, 5, 5);                            //新建一个PowerPoint文档           

               Presentation ppt = new Presentation();           

               //插入图像到PowerPoint文档           

               IImageData oleImage = ppt.Images.Append(image);           

         Rectangle rec = new Rectangle(60, 60, image.Width, image.Height);            using (MemoryStream ms = new MemoryStream())           

                {               

                  //将Excel数据保存到流               

                  book.SaveToStream(ms);               

                   ms.Position = 0;               

                   //根据Excel数据将OLE对象插入到PowerPoint文档               

                  Spire.Presentation.IOleObject oleObject = ppt.Slides[0].Shapes.AppendOleObject("excel", ms.ToArray(), rec);               

                  oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;               

                  oleObject.ProgId = "Excel.Sheet.12";   

                     }           

                     //保存文档                     

                    ppt.SaveToFile("插入OLE.pptx", Spire.Presentation.FileFormat.Pptx2013);       

              }   

        }

}

3、调试并运行代码后,生成的文档如下图所示:

PPT中插入 OLE 对象

  • CAD中怎么分解图纸中图块?
  • Excel通过VBA实现全屏显示且隐藏水平滚动条技巧
  • WPS软件文字版怎么按比例裁剪图片?
  • cad中用vba设置字体颜色
  • WPS怎么计算正弦值的反正弦值
  • 热门搜索
    豆浆怎么做 烤麸怎么做好吃 怎么办营业执照 翁帆平时是怎么解决的 怎么打响指 实习计划怎么写 手机qq怎么退出登录 水饺怎么煮 下水道堵了怎么办 反胃想吐是怎么回事