
xlsx2csv.rs
Rust CLI for Excel to CSV/TSV Conversion
Fast, Lightweight Command-Line Tool to Convert XLSX, XLS, ODS, XLSM & XLSB to CSV/TSV with Sheet Filtering & Batch Export.
What is xlsx2csv.rs?
xlsx2csv.rs is a high-performance, dependency-light Rust command-line utility designed to convert Excel spreadsheet files into structured CSV or TSV formats. It supports a wide range of Excel formats including XLSX, XLS, XLSB, XLSM, and ODS, making it ideal for data engineers and developers seeking a fast, reliable, and cross-platform conversion tool. The tool emphasizes simplicity and speed, requiring no external dependencies beyond the Rust standard library and minimal runtime overhead, while delivering robust functionality through intuitive CLI flags and options.
With features like regex-based sheet filtering, per-sheet output control, automatic filename generation using sheet names, and support for custom delimiters, xlsx2csv.rs caters to both simple one-off conversions and complex batch processing workflows. Its zero-config default behavior outputs the first sheet to stdout, enabling seamless integration into shell pipelines and CI/CD environments. As an open-source project hosted on GitHub, xlsx2csv.rs is actively maintained and optimized for performance, security, and ease of use across Linux, macOS, and Windows platforms.
Getting Started with xlsx2csv.rs
xlsx2csv.rs is a Rust CLI tool for converting Excel files to CSV/TSV. You can install it via Cargo using `cargo install xlsx2csv`, or build from source by cloning the [xlsx2csv.rs](https://github.com/zitsen/xlsx2csv.rs) repository and running `cargo build --release`. The tool requires no external runtime dependencies and compiles to a standalone binary. Once installed, simply run `xlsx2csv input.xlsx` to convert the first sheet to stdout, or specify output filenames to export multiple sheets individually. Its minimal CLI design ensures quick onboarding and seamless integration into shell scripts and CI/CD pipelines.
Install xlsx2csv.rs via Cargo
cargo install xlsx2csvConvert Specific Sheets to CSV
xlsx2csv.rs gives developers precise control over sheet selection. You can specify output filenames for individual sheets in the order they appear in the Excel file. For example, `xlsx2csv report.xlsx sales.csv finance.csv` exports the first two sheets to separate CSV files, ignoring the rest. If you need to output a specific sheet to stdout (e.g., for piping), use the `-s` or `--select` flag with either the 0-based sheet index or the sheet name. This enables flexible data extraction without loading unnecessary sheets into memory, making it efficient for large workbooks with dozens of sheets. The tool also supports selecting sheets by name, which is especially useful when sheet order may vary across files.
Export Specific Sheets via CLI
# Export first sheet to stdout
xlsx2csv data.xlsx > first.csv
# Export second sheet by index (0-based)
xlsx2csv data.xlsx -s 1 > second.csv
# Export by sheet name
xlsx2csv data.xlsx -s "Q3 Results" > q3.csvBatch Export Sheets with Regex Filtering
For large Excel files with many sheets, xlsx2csv.rs enables intelligent batch export using regex patterns. The `-I/--include` and `-X/--exclude` flags let you filter sheets by name before processing, supporting case-insensitive matching via `-i/--ignore-case`. For instance, `xlsx2csv report.xlsx -I 'Sales.*' -X 'Total'` exports only sheets starting with "Sales" but excluding those containing "Total". This is invaluable for automating reports where sheet naming conventions are consistent but variable. Combined with `-u/--use-sheet-names`, the tool automatically generates output filenames based on sheet names (e.g., `Sales_January.csv`), reducing manual effort and minimizing naming errors in automated workflows.
Filter and Export Sheets by Name Pattern
# Include only sheets matching pattern
xlsx2csv data.xlsx -u -I '^\d{4}_Report$'
# Exclude sheets with spaces in names
xlsx2csv data.xlsx -u -X '\s' -i
# Include first, then exclude
xlsx2csv data.xlsx -u -I '.*' -X 'Template'Custom Delimiters and Output Formats
xlsx2csv.rs supports configurable delimiters for output, allowing CSV or TSV generation with a single flag. Use `-d ,` for comma-separated values (default) or `-d \t` for tab-separated values. When combined with `-u/--use-sheet-names`, the delimiter determines the file extension: `,` yields `.csv`, `\t` yields `.tsv`, and other delimiters default to `.csv`. This flexibility is essential for downstream tools expecting specific formats. Additionally, you can direct output to a custom directory using `-w/--workdir`, enabling organized batch exports without post-processing file moves. This makes xlsx2csv.rs ideal for ETL pipelines where data must be transformed and staged in standardized formats.
Export with Custom Delimiter and Workdir
# Export sheets as TSV to ./output/
xlsx2csv data.xlsx -u -d '\t' -w ./output/
# Export first sheet as TSV to stdout
xlsx2csv data.xlsx -d '\t'List and Inspect Sheet Metadata
Before conversion, xlsx2csv.rs allows quick inspection of sheet structure via the `-l/--list` flag. Running `xlsx2csv -l data.xlsx` prints all sheet names with their 0-based IDs, helping you verify sheet order and names without opening the file. This is especially useful when working with unfamiliar workbooks or validating automated export scripts. The output format is simple and parseable, making it suitable for scripting. Combined with `-s/--select`, you can programmatically target sheets by ID or name, enabling robust, error-resistant batch processing in CI/CD environments where manual intervention is undesirable.
List Sheet Names and IDs
# List all sheets with IDs
xlsx2csv -l data.xlsx
# Output:
# 0: Sales
# 1: Finance
# 2: Q3 Summary