How to open file in Libre Office and save this like .doc file?

libreoffice, python

Solution

According to `libreoffice` manual (as a command line utility) you don't need python for this, but `libreoffice` should directly support this:

--convert-to output_file_extension[:output_filter_name] [--outdir output_dir] file... Batch converts files. If --outdir is not specified then the current working directory is used as the output directory for the convertedfiles.

Examples:

--convert-to pdf *.doc

Converts all .doc files to PDFs.

--convert-to pdf:writer_pdf_Export --outdir /home/user *.doc

Converts all .doc files to PDFs using the settings in the Writer PDF export dialog and saving them in /home/user.

Id you need to process many files, you could write simple bash script like this:

for i in `find folder -type f -name *.lwp` ; do
    libreoffice --headless --convert-to doc:"MS Word 2003 XML" $i
done

More detail instructions on how to invoke this command here or in manual specified earlier.

And you can basically do the same invocation from python and `subprocess`:

import os
import os.path
import subprocess

for i in os.listdir( SOURCE_FOLDER):
    if not i.endswith( '.lwp'):
        continue

    path = os.path.join( SOURCE_FOLDER, i)
    args = ['libreoffice', '--headless', '--convert-to',
            'doc:"MS Word 2003 XML"', path]

    subprocess.call(args, shell=False)

Problem

How to open file in Libre Office and save this like .doc file? It is possible? (create script for this)

Original source