OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Copy and paste formatting.

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
manxduke
General User
General User


Joined: 07 Mar 2006
Posts: 21
Location: Isle of Man

PostPosted: Thu Nov 18, 2010 1:21 am    Post subject: Copy and paste formatting. Reply with quote

I frequently use my scanner and ocr software to copy old documents, and equally I copy and paste from the web. Depending on the original layout, I usually then spend time with a series of " END, Rt arrow, backspace, spacebar" key presses, and alternatively, "down arrow,right arrow, backspace, spacebar" as appropriate.
Is there a simple way of formatting the text without the above rigmarole? Not a problem with just one side, but when a lengthy document, a real pain, especially for a one-finger operator who then needs to check everything.
I suspect somebody will suggest some "macros" , but whilst I have heard of them, I have never used them and would need to be "lead by the nose" for success.
Any advice please?
Back to top
View user's profile Send private message Send e-mail
swingkyd
OOo Advocate
OOo Advocate


Joined: 15 Sep 2004
Posts: 479

PostPosted: Thu Nov 18, 2010 8:17 pm    Post subject: Reply with quote

IF you are not concerned about retaining formatting, I'd recommend a good text editor like: Notepad++
You can select the whole area with the mouse and press <Ctrl>+<J> and then cut and past into Writer for formatting.
It would be simpler. If you use Linux, than most editors will do. YMMV
Back to top
View user's profile Send private message
John_Ha
General User
General User


Joined: 05 Dec 2005
Posts: 34

PostPosted: Mon Nov 22, 2010 5:52 am    Post subject: Removing "soft" carriage returns with find and rep Reply with quote

If you switch on the non-printing characters (View > Non printing characters) you will see that the culprit is a soft carriage return - it looks like an arrow which starts downwards, then turns backwards. You can add soft return to a document by typing Shift/Return instead of Return.

A soft return looks a bit like <-| without the descender. If you want plenty, copy some text out of an email.

The good news is that is is very easy to convert them all to spaces and you don't need to write a macro.

1 Edit > Find and Replace > More Options > tick Regular Expressions
2 in Find type \n
3 in Replace type a single space character
4 Replace all

and all soft carriage returns are replaced by spaces.

Notes:
1 Make sure you untick the Regular Expressions box and do a dummy search so that next time you search you will be looking for normal text!

A Regular Expression is a special expression where, in the Find field, \n means soft return. Switching on Regular expressions means OOo searches for the soft return and not for the two characters " \n ".

2 \n in Find is a Regular Expression for a soft return.

3 \n in Replace is the Regular Expression for a normal return (so if you put \n in Replace all soft returns will be converted to normal returns

3 Read the HELP in Find and Replace - it will show you all the Regular Expressions.

If you want a macro, the one below does it. Note it is in two parts - the first part makes the changes; the second part unticks the Regular Expressions tick box and does a dummy search for a space character to make sure the box is changed.

How can I copy this macro in to my OOo?

It is simplest to record your own macro.

To use this code, do it the simple way. Record a simple dummy macro - see Help - and save it as Fred.

Tools > macros > organise macros > and navigate to Fred

Highlight Fred > Edit

and just paste all the text below the end of Fred (Or replace Fred by it).

Code:
sub CR_to_SPACE
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(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 1
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 65536
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "\n"
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = " "
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 3
args1(18).Name = "Quiet"
args1(18).Value = true

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

rem ----------------------------------------------------------------------
dim args2(18) as new com.sun.star.beans.PropertyValue
args2(0).Name = "SearchItem.StyleFamily"
args2(0).Value = 2
args2(1).Name = "SearchItem.CellType"
args2(1).Value = 0
args2(2).Name = "SearchItem.RowDirection"
args2(2).Value = true
args2(3).Name = "SearchItem.AllTables"
args2(3).Value = false
args2(4).Name = "SearchItem.Backward"
args2(4).Value = false
args2(5).Name = "SearchItem.Pattern"
args2(5).Value = false
args2(6).Name = "SearchItem.Content"
args2(6).Value = false
args2(7).Name = "SearchItem.AsianOptions"
args2(7).Value = false
args2(8).Name = "SearchItem.AlgorithmType"
args2(8).Value = 0
args2(9).Name = "SearchItem.SearchFlags"
args2(9).Value = 65536
args2(10).Name = "SearchItem.SearchString"
args2(10).Value = " "
args2(11).Name = "SearchItem.ReplaceString"
args2(11).Value = " "
args2(12).Name = "SearchItem.Locale"
args2(12).Value = 255
args2(13).Name = "SearchItem.ChangedChars"
args2(13).Value = 2
args2(14).Name = "SearchItem.DeletedChars"
args2(14).Value = 2
args2(15).Name = "SearchItem.InsertedChars"
args2(15).Value = 2
args2(16).Name = "SearchItem.TransliterateFlags"
args2(16).Value = 1280
args2(17).Name = "SearchItem.Command"
args2(17).Value = 0
args2(18).Name = "Quiet"
args2(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args2())

end sub

_________________
John_Ha
Enthusiastic OO User
Back to top
View user's profile Send private message
manxduke
General User
General User


Joined: 07 Mar 2006
Posts: 21
Location: Isle of Man

PostPosted: Mon Nov 22, 2010 10:07 am    Post subject: Reply with quote

Thank you both for the above. Last night I downloaded notepad ++, and I will try that method this evening. After that, I will try the next suggestion. I will keep my fear of macros intact, unless neither of the other two methods works for me.
Regards, manxduke.
Back to top
View user's profile Send private message Send e-mail
swingkyd
OOo Advocate
OOo Advocate


Joined: 15 Sep 2004
Posts: 479

PostPosted: Tue Nov 23, 2010 11:08 am    Post subject: Reply with quote

View-> line endings in Notepad++ to determine if it's a soft carriage return (ie only CR and not CR LF). If so, you can use notepad++ to fix that too probably faster than dispatch calls.
Perhaps we can rewrite the dispatch code to more basic API Search/replace descriptors.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group