Ich kopiere in meinem Makro den Inhalt eines Dokuments in ein neues Dokument, um dort durch Suchen/Ersetzen Diverses zu tun (Formatierungen werden durch sichtbare Formatcodes ersetzt). Funktioniert an sich tadellos, bis auf ein paar hartnäckige Details.
Beim Kopieren kommt Folgendes zum Einsatz:
Code: Alles auswählen
args1(0).Name = "SelectedFormat"
args1(0).Value = 51
Mit Value = 51 taucht allerdings ein anderes, ganz komisches Problem auf:
Wenn ich zB Text in Schriftgröße 10 durch <small>Text in Schriftgröße 10</small> ersetze, passiert bei dem dt. Anführungszeichen Folgendes
„<small>This is an 10 pt direct format paragraph.“</small>
Das heißt: Das Anführungszeichen "rutscht aus der Formatierung heraus"!!!
Ich hänge eine Demo.doc bei. Unten wäre mein Makro.
Ich hoffe, hier treibt sich ein Guru herum! Wäre toll!
Code: Alles auswählen
Sub test
Dim noargs()
Dim oFrame As Object
Dim oDoc2 As Object
Dim oFrame2 As Object
REM : COPY FULL CONTENT to a NEW DOCUMENT to do the work there
oFrame = ThisComponent.CurrentController.Frame
Dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Dispatcher.executeDispatch(oFrame, ".uno:SelectAll", "", 0, Array())
Dispatcher.executeDispatch(oFrame, ".uno:Copy", "", 0, Array())
sURL = "private:factory/swriter"
oDoc2 = StarDesktop.loadComponentFromURL(sURL,"_blank",0,noargs())
oFrame2 = oDoc2.CurrentController.Frame
Dispatcher.executeDispatch(oFrame2, ".uno:InsertPara", "", 0, Array())
Dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SelectedFormat"
args1(0).Value = 10
Dispatcher.executeDispatch(oFrame2, ".uno:ClipboardFormatItems", "", 0, args1())
REM : 10PT --> <small> ... </small>
Dim oDoc As Object
Dim oReplace As Object
Dim SrchAttributes(0) As New com.sun.star.beans.PropertyValue
Dim ReplAttributes(0) As New com.sun.star.beans.PropertyValue
oDoc = ThisComponent
oReplace = oDoc.createReplaceDescriptor
oReplace.searchAll=True
oReplace.SearchRegularExpression=True
oReplace.SearchString = ".*"
oReplace.searchStyles=True
oReplace.ReplaceString = "<small>&</small>"
SrchAttributes(0).Name = "CharHeight"
SrchAttributes(0).Value = 10
oReplace.SetSearchAttributes(SrchAttributes())
oDoc.replaceAll(oReplace)
End Sub