[Solved] Can I merge sidebar comments into main text?

Discuss the word processor
Post Reply
linter
Posts: 5
Joined: Fri May 22, 2009 1:44 pm

[Solved] Can I merge sidebar comments into main text?

Post by linter »

so, i've got this doc that has a bunch of comments in the righthand sidebar with dotted-lines connecting them to the main text. but it's all incredibly confusing to me. i don't know what goes with what. it'd be much easier if the comments were placed right in the text where appropriate, maybe in a different color, if necessary.

is that possible? i'm working on something that has to be done in a hurry and i'm afraid i don't have time to learn a whole new way of doing things. perhaps later, but not now.

what do you think?
Last edited by Hagar Delest on Thu May 21, 2020 8:36 pm, edited 1 time in total.
Reason: tagged solved
OOo 2.3.X on MS Windows Vista
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: can i merge sidebar comments into main text?

Post by JeJe »

You can create a character style with a background color for this.

The following macro will create a character style called "CommentStyle" with a yellow background, and copy the text of the comments into the document in that style.

TO BE SAFE MAKE A COPY OF YOUR DOCUMENT FIRST BEFORE RUNNING.

Code: Select all


cs = thiscomponent.stylefamilies.getbyname("CharacterStyles")
ss=thiscomponent.createinstance("com.sun.star.style.CharacterStyle")
ss.charbackcolor =  rgb(255,255,20)
cs.insertbyname("CommentStyle",ss)

en =thiscomponent.textfields.createenumeration
tc = thiscomponent.text.createtextcursorbyrange(thiscomponent.text.start)
do until en.hasmoreelements = false
ff= en.nextelement
anch= ff.anchor
tc.gotorange(anch.end,false)
tc.string =ff.textrange.text.string
tc.charstylename = "CommentStyle"
loop


Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
linter
Posts: 5
Joined: Fri May 22, 2009 1:44 pm

Re: can i merge sidebar comments into main text?

Post by linter »

thank you for that. it'll merge the comments into the text, right?

now all i have to do is figure out macros!
OOo 2.3.X on MS Windows Vista
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: can i merge sidebar comments into main text?

Post by JeJe »

You have an ancient version of OO according to your signature. All I can do is go through what to do on my more up to date version as I don't have that old version. It may or may not be the same

Make a copy of your document, close all your others and open that.

Go to Tools menu/Macros/Organise Macros/Openoffice basic

In the dialog that pops up select the name of your document from the left side listbox and click the "New" button.

A popup box will ask you for the name of a module - just click on Okay.

You'll be taken to the macro area for your document where you'll find this:

REM ***** BASIC *****

Sub Main

End Sub
Copy and past the macro code I wrote above in between the sub main and end sub so it looks like this

Code: Select all

REM  *****  BASIC  *****

Sub Main
cs = thiscomponent.stylefamilies.getbyname("CharacterStyles")
ss=thiscomponent.createinstance("com.sun.star.style.CharacterStyle")
ss.charbackcolor =  rgb(255,255,20)
cs.insertbyname("CommentStyle",ss)

en =thiscomponent.textfields.createenumeration
tc = thiscomponent.text.createtextcursorbyrange(thiscomponent.text.start)
do until en.hasmoreelements = false
ff= en.nextelement
anch= ff.anchor
tc.gotorange(anch.end,false)
tc.string =ff.textrange.text.string
tc.charstylename = "CommentStyle"
loop
End Sub




When that's done press F5 to run the macro and see if the result is what you want.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Can I merge sidebar comments into main text?

Post by JeJe »

Slightly improved version makes sure the textfields are all comments in case you have other ones in the document:

Code: Select all


cs = thiscomponent.stylefamilies.getbyname("CharacterStyles")
if cs.hasbyname("CommentStyle") = false then
ss=thiscomponent.createinstance("com.sun.star.style.CharacterStyle")
ss.charbackcolor =  rgb(255,255,20)
cs.insertbyname("CommentStyle",ss)
end if

en =thiscomponent.textfields.createenumeration
tc = thiscomponent.text.createtextcursorbyrange(thiscomponent.text.start)
do until en.hasmoreelements = false
ff= en.nextelement
if ff.supportsService("com.sun.star.text.TextField.Annotation") then
anch= ff.anchor
tc.gotorange(anch.end,false)
tc.string =ff.textrange.text.string
tc.charstylename = "CommentStyle"
end if
loop

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
linter
Posts: 5
Joined: Fri May 22, 2009 1:44 pm

Re: Can I merge sidebar comments into main text?

Post by linter »

good golly that worked perfectly. what a life saver. i can't thank you enough. thank you!!!!
OOo 2.3.X on MS Windows Vista
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Can I merge sidebar comments into main text?

Post by JeJe »

If you want to change the color or hide/show them you just have to change the properties of the character style.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply