Ask Your Question

Feature Request: Save as Text with line breaks [closed]

asked 2017-11-08 04:20:31 +0200

Jay Michael gravatar image

updated 2017-11-08 10:30:08 +0200

floris v gravatar image

It should be possible to save a document (Writer; .odt) as Text such that the text file looks (as much as possible) like the document looked on the screen, or would have looked if printed. It may be that the only difference between what I currently get from "Save as..." Text, and what I want, is a hard line break at the end of every line that appears on the screen: I don't want each paragraph to be an arbitrarily long line in the text file, I want it to appear as a sequence of lines, broken exactly as they appeared when I was editing the document.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-19 17:49:38.244385


And what is your goal? Why not save to PDF?

gabix gravatar imagegabix ( 2017-11-08 07:27:51 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2017-11-08 11:54:11 +0200

librebel gravatar image

Hello @Jay Michael,

you could use the XLineCursor interface for this, for example just run the following method:

Sub Writer_Save_As_Text_With_LineBreaks( Optional oDoc as Object )
REM Exports Writer text lines to a text file.
REM The output file will be located in the same folder as the Writer document, or in the current directory.
REM <oDoc>  : [OPTIONAL] The Writer document whose lines to export; Default = current document.
    If IsMissing( oDoc ) Then oDoc = ThisComponent
    If oDoc.supportsService( "" ) Then

        Dim strPath As String
        If oDoc.hasLocation() Then
            strPath = oDoc.getLocation() & ".txt"
            strPath = curDir() & getPathSeparator() & oDoc.getTitle() & ".txt"
        End If

        Dim iOutputFile As Integer
        iOutputFile = Freefile()
        Open strPath For Output As #iOutputFile

        Dim oViewCursor as Object
        oViewCursor = oDoc.CurrentController.getViewCursor()
        oViewCursor.gotoStart( False )

            oViewCursor.gotoStartOfLine( False )
            oViewCursor.gotoEndOfLine( True )
            Print #iOutputFile, oViewCursor.getString()
        Loop While oViewCursor.goRight( 1, False )

        Close #iOutputFile

    End If
End Sub
edit flag offensive delete link more


I appreciate the effort you put into giving me a solution, but I'm not looking for help post-processing what LibreOffice currently produces. I thought this was the site to post a request for a new feature.

Should I be on another web site?

Jay Michael gravatar imageJay Michael ( 2017-11-12 02:21:45 +0200 )edit
librebel gravatar imagelibrebel ( 2017-11-12 07:02:30 +0200 )edit

answered 2017-11-08 10:18:04 +0200

Henk C. Meerhof gravatar image

In fact you want to go back to your old typewriter. The paragraph end, coded by typing [Enter] seems to give you a carriage return and line feed, but it signals the end of a paragraph, so I would not use it for anything else.

There is a solution though. You can use a 'soft return' by typing [Shift]+[Enter], this generates also a visible carriage return and line feed, but without the function of 'end of paragraph. This method will also work in many other editors.

Main question remains: Why do you want this. Copy send to printer or other editors will be stripped of this extra coding, and it will not be for free.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-11-08 04:20:31 +0200

Seen: 218 times

Last updated: Nov 08 '17