Joined: Dec 02, 2006 Posts: 1 Location: Tucson, AZ
Posted: Sat Dec 02, 2006 11:46 am Post subject: How to re-wrap imported text?
Every week I copy and paste a 10 page text file into Word and click AutoFormat and it re-wraps the text to fit my wide margins.
However, I wish to use NeoOffice now and am not finding a way to simply re-wrap the text. I imagine this is so simple and I am just missing it somehow.
Joined: May 25, 2003 Posts: 4752 Location: Santa Barbara, CA
Posted: Sat Dec 02, 2006 2:05 pm Post subject:
While I don't know of any autoformatting tools myself to "beautify" raw text that has embedded carriage returns, you can use the Find & Replace with regular expressions to turn carriage returns into spaces. Turn on regular expressions (More Options) and then search for "$" and replace with " " (no quotes in either). If you have some type of special character sequence separating your paragraphs like a heading style or something you could then do a second search and replace on that to reinsert carriage returns between paragraphs.
I'd suggest saving yourself a lot of anguish by doing the following:
* search for double CR (i.e. new paragraphs) and replace these by a placeholder.
* search for single CR and covert to spaces
* replace placeholder by CR
That way, your entire text does not turn into a sinle paragraph of wrapped text..
Best wishes,
Oscar _________________ "What do you think of Western Civilization?"
"I think it would be a good idea!"
- Mohandas Karamchand Gandhi
sub reWrap
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 --------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, Array())
I'm sure there's a much tidier way to do this using proper starbasic rather than dispatcher, but I haven't ever had time to learn that - whenever I try to write something in starbasic it doesn't work, sigh... anyway, I use the ± as a placeholder character because, let's face it, it's voted least likely to turn up in normal text.
Incidentally, I go about it this way (convert all CRs to something else, and *then* weed out the doubles) because depending on what kind of CRs you're dealing with, it can be hard to get Neo to find/replace double CRs, as the find/replace function is working on a 'per-paragraph' basis.
Joined: Jun 20, 2006 Posts: 2051 Location: Midwest, USA
Posted: Fri Apr 20, 2007 7:26 pm Post subject:
At the risk of betraying my ignorance....
I would really like to use this macro, but I can't for the life of me figure out how to enter the code in NeoOffice. I know how to record a macro, but not how to take written code and save it so Neo can access it as a macro.
I've looked in the help file and the User Guide section on Macros to no avail.
No doubt this is incredibly simple, and I'm just overlooking something.
go to Tools->Macros->Organise Macros->NeoOffice Basic... and then e.g. in My Macros-Standard-Module1 (it highights this by default) in the left panel, and Main highlighted in the right panel, click on Edit.
Then just paste the code in anywhere below the Main/End Sub lines - making sure you don't paste in the middle of any other macros you saved, so a couple of lines after Main's End Sub line is an obvious choice. Then hit Save and there it is.
Joined: Jun 20, 2006 Posts: 2051 Location: Midwest, USA
Posted: Sat Apr 21, 2007 5:13 am Post subject:
Thank you very much, yoxi. I knew it had to be simple, but I have to say that for someone like me who doesn't code at all, it was not an intuitive solution! (Not your fault, just the way OOo is.)
It worked perfectly, but it doing what you said, I discovered I already had a (different) macro there to remove the carriage returns. I must have downloaded and installed it from somewhere.
So, the "Main" category contains the code for all the macros in that Module, is that correct?
Sorry, when I posted the macro originally it didn't occur to me to explain how to add it in!
Yes, in the NeoOffice Basic window's right pane, the Module1 list will show Main and all other 'existing macros' added - I'm sure, if memory serves, that in previous versions this list sorted alphabetically, but now it appears to be in the order in which the macros appear within that module.
I have been chasing all over the net trying to do what I thought would be simple. I want to reformat text files in NeoOffice by finding Paragraph marks and replacing them with two paragraph marks. This is so the file will be easier to read on my ebook reader. (iRex Iliad)
Sometimes I also need to do a find/replace for a Paragraph mark and a manual line break, too. In addition, I usually like to replace a Paragraph mark followed by two or more spaces to indent the next paragraph. In those cases, I want two paragraph marks again.
None of the codes I have found for regular expressions seem to work. If I enter a ^$ for the mark, it doesn't like that. If I enter a plain $, it doesn't like that, either. If I enter the /n or /n/n in the replace field that's what it puts in the document.
I suspect I am not different from most when I say I would prefer not to enter all of these things manually. So, is there a solution?
Joined: May 25, 2003 Posts: 4752 Location: Santa Barbara, CA
Posted: Fri Mar 06, 2009 10:21 am Post subject:
Ah, to put in a newline, you should use a backslash, not a forward slash:
\n
That will translate to a newline.
Also, make sure that regular expressions are enabled. By default regular expression support in the find/replace dialog is disabled. You will need to enable it by clicking the "More Options" button and checking the regular expression checkbox.
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 You cannot attach files in this forum You cannot download files in this forum