macro to set single line spacing + don't add spacing (style implementation breaks formatting)

When pasting RTF text with indentations into LO writer the text imports fine. Usually the text is copied from a powerpoint or PDF version of powerpoint which includes multiple line indentation parameters, which I wish to remove or set to 0/automatic. I can right-click on the newly imported text, select paragraph → paragraph and ensure that “Don’t add space between paragraphs of the same stvle” is ticked and line spacing is set to single.

Tried capturing these two setting changes in a paragraph style but it also resets all the indentations essentially ruining the formatting and structure of the text. Have to copy a lot of text and cannot do it all in one action. Tried capturing these settings into a paragraph style but applying the style seems to break the indentation so that everything is flush against the side of the margin.

Am wondering how to set these two options via a macro, which should get around this problem.

How can I set the following options via a macro?


paragraph options

  • “Don’t add space between paragraphs of the same stvle” is ticked
  • line spacing is set to single.

character options

set character spacing 0 - (character… → position tab → character spacing)

“RTF, Powerpoint, PDF” - in an ODF model. It is too much in same time.

The lots of versions of the obsolete RTF file format can not handle the Styles. It uses direct formatting properties.
Note: There is not (never was and never will be) 100% compatibility between the different file formats. You always will lose some formatting property when you convert (or move) a formatted text between different fil formats.

Always paste the text content as “unformatted text” from a foreign source into an ODF document. And then reformat the text by usage the Styles in the ODF document.

It is better to use the Styles instead of applying direct formatting properties by a macro. It is possible to do it by macro, but not the best solution. And you can create and apply custom styles (what contains the desired properties and options) by macro, too.

so if we have nested indentations, are these able to be set using a single style? or do I applying multiple styles in a hierarchy?

Please upload a manually formatted, ODF type sample file here - containing the formatted text pasted from the foreign sources.

rem - select text to apply to first, then run macro.

rem - Sets single line spacing + zero spacing between characters



sub Set_Single_LineSpacing

rem ----------------------------------------------------------------------

rem define variables

dim document as object

dim dispatcher as object

rem ----------------------------------------------------------------------

rem get access to the document

document = ThisComponent.CurrentController.Frame

dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)



rem ----------------------------------------------------------------------

dim args1(0) as new com.sun.star.beans.PropertyValue

args1(0).Name = “Spacing”

args1(0).Value = 0



dispatcher.executeDispatch(document, “.uno:Spacing”, “”, 0, args1())



rem ----------------------------------------------------------------------

dim args2(1) as new com.sun.star.beans.PropertyValue

args2(0).Name = “LineSpacing.Mode”

args2(0).Value = 0

args2(1).Name = “LineSpacing.Height”

args2(1).Value = 100



dispatcher.executeDispatch(document, “.uno:LineSpacing”, “”, 0, args2())



rem ----------------------------------------------------------------------

dim args3(4) as new com.sun.star.beans.PropertyValue

args3(0).Name = “TopBottomMargin.TopMargin”

args3(0).Value = 0

args3(1).Name = “TopBottomMargin.BottomMargin”

args3(1).Value = 0

args3(2).Name = “TopBottomMargin.ContextMargin”

args3(2).Value = true

args3(3).Name = “TopBottomMargin.TopRelMargin”

args3(3).Value = 100

args3(4).Name = “TopBottomMargin.BottomRelMargin”

args3(4).Value = 100



dispatcher.executeDispatch(document, “.uno:TopBottomMargin”, “”, 0, args3())



rem ----------------------------------------------------------------------

dim args4(0) as new com.sun.star.beans.PropertyValue

args4(0).Name = “NumberingStart”

args4(0).Value = false



dispatcher.executeDispatch(document, “.uno:NumberingStart”, “”, 0, args4())



rem ----------------------------------------------------------------------

dim args5(0) as new com.sun.star.beans.PropertyValue

args5(0).Name = “NumNewStartAt”

args5(0).Value = 65535



dispatcher.executeDispatch(document, “.uno:NumNewStartAt”, “”, 0, args5())





end sub