修改Word文档中嵌入的Excel对象 [英] Modify an embedded Excel object inside a Word doc
本文介绍了修改Word文档中嵌入的Excel对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要示例代码,甚至第三方对象,这将允许我获取一个嵌入word文档中的excel对象。我已经尝试了Aspose,他们还没有能力。有没有人做过,或者你知道第三方的对象吗?
I need example code or even a 3rd party object that will allow me to get to an excel object embedded in a word doc. I have already tried Aspose and they do not have the capabilities yet. Has anyone done it or do you know of a 3rd party object that will?
推荐答案
好的,我做到了!我感谢Remou发布的链接。在我过了最初的障碍之后,它确实提供了一些支持。
Ok, i did it! I appreciate the link posted by Remou. It did provide some support after I got past the initial hurdle...
这是我的代码:
WordApp.Documents.Open("C:\Report.docx")
Dim iOLE As Int16
Dim oSheet As Object
Dim oOLE As Object
For iOLE = 1 To WordApp.ActiveDocument.Content.ShapeRange.Count 'These are the embedded objects
If Not WordApp.ActiveDocument.Content.ShapeRange(iOLE).OLEFormat Is Nothing Then '- make sure it is OLE
If WordApp.ActiveDocument.Content.ShapeRange(iOLE).OLEFormat.ProgID.Contains("Excel") Then '- make sure it's an Excel object
'- I have found an Excel Object!!!
WordApp.ActiveDocument.Content.ShapeRange(iOLE).OLEFormat.Activate()
oOLE = WordApp.ActiveDocument.Content.ShapeRange(iOLE).OLEFormat.Object
oSheet = oOLE.Worksheets(1) '- I can assert that each of them has at least one sheet and that I need the first one...
oSheet.Range("BB3") = "I did it!" '- setting some text to verify I made it in...
End If
End If
Next
WordApp.ActiveDocument.SaveAs("c:\temp\report_test.docx")
这篇关于修改Word文档中嵌入的Excel对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文