(GoLive und andere Webseitenprogramme zerschlagen die Formatierungen und setzen Tabs ein)
Gruß

Moderator: Moderatoren
Code: Alles auswählen
Function selection2Wiki
Dim selection as Object, oText as Object
Dim writerDoc as Object
Dim wiki as String
Dim elementCount as Integer
Dim oElement as Object
Dim oParagraphEnum as Object
Dim oParagraph as Object
Dim i as Integer
Dim sStyleName as String
' textportions variables
Dim oEnumeration as Object
Dim oPortion as Object
Dim sUrl as String
Dim sPortionString as String
Dim sElementString as String
' tables variables
Dim nRow as Integer
Dim sRow as String
Dim nIndex as Integer
Dim oCell as Object
Dim aCellNames as Variant
Dim bFirstInRow as Boolean
wiki = ""
writerDoc = ThisComponent
selection = writerDoc.getCurrentSelection()
' screen updates ausschalten
ThisComponent.lockControllers()
if ( Not IsNull( selection ) ) Then
elementCount = selection.count
oText = ThisComponent.Text
For i=0 to elementCount-1
oElement = selection.getByIndex( i )
If oElement.hasElements Then
oParagraphEnum = oElement.createEnumeration
while oParagraphEnum.hasMoreElements
oParagraph = oParagraphEnum.nextElement
' process paragraphs
if oParagraph.supportsService( "com.sun.star.text.Paragraph" ) Then
sStyleName = oParagraph.paraStyleName
if ( sStyleName = "Heading 1" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 2" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "==" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 3" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "===" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 4" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "====" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 5" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=====" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 6" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "======" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 7" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=======" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 8" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "========" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( sStyleName = "Heading 9" AND oParagraph.getString() <> "" ) Then
wiki = wiki & "=========" & oParagraph.getString() & chr(13) & chr(13)
Elseif ( ( sStyleName = "Text body" OR sStyleName = "Standard" ) AND oParagraph.getString() <> "" ) Then
' list or paragraph?
if oParagraph.NumberingIsNumber then
wiki = wiki & "*" & oParagraph.getString() & chr(13) & chr(13)
Else
'----------------------------------------------------------------------------------------
oEnumeration = oParagraph.createEnumeration
while ( oEnumeration.hasMoreElements )
oPortion = oEnumeration.nextElement
sUrl = oPortion.HyperlinkURL
sPortionString = oPortion.String
if sUrl <> "" AND sPortionString <> "" Then
wiki = wiki & "[" & sUrl & "|" & oPortion.getString() & "]"
Elseif sPortionString <> "" Then
wiki = wiki & oPortion.getString()
End If
Wend
wiki = wiki & chr(13) & chr(13)
'----------------------------------------------------------------------------------------
End if
Elseif ( sStyleName = "Code" ) Then
wiki = wiki & " " & oParagraph.getString() & chr(13)
Elseif ( oParagraph.getString() <> "" ) Then
MsgBox "unbekannter Style " & sStyleName
End if
Else oParagraph.supportsService( "com.sun.star.text.TextTable" )
' theres a bloody table
' we need variables !!
' init some stuff
nRow = 1
sRow = "0"
bFirstInRow = true
wiki = wiki & "||--" & chr(13)
aCellNames = oparagraph.getCellNames
for nIndex = LBound( aCellNames ) to UBound( aCellNames )
oCell = oParagraph.getCellByName( aCellNames( nIndex ) )
' be aware of new row!
sRow = Right( oCell.CellName, Len( oCell.CellName ) -1 )
if nRow < CInt(sRow) Then
' current cell is on new row
nRow = CInt(sRow)
' next row
wiki = wiki & chr(13)
bFirstInRow = true
Else
bFirstInRow = false
End If
' insert cell cell in wicki
if nRow = 1 Then
if Not( bFirstInRow ) Then
wiki = wiki & "-||-"
End If
wiki = wiki & oCell.String
else
wiki = wiki & "||" & oCell.String
End If
Next nIndex
wiki = wiki & chr( 13 ) & "--||" & chr( 13 ) & chr( 13 )
End If
Wend
End If
Next i
End If
' screen updates wieder einschalten
ThisComponent.unlockControllers()
selection2Wiki = wiki
End Function