I'm looking for a way to convert xlsx files to csv files on Linux.
I do not want to use PHP/Perl or anything like that since I'm looking at processing several millions of lines, so I need something quick. I found a program on the Ubuntu repos called xls2csv but it will only convert xls (Office 2003) files (which I'm currently using) but I need support for the newer Excel files.
Any ideas?
The Gnumeric spreadsheet application comes with a command line utility called ssconvert that can convert between a variety of spreadsheet formats:
To install on Ubuntu:
To install on Mac:
If you are OK to run Java command line then you can do it with Apache POI HSSF's Excel Extractor. It has a
main
method that says to be the command line extractor. This one seems to just dump everything out. They point out to this example that converts to CSV. You would have to compile it before you can run it but it too has amain
method so you should not have to do much coding per se to make it work.Another option that might fly but will require some work on the other end is to make your Excel files come to you as Excel XML Data or XML Spreadsheet of whatever MS calls that format these days. It will open a whole new world of opportunities for you to slice and dice it the way you want.
As others said,
libreoffice
can convert xls files to csv. The problem for me was the sheet selection.This libreoffice Python script does a fine job at converting a single sheet to CSV.
Usage is:
The only downside (on my end) is that
--headless
doesn't seem to work. I have a LO window that shows up for a second and then quits.That's OK with me, it's the only tool that does the job rapidly.
If
.xlsx
file has many sheets,-s
flag can be used to get the sheet you want. For example:second_sheet.csv
would contain data of 2nd sheet inmy_file.xlsx
.