如何使用 AddOLEObject 在 Word 中插入 Excel 图表 [英] How to insert an excel chart into Word using AddOLEObject
问题描述
我正在尝试使用 VB.Net 在 Word 文档中创建链接的 OLE 对象.
I'm trying to create a linked OLE Object in a Word document using VB.Net.
现有代码使用 InlineShapes.AddOLEObject(FileName:="abc.xlsx", LinkToFile:=True, Range:=Some Word Range) 将工作表插入 Word 文档.
Existing code uses InlineShapes.AddOLEObject(FileName:="abc.xlsx", LinkToFile:=True, Range:=Some Word Range) to insert a worksheet into a Word document.
我需要比这更多的控制.为了选择一系列单元格,我发现文件名后的额外信息很有用,例如: FileName:="abc.xlsx!sheet1!R1C1:R20C5"
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?
谢谢.
推荐答案
感谢 Mark 的帮助.
Thanks for your help Mark.
我最终发现如果图表在它自己的工作表中,而不是在 Sheet1 中的一个对象,那么 AddOLEObject 代码可以在以下设置下正常工作:
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:
文件名:="abc.xlsx!Chart1"
FileName:="abc.xlsx!Chart1"
我对这个解决方案很满意.
I'm happy with this solution.
这篇关于如何使用 AddOLEObject 在 Word 中插入 Excel 图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!