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

AutoCorrect after pasting text.

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


Joined: 31 Jan 2006
Posts: 6
Location: Novo Hamburgo, RS, Brasil

PostPosted: Tue Jan 31, 2006 8:04 am    Post subject: AutoCorrect after pasting text. Reply with quote

I need a feature (which can be a macro or anything else) that helps me
autocorrecting some text when I past it into an OpenOffice.org Writer
document.
I tried OOo autocorrect function but it does only work when I type a
text, not when I paste text.
Ex.: I have some lines like those:
ALLOWED
NOT ALLOWED
NEEDS AUTHORIZATION
I want OOo to autocorrect them when I past them into a document, so
this text can look like:
USER IS ALLOWED, THE SYSTEM DOESN'T ALLOW THIS PERSON, HE NEEDS
AUTHORIZATION FOR THIS.

The example above is only an example; I will use a different and larger
amount of text and there's no pattern for those "corrections": each
text will be replaced by its own correct form. And the "returns" will
be replaced by ", " (comma and space).

Btw, I CANNOT install any kind of software on these computers we use, but it seems to me I can use macros with no problems.
Version of OOo installed: 1.9.128.

AugustoGabriel.
_________________
Augusto Gabriel Feyh
Back to top
View user's profile Send private message MSN Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Tue Jan 31, 2006 12:06 pm    Post subject: Reply with quote

Here is a macro example of how to do this type of thing. Please note that I have changed the searched for terms so they are unique otherwise you will get unexpected results, e.g., ALLOWED to @ALLOWED .
Code:
Sub ChangeStuff 'Using find & replace.
REM We need to to look for text that will not appear in the document
'after a search and replace has occured so the searched for words
'should be unique. 3 separate searches are preformed below.
REM Populate an array.
CurrentText() = Array("@ALLOWED","@NOT ALLOWED","@NEEDS AUTHORIZATION")
REM Another way to populate an array.
Dim Replace(2)
Replace(0) = "USER IS ALLOWED, " 
Replace(1) = "THE SYSTEM DOESN'T ALLOW THIS PERSON,"
Replace(2) = "HE NEEDS AUTHORIZATION FOR THIS."
oDoc = thisComponent
FandR = oDoc.createReplaceDescriptor
For i = lBound(CurrentText()) to uBound(CurrentText())
 FandR.setSearchString(CurrentText(i))
 FandR.setReplaceString(Replace(i))
 oDoc.ReplaceAll(FandR)
Next i
End Sub
Back to top
View user's profile Send private message
Bhikkhu Pesala
Super User
Super User


Joined: 23 Aug 2005
Posts: 2324
Location: Seven Kings, London, UK

PostPosted: Tue Jan 31, 2006 1:47 pm    Post subject: Reply with quote

Also have a look at Autotext. It might be easier to edit than a macro. Aftter pasting each abbreviation you press F3 to convert it to the long form, e.g. tyvm + F3 = Thank you very much for your letter of
_________________
Fonts * Opera * Oo Tips * FAQ * New Forum
Oo 2.3.1 * Win XP
Back to top
View user's profile Send private message Visit poster's website
augux
General User
General User


Joined: 31 Jan 2006
Posts: 6
Location: Novo Hamburgo, RS, Brasil

PostPosted: Wed Feb 01, 2006 8:46 am    Post subject: Reply with quote

Bhikkhu Pesala: I haven't tried your idea because it seems to me that it would only works with single words, but the text I paste into writer has spaces between words and even spaces after them... so I user JohnV's code.

JohnV: Your code worked, and I'm editing it so I can use it in my document. Thank you VERY much!
But, I still have two things to resolve:
1) The following line will become VERY large in my code:
Code:
CurrentText() = Array("@ALLOWED","@NOT ALLOWED","@NEEDS AUTHORIZATION")

Is there a way for me to use it in several lines? Using this part of the code in only one line will not be "easy-to-use"...

2) The original text has each item in a different line and there may be some spaces after each word, before the line break. E. g.:
FOOTBALL
SOCCER
VOLLEYBALL
And I want them in the same paragraph:
FOOTBALL, SOCCER, VOLLEYBALL

So, how can I replace "line breaks" to comma and space?
_________________
Augusto Gabriel Feyh
Back to top
View user's profile Send private message MSN Messenger
augux
General User
General User


Joined: 31 Jan 2006
Posts: 6
Location: Novo Hamburgo, RS, Brasil

PostPosted: Wed Feb 01, 2006 9:38 am    Post subject: Reply with quote

My first doubt of the last post has been solved: I just tried the second way to populate arrays that JohnV has posted!
_________________
Augusto Gabriel Feyh
Back to top
View user's profile Send private message MSN Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Wed Feb 01, 2006 1:44 pm    Post subject: Reply with quote

I thought there was a good reason to show two way to set up an array Wink

If I understand your second question you put the commas and spaces in the replacement text that goes in the Replace array (see my original post) or organize the actual document in a way that includes them as part of its text. As an example of the last of these lets say you have a document where you want two paragraphs as follows:
Not everyone can kick a football.
Not everyone can kick a football, head a soccer ball or spike a volley ball.
Then set it up as:
@F.
@F,<space>@S<space>@V.
Your Replace array would not contain any spacing or punctuation as you have provided it in the document. Note that this allows you to use @F as both a sentence and a phrase.

Hope this makes sense. Put another way, you can have the macro replace your shortcuts with text but you cannot expect it to organize or compose your document.
Back to top
View user's profile Send private message
augux
General User
General User


Joined: 31 Jan 2006
Posts: 6
Location: Novo Hamburgo, RS, Brasil

PostPosted: Sun Feb 05, 2006 4:37 pm    Post subject: Reply with quote

JohnV: in fact, I'll always have a text like this one:
@A
@B
@C

That should be replaced by something like:
Australia, Brazil, Canada,

But I'll always have several lines (avarage: 20), so I'd like this macro to ease my work, by replacing every occurance of a <line break> by <comma><space>.
As I see, OOo replace function doesn't support line breaks (or even tabs, but that's not what I need).
With my current macro, I organize the text right after I run the macro, by deleting those line breaks and writing those commas and spaces.
_________________
Augusto Gabriel Feyh
Back to top
View user's profile Send private message MSN Messenger
Gabor
Super User
Super User


Joined: 21 Sep 2003
Posts: 610
Location: Hungary (E-Europe)

PostPosted: Sun Feb 05, 2006 5:14 pm    Post subject: Try this Reply with quote

Code:
Function ChangeLinebreakToCommmaSpace
        dim odoc, oRD
        oDoc=thiscomponent
        oRD=oDoc.createReplaceDescriptor
        oRD.searchRegularExpression=TRUE
        oRD.setSearchString("\n")
        oRD.setReplaceString(", ")
        Zapall=oDoc.replaceall(oRD)
end function


Try to include this in your macro, this will change line breaks to commaspaces. If you include it in another macro the
dim odoc, oRD
must be commented out. I am far from being a macro expert, I think I took this one from A. C. Brown's fine macro doc.
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Mon Feb 06, 2006 5:33 am    Post subject: Reply with quote

To convert a vertical list of short cuts and have it replaced by a paragraph of text separated by <comma> and <space> you do much as Gabor has indicated. In your post you use the term "line break" but you may mean "paragraph break".

Add the following to my macro just above End Sub:
FandR.searchRegularExpression = true
FandR.setSearchString("\n") 'use ("$") for paragraph breaks
FandR.setReplaceString(", ")
oDoc.ReplaceAll(FandR)
Back to top
View user's profile Send private message
augux
General User
General User


Joined: 31 Jan 2006
Posts: 6
Location: Novo Hamburgo, RS, Brasil

PostPosted: Tue Feb 07, 2006 7:21 am    Post subject: Reply with quote

Thanks Gabor and JohnV... my English is not 100% yet, so sometimes I make some mistakes!
I'll try your last codes as soon as possible, then I'll post here if it goes successful!
_________________
Augusto Gabriel Feyh
Back to top
View user's profile Send private message MSN Messenger
augux
General User
General User


Joined: 31 Jan 2006
Posts: 6
Location: Novo Hamburgo, RS, Brasil

PostPosted: Tue Feb 07, 2006 7:30 am    Post subject: Reply with quote

Well, the code worked very fine.
Now I'm going to test it some more times and send it to other people of my company.
By the way, I work at Banco do Brasil S. A. (Bank of Brazil, Inc): www.bb.com.br
Thanks a lot for you help!
_________________
Augusto Gabriel Feyh
Back to top
View user's profile Send private message MSN Messenger
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