[Solved] Line Spacing in Writer
Posted: Sun May 13, 2018 8:47 am
Can someone please help with this?
Code: Select all
' =========================
' Line Spacing.vbs
' =========================
Dim arg()
Input1 = "I want this text written in larger Segoe Font characters and to be blue, " &_
"and the line spacing to be normal single line. "
Input2 = "This text will be written in italic with the Cambria font and in a size usual " &_
"for printed text, but with expanded (double) line spacing. The colour is a faded reddish " &_
"sandy brown. The problem here seems to be that to adjust line spacing you need to " &_
"control positioning of the view cursor because line spacing is a property of paragraph " &_
"styles, the creation of which seems to require application of the view cursor, but " &_
"bizarrely the view cursor ""knows nothing"" about which paragraph it is currently in; " &_
"this is apparently ""known"" only to the text cursor !!! So what happens when I try to " &_
"adjust line spacing is that all paragraphs get adjusted instead of this particular one. " &_
"I think that what I may be lacking is a method to create extra paragraph stylenames " &_
"as the one I'm using seems to behave as a default, so I then could apply specific style " &_
"names to specific paragraphs."
Input3 = "The final text will be written in smaller characters with the Segoe UI Semibold font " &_
"and coloured in a minty blueish-green. Line spacing here should return to normal"
Set oSM = CreateObject ("com.sun.star.ServiceManager")
Set oDsk = oSM.createInstance(_
"com.sun.star.frame.Desktop")
Set oDoc = oDsk.loadComponentFromURL( _
"private:factory/swriter", "_blank", 0, arg)
Set oViewCursor = oDoc.CurrentController.getViewCursor()
Set oParaStyles = oDoc.StyleFamilies.getByName("ParagraphStyles")
oParaStyleName = oViewCursor.ParaStyleName
Set oParaStyle = oParaStyles.getByName(oParaStyleName)
Set objText= oDoc.getText
Set objCursor= objText.createTextCursor
objCursor.CharHeight="15"
objCursor.CharColor = RGB(185,70,45)
objCursor.CharFontName="Segoe Print"
objText.insertString objCursor, Input1 , false
objCursor.gotoEndOfParagraph False
objText.insertControlCharacter oViewCursor, 0, False
objText.insertControlCharacter oViewCursor, 0, False
objCursor.CharHeight="13"
objCursor.CharPosture=1
objCursor.CharColor = RGB(10,110,205)
objCursor.CharFontName="Cambria"
objText.insertString objCursor, Input2 , false
oViewCursor.gotoRange objCursor, False
Set v = oParaStyle.ParaLineSpacing
v.height = 200
oParaStyle.ParaLineSpacing = v
objCursor.gotoEndOfParagraph False
objText.insertControlCharacter oViewCursor, 0, False
objText.insertControlCharacter oViewCursor, 0, False
objCursor.CharHeight="10"
objCursor.CharPosture=0
objCursor.CharColor = RGB(180,155,20)
objCursor.CharFontName="Segoe UI Semibold"
objText.insertString objCursor, Input3 , false