How to insert an excel chart into Word using AddOLEObject

▼魔方 西西 提交于 2019-12-19 04:57:07

问题


I'm trying to create a linked OLE Object in a Word document using VB.Net.

Existing code uses InlineShapes.AddOLEObject(FileName:="abc.xlsx", LinkToFile:=True, Range:=Some Word Range) to insert a worksheet into a Word document.

I need more control than this. To select a range of cells I've found that extra information after the filename can be useful, for example: FileName:="abc.xlsx!sheet1!R1C1:R20C5"

Is there a way to specify a specific chart within a worksheet? So can I specify the second chart on the worksheet as the object to link to?

Thanks.


回答1:


Thanks for your help Mark.

I eventually figured out that if the Chart is in it's own sheet, rather than an object in Sheet1, then the AddOLEObject code works correctly with the following setting:

FileName:="abc.xlsx!Chart1"

I'm happy with this solution.




回答2:


A chart will either be a whole worksheet so address as per your sheet1 e.g. abc.xlsx!sheet1 or an object on a sheet so use the object name e.g. abc.xlsx!sheet1!chart_object



来源:https://stackoverflow.com/questions/2262686/how-to-insert-an-excel-chart-into-word-using-addoleobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!