| View previous topic :: View next topic |
| Author |
Message |
jwesonga General User

Joined: 12 Feb 2008 Posts: 20
|
Posted: Fri Feb 29, 2008 4:04 am Post subject: code to list all hyperlinks in a OOo document |
|
|
| I need code to list all hyperlinks in my OOo Writer document, I have found code here http://www.oooforum.org/forum/viewtopic.phtml?t=9957 that adds a hyperlink to text, |
|
| Back to top |
|
 |
jwesonga General User

Joined: 12 Feb 2008 Posts: 20
|
Posted: Fri Feb 29, 2008 5:04 am Post subject: count all hyperlinks |
|
|
I took the code for searching and replacing hyperlinks http://www.oooforum.org/forum/viewtopic.phtml?t=46675 and ammended it so that I could count the hyperlinks:
| Code: | REM ***** BASIC *****
dim objEnumPar as object, objText as object, oDoc as object
Sub Main
initOOo
ListHyperLinks thisComponent
End Sub
Sub initOOo
oDoc = thisComponent'starDesktop.currentComponent
objText=oDoc.GetText
End Sub
Sub ListHyperlinks (oDoc )
nCount = 0
objEnumPar=objText.createEnumeration
Do While objEnumPar.hasMoreElements()
objPar = objEnumPar.nextElement()
objEnumChunks = objPar.createEnumeration()
Do While objEnumChunks.hasMoreElements()
objChunk = objEnumChunks.nextElement()
XRay objChunk
If objChunk.HyperLinkURL <> "" Then
nCount = nCount + 1
End If
Loop
Loop
msgbox "Number of hyperlinks " & nCount
End Sub |
|
|
| Back to top |
|
 |
probe1 Moderator


Joined: 18 Aug 2004 Posts: 2465 Location: Chonburi Thailand Asia
|
Posted: Fri Feb 29, 2008 5:14 am Post subject: |
|
|
... this code won't get you hyperlinks in other areas than "Text": tables, headers, footers, frames, ... _________________ Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs |
|
| Back to top |
|
 |
jwesonga General User

Joined: 12 Feb 2008 Posts: 20
|
Posted: Fri Feb 29, 2008 6:44 am Post subject: |
|
|
| probe1 wrote: | | ... this code won't get you hyperlinks in other areas than "Text": tables, headers, footers, frames, ... |
For now all I need is hyperlinks within the text so for now its okay. The code only counts the items, how can I get the properties of the hyperlinks that have been identified? In the form of:
Property- Value |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Fri Feb 29, 2008 7:14 am Post subject: |
|
|
Taking that code as a starting point and, as indicated, only looking in normal text, you could use this. | Code: | Sub GetHyperlinks 'List, unlink or delete.
Dim oDoc,oEnum,oEnum1,oPara,oPortion,s
oDoc = ThisComponent
oEnum = oDoc.Text.createEnumeration
While oEnum.hasMoreElements
oPara = oEnum.nextElement
oEnum1 = oPara.createEnumeration
While oEnum1.hasMoreElements
oPortion = oEnum1.nextElement
If oPortion.HyperLinkURL <> "" then
REM list it
s = s & "URL = " & oPortion.HyperLinkURL & " - Text = " & oPortion.String & Chr(13)
REM unlink it
'oPortion.HyperLinkURL = ""
REM delete it
'oPortion.String = ""
EndIf
Wend
Wend
REM show list
MsgBox s
End Sub |
|
|
| Back to top |
|
 |
jwesonga General User

Joined: 12 Feb 2008 Posts: 20
|
Posted: Fri Feb 29, 2008 7:36 am Post subject: |
|
|
| JohnV wrote: | Taking that code as a starting point and, as indicated, only looking in normal text, you could use this. | Code: | Sub GetHyperlinks 'List, unlink or delete.
Dim oDoc,oEnum,oEnum1,oPara,oPortion,s
oDoc = ThisComponent
oEnum = oDoc.Text.createEnumeration
While oEnum.hasMoreElements
oPara = oEnum.nextElement
oEnum1 = oPara.createEnumeration
While oEnum1.hasMoreElements
oPortion = oEnum1.nextElement
If oPortion.HyperLinkURL <> "" then
REM list it
s = s & "URL = " & oPortion.HyperLinkURL & " - Text = " & oPortion.String & Chr(13)
REM unlink it
'oPortion.HyperLinkURL = ""
REM delete it
'oPortion.String = ""
EndIf
Wend
Wend
REM show list
MsgBox s
End Sub |
|
Thanks JohnV that worked very well. Is it possible to identify which links are "dead" that is if the internal link being pointed to does exist or has been deleted? Basically users sometimes create internal document links then at a later date they might delete the target as they amend the document. |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Fri Feb 29, 2008 11:06 am Post subject: |
|
|
| Quote: | | Is it possible to identify which links are "dead" that is if the internal link being pointed to does exist or has been deleted? | I doubt that but if it can be done it's beyond me, |
|
| Back to top |
|
 |
jwesonga General User

Joined: 12 Feb 2008 Posts: 20
|
Posted: Mon Mar 03, 2008 12:14 am Post subject: |
|
|
| JohnV wrote: | | Quote: | | Is it possible to identify which links are "dead" that is if the internal link being pointed to does exist or has been deleted? | I doubt that but if it can be done it's beyond me, |
I've seen that a few people have found ways how to detect broken hyperlinks like http://www.oooforum.org/forum/viewtopic.phtml?p=276137#276137 , although no one has shared the code snippet. In essence thats what i'm trying to achieve[/url] |
|
| Back to top |
|
 |
|