我使用draw来标记pdf格式的索引图。所以在网格99中,文本超链接到map99.pdf
有1000个网格单元 - 是否有一种方法可以让(宏)扫描工作表中的文本,如
Text in File | Link to add
99|file:///c:/maps/map99.pdf
100|file:///c:/maps/map100.pdf
并在找到文本时添加相关文件的链接(99,100等)。
我不太习惯使用libre,但很乐意实现任何程序化解决方案。
答案 0 :(得分:1)
好的,在使用xray钻取枚举内容后,我终于得到了答案。代码需要使用游标创建text field。这是一个完整的工作解决方案:
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.
我上传了一个有效的示例文件here。由于某种原因,您的示例文件挂在我的系统上 - 可能它太大了。
使用链接替换文本在Writer中比在Draw中更容易。但是Writer无法打开PDF文件。
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=1401有一些相关的代码。