Linux: Convert xlsx to csv in Linux with command line
Linux: Convert xlsx to csv in Linux with command line
The Gnumeric spreadsheet application comes with a command line utility called ssconvert that can convert between a variety of spreadsheet formats:
$ ssconvert Book1.xlsx newfile.csv Using exporter Gnumeric_stf:stf_csv $ cat newfile.csv Foo,Bar,Baz 1,2,3 123.6,7.89, 2012/05/14,, The,last,Line
To install on Ubuntu:
apt-get install gnumeric
To install on Mac:
brew install gnumeric
Try libre office
libreoffice --headless --convert-to csv $filename --outdir $outdir
For reasons not clear to me, you might need to run this with sudo. You can make LibreOffice work with sudo without requiring a password by adding this line to you sudoers file:
users ALL=(ALL) NOPASSWD: libreoffice
5 Methods to Convert xlsx Format Files to CSV on Linux CLI. XLSX is a file extension for an open XML spreadsheet file format used by MicrosoftExcel.Converting Microsoft Excel sheet to a Comma Separated file (CSV) is relatively very easy while using command line.
1
|
libreoffice --headless --convert-to csv $filename --outdir $outdir |
For reasons not clear to me, you might need to run this with sudo. You can make LibreOffice work with sudo without requiring a password by adding this line to you sudoers file:
1
|
users ALL=(ALL) NOPASSWD: libreoffice |
Another option would be to use R via a small bash wrapper for convenience:
xlsx2txt(){
echo '
require(xlsx)
write.table(read.xlsx2(commandArgs(TRUE)[1], 1), stdout(), quote=F, row.names=FALSE, col.names=T, sep="\t")
' | Rscript --vanilla - $1 2>/dev/null
}
xlsx2txt file.xlsx > file.txt
The Gnumeric spreadsheet application comes with a command line utility called ssconvert that can convert between a variety of spreadsheet formats:
$ ssconvert Book1.xlsx newfile.csv
Using exporter Gnumeric_stf:stf_csv
$ cat newfile.csv
Foo,Bar,Baz
1,2,3
123.6,7.89,
2012/05/14,,
The,last,Line
To install on Ubuntu:
apt-get install gnumeric
To install on Mac:
brew install gnumeric