Ubuntu – Converting XSL files to CSV files in command line

command linelibreoffice

I have a set of XLS files which I want to convert to .CSV retaining the original base name. I found that this code worked best:

unoconv -f csv *.xls  

also there are other ways in this link converting xls to csv but I wanted to retain the same name.

After a while it showed me this error

Failed to connect to /usr/lib/libreoffice/program/soffice.bin (pid=7779) in 6 seconds.
Connector : couldn't connect to socket (Success)
Error: Unable to connect or start own listener. Aborting.

I have tried reinstalling but it does not work. I would like any help where I can retain the name of the xls file and convert it to csv. I am using this code in an R environment and accessing the system terminal.

Best Answer

I would start by closing LibreOffice. That has caused issues for me in the past with unoconv but it has been hard to predict. It's easiest to just let unoconv launch its own processing server. If you think you've done that but you're seeing the same error, run killall soffice.bin and try again.

In terms of retaining the same name, it does that by default.

unoconv -f csv filename.xls

That will create a filename.csv file. In my mind, this is really desirable because then you know the format of the file (and you won't try to do silly things by accident). And that works for wildcards too:

$ ls *.xls
ie_data.xls  QTL_Sample_data.xls  WBC_FTTC_Price_List_Entry_16-Aug-10.xls

$ unoconv -f csv *.xls 

$ ls *.csv
ie_data.csv  QTL_Sample_data.csv  WBC_FTTC_Price_List_Entry_16-Aug-10.csv

So you just need to get it up and running and it'll do what you want.