Ask Your Question

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

asked 2020-09-04 05:00:16 +0100

blashrkh gravatar image

updated 2020-09-21 23:06:44 +0100

Alex Kemp gravatar image

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)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2020-09-04 06:41:35 +0100

Zizi64 gravatar image

updated 2020-09-04 06:57:49 +0100

"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.

edit flag offensive delete link more


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?

blashrkh gravatar imageblashrkh ( 2020-09-04 10:15:49 +0100 )edit

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

Zizi64 gravatar imageZizi64 ( 2020-09-04 12:07:13 +0100 )edit

answered 2020-09-15 04:07:58 +0100

blashrkh gravatar image

updated 2020-09-15 04:13:25 +0100

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("")

rem ----------------------------------------------------------------------
dim args1(0) as new
args1(0).Name = "Spacing"
args1(0).Value = 0

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

rem ----------------------------------------------------------------------
dim args2(1) as new
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
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
args4(0).Name = "NumberingStart"
args4(0).Value = false

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

rem ----------------------------------------------------------------------
dim args5(0) as new
args5(0).Name = "NumNewStartAt"
args5(0).Value = 65535

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

end sub

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-09-04 05:00:16 +0100

Seen: 85 times

Last updated: Sep 15 '20