如何检索演示文稿中 PowerPoint 幻灯片之间的链接

发布于 2024-09-07 17:41:16 字数 349 浏览 6 评论 0原文

我正在寻找一种方法来读取单个 PowerPoint 演示文稿中幻灯片之间的链接。我需要打开一个 PowerPoint 文件并检索幻灯片之间的所有链接。

现在我正在使用 Aspose 但似乎他们没有任何内容可以读取幻灯片之间的链接。

我阅读了有关 PowerPoint 2007/2010 文件格式的更多内容,发现它只是一个 zip 存档。重命名后,您可以看到其中的所有 xml 数据。有谁知道其中的众多 xml 文件中的哪一个包含链接到哪张幻灯片以及哪张幻灯片的信息?

我需要用 C# 或 VB.NET 来完成。

I`m looking for a way to read a links between slides in single PowerPoint presentation. I need to open a PowerPoint file and retrieve all links slides have to each other.

Right now I`m using Aspose but it appears they do not have anything to read links between slides.

I've read some more about the PowerPoint 2007/2010 file format and found out that it`s just a zip archive. After renaming it you can see all the xml data inside it. Does anybody know which one of the many xml files inside it contains information what slide is linked and to what slide?

I need to do it in C# or VB.NET.

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

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

发布评论

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

评论(2

霓裳挽歌倾城醉 2024-09-14 17:41:16

如果没有必要的话,就没有必要在这里使用 OpenXML - 这可以通过对象模型来完成。以下是在 VBA 中完成的方法,它可以轻松移植到 C# 或 VB.NET。

Sub PrintInteralLinks()
    Dim ap As Presentation
    Set ap = ActivePresentation
    Dim hs As Hyperlinks
    Dim h As Hyperlink
    Dim sl As Slide
    Dim linkedToSlide As String
    Dim slideTitle As Integer
    For Each sl In ap.Slides
        Set hs = sl.Hyperlinks
        For Each h In hs
            slideTitle = InStrRev(h.SubAddress, ",")
            If slideTitle > 0 Then
                linkedToSlide = Mid(h.SubAddress, slideTitle + 1)
                Debug.Print sl.Name & " links to " & linkedToSlide
            End If
        Next
    Next
End Sub

不过,slideTitle = InStrRev(h.SubAddress, ",") 并不是万无一失的。内部链接的模式是#,#,Slide Title,因此您可能需要使用一些正则表达式来使其更好。

There's no need to go to OpenXML here if you don't have to - this can be done with the Object Model. Here's how it is done in VBA, which can easily be ported to C# or VB.NET.

Sub PrintInteralLinks()
    Dim ap As Presentation
    Set ap = ActivePresentation
    Dim hs As Hyperlinks
    Dim h As Hyperlink
    Dim sl As Slide
    Dim linkedToSlide As String
    Dim slideTitle As Integer
    For Each sl In ap.Slides
        Set hs = sl.Hyperlinks
        For Each h In hs
            slideTitle = InStrRev(h.SubAddress, ",")
            If slideTitle > 0 Then
                linkedToSlide = Mid(h.SubAddress, slideTitle + 1)
                Debug.Print sl.Name & " links to " & linkedToSlide
            End If
        Next
    Next
End Sub

The slideTitle = InStrRev(h.SubAddress, ",") isn't fool-proof though. The pattern for internal links is #,#,Slide Title, so you may have to make this better with like some RegEx.

情定在深秋 2024-09-14 17:41:16

要在 C# 中完成此操作,这里有一个查找链接幻灯片的好方法:

    private int GetSlideIndexFromHyperlink(Hyperlink hyperlink)
    {
        var subAddrParts = hyperlink.SubAddress.Split(',');
        return int.Parse(subAddrParts[1]);
    }

请注意,超链接可在您关心的形状的所需 ActionSettings 中找到(在我的例子中,它是 shape.ActionSettings[PpMouseActivation.ppMouseClick]

中用于链接的子地址的格式类似于 SlideId,SlideIndex,SlideTitle 使用此方法通过一些小调整来获取其他部分(如果需要)应该相当简单。 。

To accomplish this in C#, here is a good method to find the linked slide:

    private int GetSlideIndexFromHyperlink(Hyperlink hyperlink)
    {
        var subAddrParts = hyperlink.SubAddress.Split(',');
        return int.Parse(subAddrParts[1]);
    }

Note that the Hyperlink is found within the desired ActionSettings for the Shape you care about (in my case it was shape.ActionSettings[PpMouseActivation.ppMouseClick].

The sub-address for linking in PowerPoint is formatted like SlideId,SlideIndex,SlideTitle. It should be rather simple to obtain the other parts(if desired) with this method via some small tweaks.

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