Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Convert XLSX to CSV in Linux with Command Line in Linux
XLSX files are the standard format for modern Microsoft Excel spreadsheets, containing structured data organized in rows and columns. CSV (Comma-Separated Values) files are plain text files where data records are separated by commas, making them more portable and easier to process programmatically.
Converting XLSX to CSV in Linux can be accomplished using several command-line tools. This guide covers the two most effective methods: ssconvert from Gnumeric and libreoffice headless mode.
Method 1: Using Gnumeric ssconvert
The Gnumeric spreadsheet application includes a powerful command-line utility called ssconvert that handles various spreadsheet format conversions.
Installation
First, install Gnumeric on your system:
Ubuntu/Debian:
sudo apt-get install gnumeric
macOS (using Homebrew):
brew install gnumeric
Basic Conversion
Convert a single XLSX file to CSV using the following syntax:
ssconvert input_file.xlsx output_file.csv
Example:
ssconvert Sample_XLSX.xlsx Sample_CSVFile.csv
Output:
Using exporter Gnumeric_stf:stf_csv
Verify the conversion by examining the CSV content:
cat Sample_CSVFile.csv
1,"Eldon Base for stackable storage shelf, platinum",Muhammed MacIntyre,3,-213.25,38.94,35,Nunavut,Storage & Organization,0.8 2,"1.7 Cubic Foot Compact ""Cube"" Office Refrigerators",Barry French,293,457.81,208.16,68.02,Nunavut,Appliances,0.58 3,"Cardinal Slant-D? Ring Binder, Heavy Gauge Vinyl",Barry French,293,46.71,8.69,2.99,Nunavut,Binders and Binder Accessories,0.39 4,R380,Clay Rozendal,483,1198.97,195.99,3.99,Nunavut,Telephones and Communication,0.58
Method 2: Using LibreOffice Headless Mode
LibreOffice provides a headless mode that allows batch conversion without opening the GUI application.
Single File Conversion
libreoffice --headless --convert-to csv input_file.xlsx
Batch Conversion
Convert all XLSX files in the current directory:
for i in *.xlsx; do libreoffice --headless --convert-to csv "$i" ; done
Before and After Example
Before conversion:
immukul@192 cc % ls -ltr total 40 -rw-r--r--@ 1 immukul staff 5425 Jul 3 11:48 Sample_XLSX.xlsx
After conversion:
immukul@192 cc % ls -ltr total 56 -rw-r--r--@ 1 immukul staff 5425 Jul 3 11:48 Sample_XLSX.xlsx -rw-r--r-- 1 immukul staff 1247 Jul 3 12:15 Sample_XLSX.csv
Comparison
| Feature | ssconvert (Gnumeric) | LibreOffice Headless |
|---|---|---|
| Installation Size | Lightweight | Larger (full office suite) |
| Batch Processing | Manual scripting required | Built-in loop support |
| Format Support | Excel-focused | Extensive format support |
| Performance | Fast | Slower startup time |
Conclusion
Both ssconvert and LibreOffice headless mode provide reliable XLSX to CSV conversion in Linux. Choose ssconvert for lightweight, fast conversions, or LibreOffice for batch processing and broader format support. Both methods preserve data integrity while converting complex spreadsheet structures into simple comma-separated format.
