LibreOffice Draw-基于查询表添加超链接 [英] LibreOffice Draw -add hyperlinks based on query table

查看:248
本文介绍了LibreOffice Draw-基于查询表添加超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用draw标记pdf格式的索引图.因此,在网格99中,文本超链接到map99.pdf

I am using draw to mark up a pdf format index map. So in grid 99, the text hyperlinks to map99.pdf

有1000个网格单元-有一种方法可以使(宏)扫描像这样的工作表中的文本

There are 1000's of grid cells - is there a way for a (macro) to scan for text in a sheet that is like

Text in File | Link to add
99|file:///c:/maps/map99.pdf
100|file:///c:/maps/map100.pdf

并在找到文本时添加指向相关文件的链接(99,100等).

and add links to the relevant file whenever the text is found (99,100 etc).

我不太使用libre,但很高兴实现任何程序化解决方案.

I don't use libre much but happy to implement any programatic solution.

推荐答案

好,在使用 xray 来浏览枚举内容,我终于有了答案.该代码需要使用光标创建文本字段.这是一个完整的工作解决方案:

Ok, after using xray to drill through enumerated content, I finally have the answer. The code needs to create a text field using a cursor. Here is a complete working solution:

Sub AddLinks
    Dim oDocument As Object
    Dim vDescriptor, vFound
    Dim numText As String, tryNumText As Integer
    Dim oDrawPages, oDrawPage
    Dim oField, oCurs
    Dim numChanged As Integer

    oDocument = ThisComponent
    oDrawPages = oDocument.getDrawPages()
    oDrawPage = oDrawPages.getByIndex(0)
    numChanged = 0
    For tryNumText = 1 to 1000
        vDescriptor = oDrawPage.createSearchDescriptor
        With vDescriptor
            '.SearchString = "[:digit:]+"  'Patterns work in search box but not here?
            .SearchString = tryNumText
        End With
        vFound = oDrawPage.findFirst(vDescriptor)
        If Not IsNull(vFound) Then
            numText = vFound.getString()
            oField = ThisComponent.createInstance("com.sun.star.text.TextField.URL") 
            oField.Representation = numText
            oField.URL = numText & ".pdf"
            vFound.setString("")
            oCurs = vFound.getText().createTextCursorByRange(vFound)
            oCurs.getText().insertTextContent(oCurs, oField, False)
            numChanged = numChanged + 1 
        End If
    Next tryNumText
    MsgBox("Added " & numChanged & " links.")
End Sub

要保存相对链接,请转到File -> Export as PDF -> Links并选中Export URLs relative to file system.

To save relative links, go to File -> Export as PDF -> Links and check Export URLs relative to file system.

我在此处上传了示例文件.由于某种原因,您的示例文件挂在我的系统上-可能太大了.

I uploaded an example file here that works. For some reason your example file is hanging on my system -- maybe it's too large.

在Writer中用链接替换文本比在Draw中容易得多.但是Writer不会打开PDF文件.

Replacing text with links is much easier in Writer than in Draw. However Writer does not open PDF files.

https://上有一些相关的代码forum.openoffice.org/en/forum/viewtopic.php?f=20&t=1401 .

这篇关于LibreOffice Draw-基于查询表添加超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆