Data manipulation is the backbone of modern engineering, systems administration, and data analysis. While Microsoft Excel is the world's most ubiquitous spreadsheet editor, its graphical interface becomes a massive bottleneck when you need to automate workflows, process large batches of documents, or work on remote servers. If you are reading this, you are probably trying to figure out how to bridge the gap between heavy, formatting-rich ".xlsx" or ".xls" files and clean, lightweight, script-friendly ".csv" files.
Automating this transition is where the command line shines. Whether you are running a bash script on a headless Linux server, triggering a cron job, or building an ETL pipeline, knowing how to execute an excel to csv command line instruction is an essential skill.
In this complete guide, we will explore the 5 most reliable, high-performance ways to convert Excel spreadsheets to CSV and back again using the command line. We will cover cross-platform Python packages, headless office engines, Windows-centric PowerShell hacks, and lightweight Linux binaries. No matter your operating system or stack, you will leave with a copy-pasteable solution that works.
1. The Terminal Purist's Choice: csvkit (in2csv)
csvkit is an incredible suite of command-line utilities designed specifically for converting and working with CSV files. Built on Python, it is entirely cross-platform and operates with zero dependencies on Microsoft Excel or LibreOffice. Within this suite, the in2csv tool is widely considered the absolute gold standard when you want to convert excel to csv command line style.
Unlike Excel's native GUI exporter, which often introduces unpredictable formatting (such as adding thousands separators or arbitrary quotation marks), csvkit handles data programmatically. It preserves raw numeric values while keeping fields cleanly delimited.
Installing csvkit
Since csvkit is a Python-based utility, you can easily install it using pip. Open your command prompt, terminal, or PowerShell, and run:
pip install csvkit
(Note: If you are using Linux, you may also find it in your system package manager as sudo apt install csvkit or sudo dnf install csvkit.)
Basic Excel to CSV Conversion
To perform a basic conversion of a standard Excel workbook (.xlsx or .xls) to a CSV file, use the redirection operator (>) to stream the stdout output to a new file:
in2csv employee_data.xlsx > employee_data.csv
This is the simplest way to command line convert excel to csv. By default, if the Excel file contains multiple sheets, in2csv will convert the first sheet.
Inspecting and Converting Specific Sheets
What if your Excel workbook contains multiple tabs? Running blind conversions can result in missing data. First, query the sheet names inside the file without actually extracting them:
in2csv -n employee_data.xlsx
This will output a numbered list of all the sheets present in the workbook:
1: Overview
2: Q1_Sales
3: Q2_Sales
4: Archives
Once you know the name or the index of the sheet you want, use the --sheet flag to target it:
in2csv --sheet "Q1_Sales" employee_data.xlsx > q1_sales.csv
Or, target it by its 1-based index:
in2csv --sheet 2 employee_data.xlsx > q1_sales.csv
Advanced Performance Optimization
For massive Excel workbooks, csvkit can sometimes slow down because it performs type inference by default (attempting to identify date formats, booleans, and floats). If you are processing a highly structured dataset and want a raw, blazing-fast dump without type scanning, disable inference:
in2csv --no-inference employee_data.xlsx > raw_dump.csv
This command skips the parsing overhead and writes the data to the CSV exactly as it is stored, significantly reducing processing time on large files.
2. Headless Office Engines: LibreOffice (soffice)
If your server lacks Python but has a system-level office suite installed, LibreOffice is an incredibly powerful alternative. LibreOffice includes a command-line interface called soffice that allows you to run a full office engine in "headless" mode—meaning it operates completely in the background without launching a graphical user interface.
This is highly reliable because it leverages LibreOffice's robust file-parsing engines, making it incredibly resilient against weirdly formatted Excel files that crash script-based parsers.
The Basic Command
To convert a .xlsx workbook to a .csv file in your current directory, run:
soffice --headless --convert-to csv employee_data.xlsx
LibreOffice will generate a file named employee_data.csv in the same folder. You can also specify an output directory with the --outdir flag:
soffice --headless --convert-to csv employee_data.xlsx --outdir /path/to/output/
Advanced Configuration: Custom Delimiters and Encodings
By default, LibreOffice uses a comma as the delimiter. However, if your data contains commas and you need to generate a semicolon-delimited file or specify a UTF-8 encoding, you can pass filter options. The syntax uses a colon followed by the filter name and parameter strings:
soffice --headless --convert-to csv:"Text - txt - csv (StarCalc)":"59,34,UTF8,1" employee_data.xlsx
Let's break down the filter options string "59,34,UTF8,1":
- 59: The ASCII value for a semicolon (
;). (Use44for a comma, or9for a tab). - 34: The ASCII value for double-quotes (
") used as the text delimiter. - UTF8: The character encoding system.
- 1: Starts the export from the first row of the sheet.
Converting CSV Back to Excel
If you are looking for a csv to excel command line solution, LibreOffice is equally capable of doing the reverse. To convert a clean, flat CSV file into a fully formatted modern Excel .xlsx spreadsheet, use:
soffice --headless --convert-to xlsx:"Calc MS Excel 2007 XML" dataset.csv
This is a highly reliable way to convert csv to excel command line because LibreOffice automatically handles column types and constructs a valid Office Open XML structure that opens perfectly in any copy of Microsoft Excel.
Batch Converting an Entire Folder
If you have dozens of files to convert, you can loop through them using native shell scripting.
On Linux/macOS (Bash):
for file in *.xlsx; do
soffice --headless --convert-to csv "$file"
done
On Windows (Command Prompt):
for %f in (*.xlsx) do "C:\Program Files\LibreOffice\program\soffice.exe" --headless --convert-to csv "%f"
3. Windows Native Power: PowerShell and the ImportExcel Module
Many Windows system administrators resort to using the built-in COM object wrapper for Microsoft Excel. However, using New-Object -ComObject Excel.Application is a bad practice. It is extremely slow, requires MS Excel to be physically installed on the machine, and frequently leaves orphaned excel.exe processes running in your Task Manager, which can leak memory and crash production servers.
The modern, production-grade alternative is Doug Finke's widely popular, open-source PowerShell module: ImportExcel. This package reads and writes Excel files directly by manipulating the underlying XML schemas, meaning it requires zero Microsoft Office installations and works perfectly on headless Windows Server environments, Docker containers, or even PowerShell Core on Linux.
Installing ImportExcel
Open a PowerShell console as an Administrator and run:
Install-Module -Name ImportExcel -Force -Scope CurrentUser
Convert Excel to CSV via PowerShell CLI
With the module installed, converting a spreadsheet is as simple as piping the imported spreadsheet object straight to PowerShell's native CSV exporter:
Import-Excel -Path "C:\Data\monthly_report.xlsx" | Export-Csv -Path "C:\Data\monthly_report.csv" -NoTypeInformation -Encoding UTF8
This approach handles the parsing of the XML data seamlessly and dumps the output into a clean, standardized, UTF-8 encoded CSV.
Convert CSV to Excel via PowerShell CLI
To execute a convert csv to excel command line process, you simply reverse the pipeline. Read the flat data with PowerShell's native CSV cmdlet and pipe it straight into Export-Excel:
Import-Csv -Path "C:\Data\raw_data.csv" | Export-Excel -Path "C:\Data\formatted_report.xlsx" -TableStyle Medium2 -AutoSize
Note the two incredible flags we tacked onto the end of the command:
- -TableStyle Medium2: This automatically converts the plain data range into a stylized, alternate-row-shaded Excel Table.
- -AutoSize: This automatically calculates the cell width for every column based on the longest string, preventing those annoying
###column overflow errors when users open the sheet in Excel!
This is why ImportExcel is highly praised—it turns a flat, dull text file into a highly professional Excel sheet programmatically with zero hassle.
4. The Ultimate Flex Solution: Python Scripting (pandas + openpyxl)
When your business logic requires highly customized data formatting, custom error logging, or the integration of multiple source files, off-the-shelf command-line binaries might not suffice. In these situations, drafting a micro Python script that runs via the CLI is your strongest option.
Using the industry-standard libraries pandas and openpyxl, you can construct a resilient conversion script in under 10 lines of code.
Prerequisites
Install the required parsing libraries via pip:
pip install pandas openpyxl
Python Script: Excel to CSV CLI Utility
Create a file named excel_to_csv.py and write the following script:
import sys
import os
import pandas as pd
if len(sys.argv) < 2:
print("Usage: python excel_to_csv.py <input_excel_file> [output_csv_file]")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2] if len(sys.argv) > 2 else os.path.splitext(input_file)[0] + ".csv"
try:
# Read all sheets in the workbook
excel_sheets = pd.read_excel(input_file, sheet_name=None)
# If there is only one sheet, save it directly
if len(excel_sheets) == 1:
sheet_name = list(excel_sheets.keys())[0]
excel_sheets[sheet_name].to_csv(output_file, index=False, encoding='utf-8')
print(f"Successfully converted sheet '{sheet_name}' to {output_file}")
else:
# Save each sheet as a separate CSV file
base_name = os.path.splitext(output_file)[0]
for sheet_name, data in excel_sheets.items():
sheet_output = f"{base_name}_{sheet_name}.csv"
data.to_csv(sheet_output, index=False, encoding='utf-8')
print(f"Saved sheet '{sheet_name}' to {sheet_output}")
except Exception as e:
print(f"Error converting file: {e}")
sys.exit(1)
Now, you can execute this custom utility straight from your terminal:
python excel_to_csv.py raw_sales.xlsx clean_sales.csv
The script will cleanly export the single sheet, or gracefully output separate numbered/labeled files for each tab if your workbook contains multiple spreadsheets.
Python Script: CSV to Excel CLI Utility
Similarly, you can easily reverse the process to build a csv to excel command line script. Create csv_to_excel.py:
import sys
import os
import pandas as pd
if len(sys.argv) < 2:
print("Usage: python csv_to_excel.py <input_csv_file> [output_excel_file]")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2] if len(sys.argv) > 2 else os.path.splitext(input_file)[0] + ".xlsx"
try:
# Read the CSV file
data = pd.read_csv(input_file)
# Export to Excel using the openpyxl engine
with pd.ExcelWriter(output_file, engine='openpyxl') as writer:
data.to_excel(writer, index=False, sheet_name='Sheet1')
print(f"Successfully converted {input_file} to Excel workbook: {output_file}")
except Exception as e:
print(f"Error during conversion: {e}")
sys.exit(1)
Run it instantly from your shell:
python csv_to_excel.py records.csv records.xlsx
5. The Lightweight Linux Classic: Gnumeric (ssconvert)
For Linux power users who need extreme speed, minimal resource footprints, and simple dependency management (such as within ultra-slim Docker containers), ssconvert is an exceptional command-line tool. It comes bundled as part of the Gnumeric spreadsheet application package, a lightweight desktop spreadsheet tool.
Unlike heavy graphical applications, ssconvert is designed primarily to run headlessly from the console. It boasts incredibly fast execution times because it is compiled as a native C binary.
Installing ssconvert
On Debian/Ubuntu systems, install the tool via apt:
sudo apt update
sudo apt install gnumeric
On Red Hat/Fedora/CentOS systems:
sudo dnf install gnumeric
Basic Excel to CSV Conversion
To process an input spreadsheet, call ssconvert with your source file and the desired output filename. The application automatically infers the input and output formats based on the file extensions:
ssconvert monthly_audit.xlsx monthly_audit.csv
Because of its optimized C backend, this conversion executes in milliseconds, making it significantly faster than spinning up a JVM or loading Python's massive runtime environments.
Basic CSV to Excel Conversion
Converting the other way is just as trivial:
ssconvert dataset.csv dataset.xlsx
If you need to query the extensive array of exporters supported by ssconvert on your local system, run:
ssconvert --list-exporters
This is highly useful when you need to output legacy spreadsheet formats, highly optimized XML configurations, or strict ISO/IEC standard files.
Comparing Command-Line Methods: Which One is Right for You?
To help you choose the best option for your infrastructure, here is a breakdown of how these 5 solutions compare across speed, ease of installation, and system environment suitability:
| Method | Speed | Best For | Platform Support | No-Excel Dependency? | Multi-Sheet Support |
|---|---|---|---|---|---|
csvkit (in2csv) |
Medium | Data Analysts, Scripting pipelines | Cross-Platform (macOS, Windows, Linux) | Yes | Excellent (via CLI sheet targets) |
LibreOffice (soffice) |
Medium-Slow | Batch converting folders | Cross-Platform | Yes | Active sheet only (or via macros) |
PowerShell (ImportExcel) |
Fast | Windows SysAdmins, Server Automation | Windows (PowerShell Core supports Linux) | Yes | Excellent |
Python (pandas / openpyxl) |
Fast-Medium | Complex data cleaning, custom business logic | Cross-Platform | Yes | Highly customizable |
Gnumeric (ssconvert) |
Blazing Fast | Linux servers, Docker containers | Linux (primarily), macOS | Yes | Yes (exports tabs cleanly) |
Frequently Asked Questions (FAQ)
How do I command line convert excel to csv when my spreadsheet has multiple sheets?
Using csvkit's in2csv tool is the easiest way. First, query the list of sheets using in2csv -n file.xlsx. Then, convert a specific sheet by using the sheet name with in2csv --sheet "SheetName" file.xlsx > output.csv. If you are using Gnumeric's ssconvert, it can extract individual sheets cleanly as well.
Why do dates and large numbers change formats when I convert Excel to CSV?
This is a common issue caused by Excel's default formatting behavior or raw type inference of various tools. When using Python, pandas might read scientific notation or modify date structures. You can handle this in your Python scripts by specifying column-level datatypes with dtype=str or custom datetime parsers. In csvkit, disabling automatic type inference with the --no-inference or -I flag will prevent it from converting numbers into formats you don't want.
How do I convert a CSV back to Excel via command line?
You can use LibreOffice headless mode with soffice --headless --convert-to xlsx input.csv, use Python's pandas script, or run PowerShell with Import-Csv input.csv | Export-Excel output.xlsx if you are on Windows.
Can I batch-convert multiple folders of XLSX files in one command?
Yes. Using LibreOffice, you can pass a wildcard pattern: soffice --headless --convert-to csv *.xlsx. Alternatively, a simple Bash or Command Prompt loop can iterate through a directory and execute the tool of your choice on each file.
Conclusion
Moving away from manual clicks to automated, headless file conversion is one of the easiest ways to scale and optimize your technical pipelines. As we have seen, the best excel to csv command line solution depends entirely on your existing infrastructure.
- For lightweight, rapid data science pipelines,
csvkit(in2csv) or Python offer the most control. - For system administrators operating headless Windows servers, PowerShell and the
ImportExcelmodule deliver enterprise-grade performance without Microsoft Excel bloat. - For high-performance Linux microservices or Docker containers, Gnumeric's
ssconvertprovides raw native speed. - For robust, bulletproof batch processing across any format, LibreOffice's
sofficeheadless mode is unmatched.
Select the tool that integrates best with your tech stack, script the process, and never waste time manually saving-as spreadsheets again.




![How to Convert XLSX to CSV Without Opening [5 Fast Ways]](https://blog.assetly.work/image/covers/_generic/04.webp)



