11

I'm working with an ODS file in LibreOffice, and every now and then I want to convert it to CSV from the command line. I have found two tools for this: libreoffice --headless --convert-to csv and unoconv -f csv but none of them works when there is an UI instance of LibreOffice running.

Is there a way to convert an ODS file to CSV from the command line, while LibreOffice UI instance is running?

foolo
  • 804
  • 12
  • 22
  • @tohuwawohu No, I don't receive any error messages because both `libreoffice --headless` and `unoconv` are working as designed. They are not designed to work on the same time as LibreOffice UI is running. – foolo Oct 29 '20 at 15:06

2 Answers2

11

To convert csv on the command line while LibreOffice is running, just skip the --headless parameter. The following command (run in PowerShell) worked for me even while C:\TEMP\Untitled1.ods resp. /tmp/Untitled1.ods was opened in LibreOffice Calc:

Windows 10 (tested with LibreOffice 7.0.1)

& 'C:\Program Files\LibreOffice\program\soffice.exe' --convert-to csv --outdir C:\TEMP\ .\Untitled1.ods

Or similar, if the present working directory is C:\Program Files\LibreOffice\program\:

.\soffice --convert-to csv --outdir C:\TEMP\ C:\TEMP\Untitled1.ods

Linux (tested with LibreOffice 6.4.6)

soffice --convert-to csv --outdir /tmp/ /tmp/Untitled1.ods

On linux, you could alternatively use the libreoffice command instead of soffice (seems to be linux-specific...):

libreoffice --convert-to csv --outdir /tmp/ /tmp/Untitled1.ods

In all cases, Untitled.csv was created in the expected place.

tohuwawohu
  • 13,268
  • 4
  • 42
  • 61
  • 2
    Ahh, the docs of the --headless parameter is: *"Starts in "headless mode", which allows using the application without user a interface."* (These are the exact words :) ) – foolo Oct 30 '20 at 18:17
  • 3
    And even more interesting: The description of the `--convert-to` flag is: *"(...) It implies --headless."* – foolo Oct 30 '20 at 20:13
  • 2
    Note the & prefix on Windows if using powershell. This is not necessary if using the "old" Command Prompt. – Victor Chelaru Jan 22 '23 at 15:26
1

Tested with MacOS :

/Applications/LibreOffice.app/Contents/MacOS/soffice --convert-to csv myspread.ods 

This wrote out myspread.csv in the same directory

johng
  • 11
  • 1