修改 Word 文档中嵌入的 Excel 对象

发布于 2024-10-01 08:34:02 字数 108 浏览 4 评论 0原文

我需要示例代码,甚至需要第 3 方对象,以允许我访问嵌入在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉世弥音 2024-10-08 08:34:02

好吧,我做到了!我很欣赏 Remou 发布的链接。在我克服最初的障碍后,它确实提供了一些支持......

这是我的代码:

        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")

Ok, i did it! I appreciate the link posted by Remou. It did provide some support after I got past the initial hurdle...

Here is my code:

        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")
心房的律动 2024-10-08 08:34:02

您可以在这里找到一些信息:VBScript 和多级 OLE?

You may find some information here: VBScript and multilevel OLE?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文