Excel .NET组件Spire.XLS教程:在Excel 中插入 OLE 对象

11月优惠进行时,消费满额即享折上豪礼,想买Spire.Doc的朋友赶快咨询在线客服吧!

推荐阅读:【想要快速完成文档格式转换吗pire系列组件格式转换完整攻略来啦!】


在Excel 中插入 OLE 对象

定义一个GetDocImage(string docxFile) 方法获取图片,这里的图片是原始Word文档中的数据信息图像,将OLE对象插入到Excel工作表后,这个图像将显示在Excel工作表中。

private static Image GetDocImage(string docxFile){//加载Word文档Document document = new Document();document.LoadFromFile(docxFile);//将Word文档的第一页保存为图片Image olePicture=document.SaveToImages(0, Spire.Doc.Documents.ImageType.Bitmap);     return olePicture; }

调用上个步骤获取的图像,将Word文档作为OLE对象插入到Excel工作表中。

static void Main(string[] args){//加载Excel文档Workbook workbook = new Workbook();workbook.LoadFromFile("d:\Excel示例.xlsx");//获取第一张工作表Worksheet ws = workbook.Worksheets[0];//插入OLE对象string docx = "d:\Word示例.docx";Image image = GetDocImage(docx);IOleObject oleObject = ws.OleObjects.Add(docx, image, OleLinkType.Embed);oleObject.Location = ws.Range["B4"];oleObject.ObjectType = OleObjectType.WordDocument;//保存文档workbook.SaveToFile("OLE文档.xlsx", ExcelVersion.Version2013);System.Diagnostics.Process.Start("OLE文档.xlsx");}

Insert-OLE-Object-in-Excel.png

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年10月5日
下一篇 2019年10月5日

相关推荐

发表回复

登录后才能评论