' =========================
' 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
Last edited by robleyd on Mon May 14, 2018 8:19 am, edited 1 time in total.
Reason:Tagged [Solved] [robleyd, Moderator]
My first tip is:
Use the Styles (the Paragraph styles in this case) instead of the direct formatting properties.
You can predefine them in a template file, or you can create and apply a new paragraph style by macro too.
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
My Second tip is:
Download, install, and use one of the object inspection tools like the MRI and the XrayTool. They can list all of the properties, methods, interfaces ... etc of the programming objects.
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
My third tip is:
Download, and study the Andrew Pitonyak's free macro books.
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
newstylename = "NewStyle" 'name for style
vStyle =ThisComponent.createInstance("com.sun.star.style.ParagraphStyle") 'get a style instance
with vstyle 'set properties
Set pspacing = .ParaLineSpacing
pspacing.height = 200
.ParaLineSpacing = pspacing
.CharFontName="Cambria"
end with
ThisComponent.StyleFamilies.getByName("ParagraphStyles").insertByName(newstylename,vStyle) 'add style to document
'set the style in the document with the viewcursor or a textcursor
oVC = thisComponent.getCurrentController.getViewCursor
oVC.parastylename = newstylename
for i = 0 to 100
st =st & "In new style "
next
oVC.string =st
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)