[Solved] Macro to change wrap to carriage return
-
harryspier
- Posts: 21
- Joined: Fri Feb 01, 2013 9:24 pm
[Solved] Macro to change wrap to carriage return
I need a macro to convert line wraps in an OpenOffice document to hard line breaks. If someone could show me how to do this, I'd greatly appreciate it. I found such a macro years ago, but somehow I lost all my macros when I upgraded to the new version of OpenOffice.
Many thanks in advance,
Harry Spier
Many thanks in advance,
Harry Spier
Last edited by MrProgrammer on Sun Nov 08, 2020 2:59 am, edited 1 time in total.
Reason: Tagged ✓ [Solved]
Reason: Tagged ✓ [Solved]
OpenOffice 3.4.1 Windows 8
Re: Macro to change wrap to carriage return
If I understand you correctly, you don't need a macro. You can use Edit -> Find & Replace and enter \n in both the Search For and Replace With box, click More Options and select Regular Expressions. Doing a Replace All should now replace all line breaks with paragraph breaks. Certainly try it on a copy of your document first, just in case.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
- Hagar Delest
- Moderator
- Posts: 33428
- Joined: Sun Oct 07, 2007 9:07 pm
- Location: France
Re: Macro to change wrap to carriage return
Try that macro: Convert ASCII text files by deleting extra paragraph breaks.
Please add '[Solved]' at the beginning of your first post title (edit button) if your issue has been fixed.
Please add '[Solved]' at the beginning of your first post title (edit button) if your issue has been fixed.
| Edit: Well, after seeing the following replies, I read more carefully the first post and I think that FJCC is right, the macro I've cited does the opposite in fact. |
LibreOffice 25.2 on Linux Mint Debian Edition (LMDE Faye) and 24.8 portable on Windows 11.
Re: Macro to change wrap to carriage return
It's really very interesting how difficult it is to discuss this kind of problem--the lack of any kind of standard vocabulary makes it just about impossible to have a meaningful discussion without going back and forth several times and everyone gets on the same page. Weird.
Anyway, I read the question completely differently. It sounds to me like harryspier is looking for the equivalent of pressing the keys: End, Enter, or maybe End, Shift+Enter. That is, convert paragraphs with lines wrapped to separate paragraphs or lines.
If you want paragraphs, you can come close with Edit > Find & Replace, and something like:
Search for: (.{50,70}) +
Replace with: $1\n
Options: Regular expressions: ON
Click "Replace all"
If you want line breaks at the end of each line, then it's a bit tricky because you have to enter a lliteral newline character into the "replace" box, and that isn't possible on all platforms.
Anyway, I read the question completely differently. It sounds to me like harryspier is looking for the equivalent of pressing the keys: End, Enter, or maybe End, Shift+Enter. That is, convert paragraphs with lines wrapped to separate paragraphs or lines.
If you want paragraphs, you can come close with Edit > Find & Replace, and something like:
Search for: (.{50,70}) +
Replace with: $1\n
Options: Regular expressions: ON
Click "Replace all"
If you want line breaks at the end of each line, then it's a bit tricky because you have to enter a lliteral newline character into the "replace" box, and that isn't possible on all platforms.
AOO4/LO5 • Linux • Fedora 23
Re: Macro to change wrap to carriage return
I read it as FJCC did. If this situation occurs regularly then the macro Hagar cites may be appropriate, otherwise the F&R methd from FJCC is best. On the rare occasion I need to do this, I use the F&R method.
| Edit: If I need to turn line feeds into Paragraph marks as a step to making proper paragraphs, where the paragraphs are delimited by paragraph marks but the lines by line feeds, it may be best to turn the line feeds into spaces (replace the second \n with a space character), and the job is done. |
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
-
harryspier
- Posts: 21
- Joined: Fri Feb 01, 2013 9:24 pm
Re: Macro to change wrap to carriage return
To clarify what I'm looking for. I OpenOffice writer if I enter a long paragraph without any hard (enter key) or soft (shift enter key) until the end of the paragraph then OpenOffice will wrap the text at the margins and when I open it again in OpenOffice it still looks the way I typed it in. But I need something else. I need to put in hard breaks everywhere that OpenOffice wraps the text due to the margins. This is so I can take the document (which can be several hundred pages) and display it correctly on the web, otherwise each paragraph is displayed as a single very very long line.
I had found a macro to do this several years ago, but when I upgraded to OpenOffice 3.4.1 somehow all my macros disappeared. So if someone can show me how to do this with a macro I'd appreciate it. (On the web somewhere, someone suggested doing a find and replace (using regular expressions) of \n with \n but this didn't work . Also In Microsoft word you can save with cr&lf option and that does it.)But I think that in OpenOffice you need to write a macro for this.
Thanks,
Harry Spier
I had found a macro to do this several years ago, but when I upgraded to OpenOffice 3.4.1 somehow all my macros disappeared. So if someone can show me how to do this with a macro I'd appreciate it. (On the web somewhere, someone suggested doing a find and replace (using regular expressions) of \n with \n but this didn't work . Also In Microsoft word you can save with cr&lf option and that does it.)But I think that in OpenOffice you need to write a macro for this.
Thanks,
Harry Spier
OpenOffice 3.4.1 Windows 8
- Hagar Delest
- Moderator
- Posts: 33428
- Joined: Sun Oct 07, 2007 9:07 pm
- Location: France
Re: Macro to change wrap to carriage return
OK, this is clear now.
I don't recall such topics here about that.
In the custom search engine in the forum landing page (http://forum.openoffice.org/) I've found 2 possibly relevant topics but in the oooforum that is down right now it seems:
- https://www.google.com/url?q=http://www ... 7C-ixAyCQg
- https://www.google.com/url?q=http://www ... SBnwkWqiFQ
I don't recall such topics here about that.
In the custom search engine in the forum landing page (http://forum.openoffice.org/) I've found 2 possibly relevant topics but in the oooforum that is down right now it seems:
- https://www.google.com/url?q=http://www ... 7C-ixAyCQg
- https://www.google.com/url?q=http://www ... SBnwkWqiFQ
LibreOffice 25.2 on Linux Mint Debian Edition (LMDE Faye) and 24.8 portable on Windows 11.
- MrProgrammer
- Moderator
- Posts: 5318
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Macro to change wrap to carriage return
Yours is an interesting question. I've found a way to do it without an evil macro. Set Edit > Selection Mode > Block Area. Then select the text. On OOo 3.2 on Mac OS X it can be difficult to do this with the keyboard, and using the mouse seems to work better. Use Edit > Copy. Then, when you paste this selected text somewhere, each line will be terminated with a paragraph break.harryspier wrote: I need to put in hard breaks everywhere that OpenOffice wraps the text due to the margins.
If this answered your question please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
Re: Macro to change wrap to carriage return
How are you putting the document on the web?harryspier wrote:... I need to put in hard breaks everywhere that OpenOffice wraps the text due to the margins. This is so I can take the document (which can be several hundred pages) and display it correctly on the web, otherwise each paragraph is displayed as a single very very long line. ...
If you export the document as html, each Writer paragraph converts to an html paragraph, which should be exactly what you want: the html paragraph will be automatically wrapped by the browser at whatever window size is displaying the page.
Adding explicit breaks to avoid long lines should not be necessary.
AOO4/LO5 • Linux • Fedora 23
-
harryspier
- Posts: 21
- Joined: Fri Feb 01, 2013 9:24 pm
Re: Macro to change wrap to carriage return
Unfortunately its not as simple as that. Its a digital library application where there are thousands of text documents, with extension .txt, so when the documents are displayed there is no wrapping until it finds an end of line character. They are displayed as text not html documents because they are designed to be downloaded as well as viewed and they are also the data for an integrated search engine that does a "search on files" function on them, so to change them to html would mean redesigning the whole digital library software.
OpenOffice 3.4.1 Windows 8
-
harryspier
- Posts: 21
- Joined: Fri Feb 01, 2013 9:24 pm
Re: Macro to change wrap to carriage return
Is there an official place to ask for "new features" for OpenOffice. What I'm trying to simulate is the "save with cr&lf" feature of Microsoft Word, which seems a useful enhancement for OpenOffice.
OpenOffice 3.4.1 Windows 8
Re: Macro to change wrap to carriage return
Can you post a small sample of your text, please?
[Forum] How to attach a document here
I cannot (at present) understand how OpenOffice wraps your lines at a place that is acceptable to you, as text wrapping normally depends on the page width/margin settings (and other controls). Is it that each unit is continuous unbroken text, terminated by a space, and OpenOffice wraps on that space? If so, it is trivially easy to turn the spaces into hard paragraph marks with Find and Replace. A sample would help.
[Forum] How to attach a document here
I cannot (at present) understand how OpenOffice wraps your lines at a place that is acceptable to you, as text wrapping normally depends on the page width/margin settings (and other controls). Is it that each unit is continuous unbroken text, terminated by a space, and OpenOffice wraps on that space? If so, it is trivially easy to turn the spaces into hard paragraph marks with Find and Replace. A sample would help.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
Re: Macro to change wrap to carriage return
I'm almost sure that there is already a request for export to nicely-formatted plain text, but I can't find anything in the issue database.
If you want to submit something, see [Tutorial] Reporting bugs or suggestions
You may be able to get what you want by a two-stage process: export from OOo to html (or xhtml), then use a separate application to convert the html (or xml) to text. I'm sure there are batch converters for the second step.
If you want to submit something, see [Tutorial] Reporting bugs or suggestions
You may be able to get what you want by a two-stage process: export from OOo to html (or xhtml), then use a separate application to convert the html (or xml) to text. I'm sure there are batch converters for the second step.
AOO4/LO5 • Linux • Fedora 23
Re: Macro to change wrap to carriage return
This is an old thread but I've been wanting this, so here is my solution in case anyone else needs it. It won't handle paragraph style and indent changes resulting from inserting the returns - that would need more code depending on how you wanted to handle those.
May also be issues with hyphenation.
May also be issues with hyphenation.
Code: Select all
Sub WrapToCarriageReturns 'issues with paragraphs styles and indents, space before etc. not dealt with
dim oDoc, oVC,oText
on error goto hr
oDoc = thiscomponent
oDoc.lockControllers
oVC = oDoc.getCurrentController.getViewCursor
oText = oDoc.text
oVC.gotostart(false)
While oText.compareRegionEnds(oVC.End, oText.End) <> 0
oVC.gotoEndofLine(false)
oVC.goright(1,true)
if asc(oVC.string) <>13 then
oVC.collapseTostart
oVC.goleft(1,false)
oText.insertControlCharacter(oVC,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
' oText.insertControlCharacter(oVC,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
oVC.goright(1,true)
if oVC.string = " " then oVC.string = ""
else
oVC.collapseToend
end if
wend
hr:
oDoc.unlockControllers
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Macro to change wrap to carriage return
File > Export as PDF. Now copy everything from the PDF and paste it into a new document.harryspier wrote: I need to put in hard breaks everywhere that OpenOffice wraps the text due to the margins. This is so I can take the document (which can be several hundred pages) and display it correctly on the web, otherwise each paragraph is displayed as a single very very long line.
This works because PDF files do exactly what you want to do - they force End of paragraphs at the end of each line so that the document never spills lines and never runs lines together.
LO 6.4.4.2, Windows 10 Home 64 bit
See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.
Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.
Remember: Always save your Writer files as .odt files. - see here for the many reasons why.