excelstream
🦀 High-performance Rust library for Excel import/export with streaming support
⚠️ BREAKING CHANGE in v0.2.0:
Removedrust_xlsxwriterdependency! ExcelWriter now uses custom FastWorkbook implementation for streaming with constant memory usage and 21-40% faster performance.
See MIGRATION_v0.2.0.md for migration guide.
✨ Features
- 🚀 Streaming Read - Read large Excel files without loading entire content into memory
- 💾 Streaming Write - Write millions of rows with constant ~80MB memory usage (NEW in v0.2.0!)
- ⚡ 21-40% Faster - ExcelWriter is now faster than rust_xlsxwriter (v0.2.0)
- 🎯 Typed Values - Write with proper data types for better Excel compatibility
- 🎯 Memory Constrained - Configurable flush intervals for memory-limited environments
- 📊 Multi-format Support - XLSX, XLS, ODS for reading
- 🔒 Type-safe - Leverage Rust's type system
- ⚡ Zero-copy - Minimize memory allocations
- 📝 Multi-sheet - Support multiple sheets in one workbook
- 🗄️ PostgreSQL - Database export examples included
📦 Installation
Add to your Cargo.toml:
[]
= "0.2"
🚀 Quick Start
Reading Excel Files (Streaming)
use ExcelReader;
Writing Excel Files (Streaming - v0.2.0)
use ExcelWriter;
v0.2.0 Changes:
- ✅ Streaming with constant ~80MB memory (was ~300MB in v0.1.x)
- ✅ 21-40% faster than rust_xlsxwriter
- ❌ Bold header formatting removed (will be added back in v0.2.1)
- ❌
set_column_width()is now a no-op (will be added back in v0.2.1)
Writing with Typed Values (Recommended)
For better Excel compatibility and performance, use typed values:
use ExcelWriter;
use CellValue;
Benefits of write_row_typed():
- ✅ Numbers are stored as numbers (not text)
- ✅ Booleans display as TRUE/FALSE
- ✅ Better type safety
- ✅ 40% faster than rust_xlsxwriter in v0.2.0
Direct FastWorkbook Usage (Maximum Performance)
For maximum performance, use FastWorkbook directly:
use FastWorkbook;
Performance (v0.2.0):
- ExcelWriter.write_row(): 36,870 rows/sec (+21% vs rust_xlsxwriter)
- ExcelWriter.write_row_typed(): 42,877 rows/sec (+40% vs rust_xlsxwriter)
- FastWorkbook direct: 44,753 rows/sec (+47% vs rust_xlsxwriter)
Memory-Constrained Writing (For Kubernetes Pods)
In v0.2.0, all writers use streaming with constant memory:
use ExcelWriter;
Memory usage in v0.2.0:
- Constant ~80MB regardless of dataset size
- Configurable flush interval and buffer size
- Suitable for Kubernetes pods with limited resources
Multi-sheet workbook
use ExcelWriterBuilder;
📚 Examples
The examples/ directory contains detailed examples:
Basic Usage:
basic_read.rs- Basic Excel file readingbasic_write.rs- Basic Excel file writingstreaming_read.rs- Reading large files with streamingstreaming_write.rs- Writing large files with streaming
Performance Comparisons:
three_writers_comparison.rs- Compare all 3 writer types (recommended!)write_row_comparison.rs- String vs typed value writingwriter_comparison.rs- Standard vs fast writer comparisonfast_writer_test.rs- Fast writer performance benchmarks
Advanced Features:
memory_constrained_write.rs- Memory-limited writing for podsauto_memory_config.rs- Auto memory configuration democsv_to_excel.rs- CSV to Excel conversionmulti_sheet.rs- Creating multi-sheet workbooks
PostgreSQL Integration:
postgres_to_excel.rs- Basic PostgreSQL exportpostgres_streaming.rs- Streaming PostgreSQL exportpostgres_to_excel_advanced.rs- Advanced async with connection pooling
Running examples:
# Create sample data first
# Read Excel file
# Streaming with large files
# Performance comparisons (RECOMMENDED)
# Memory-constrained writing
MEMORY_LIMIT_MB=512
# Multi-sheet workbooks
# PostgreSQL examples (requires database setup)
🔧 API Documentation
ExcelReader
open(path)- Open Excel file for readingsheet_names()- Get list of sheet namesrows(sheet_name)- Iterator for streaming row readingread_cell(sheet, row, col)- Read specific celldimensions(sheet_name)- Get sheet dimensions (rows, cols)
ExcelWriter (v0.2.0 - Streaming)
new(path)- Create new writerwrite_row(data)- Write row with stringswrite_row_typed(cells)- Write row with typed values (recommended)write_header(headers)- Write header row (no formatting in v0.2.0)add_sheet(name)- Add new sheetset_flush_interval(rows)- Configure flush frequency (NEW in v0.2.0)set_max_buffer_size(bytes)- Configure buffer size (NEW in v0.2.0)set_column_width(col, width)- No-op in v0.2.0 (will be restored in v0.2.1)save()- Save and finalize workbook
FastWorkbook (Direct Access)
new(path)- Create fast writeradd_worksheet(name)- Add worksheetwrite_row(data)- Write row (optimized)set_flush_interval(rows)- Set flush frequencyset_max_buffer_size(bytes)- Set buffer limitclose()- Finish and save file
Types
CellValue- Enum for cell values: Empty, String, Int, Float, Bool, DateTime, ErrorRow- Struct representing a row with index and cellsCell- Struct for a cell with position (row, col) and value
🎯 Use Cases
Processing Large Excel Files (100MB+)
// Streaming ensures only small portions are loaded into memory
let mut reader = open?;
let mut total = 0.0;
for row_result in reader.rows?
Exporting Database to Excel
let mut writer = new?;
writer.write_header?;
// Fetch from database and write directly
for record in database.query?
writer.save?;
Converting CSV to Excel
use File;
use ;
let csv = new;
let mut writer = new?;
for in csv.lines.enumerate
writer.save?;
⚡ Performance
v0.2.0 Performance (1M rows × 30 columns)
Tested with 1 million rows × 30 columns (mixed data types):
| Writer Type | Speed (rows/s) | vs rust_xlsxwriter | Memory Usage |
|---|---|---|---|
| rust_xlsxwriter direct | 30,525 | baseline (1.00x) | ~300MB (grows) |
| ExcelWriter.write_row() | 36,870 | +21% faster | ~80MB constant ✅ |
| ExcelWriter.write_row_typed() | 42,877 | +40% faster | ~80MB constant ✅ |
| FastWorkbook direct | 44,753 | +47% faster | ~80MB constant ✅ |
Key Improvements in v0.2.0:
- ✅ 21-47% faster than rust_xlsxwriter
- ✅ Constant ~80MB memory (was ~300MB with rust_xlsxwriter)
- ✅ Streaming - memory doesn't grow with dataset size
- ✅ No external dependencies for writing
Memory Usage Comparison
v0.1.x (using rust_xlsxwriter):
- Memory grows with data: ~300MB for 1M rows
- All data kept in memory until save()
v0.2.0 (using FastWorkbook):
- Constant memory: ~80MB regardless of rows
- Data written directly to disk
- Configurable flush intervals
Recommendations
| Use Case | Recommended Writer | Performance |
|---|---|---|
| General use | ExcelWriter.write_row_typed() |
42,877 rows/s, typed values |
| Simple text | ExcelWriter.write_row() |
36,870 rows/s, easy to use |
| Maximum speed | FastWorkbook direct |
44,753 rows/s, low-level API |
| Need formatting | Use rust_xlsxwriter directly | 30,525 rows/s, full features |
📖 Documentation
- Quick Start Guide - Get started in 5 minutes
- Fast Writer Guide - High-performance writing
- Memory-Constrained Guide - For Kubernetes pods
- Optimization Summary - Performance details
- Contributing Guide - How to contribute
🛠️ Development
Build
Test
Run examples
Benchmark
📋 Requirements
- Rust 1.70 or higher
- Dependencies:
calamine- Reading Excel fileszip- ZIP compression for writingthiserror- Error handling
🚀 Production Ready
- ✅ Tested with 1M+ row datasets
- ✅ Streaming with constant memory usage
- ✅ 21-47% faster than rust_xlsxwriter
- ✅ Memory-safe with Rust's ownership
- ✅ Works in Kubernetes pods with limited resources
- ✅ Comprehensive error handling
- ✅ Zero unsafe code
- ✅ Validated Excel output (readable by Excel/LibreOffice)
🤝 Contributing
Contributions welcome! Please feel free to submit a Pull Request.
📄 License
MIT License - see LICENSE file for details.
🙏 Credits
This library uses:
- calamine - Excel reader
- Custom FastWorkbook implementation - High-performance writer (v0.2.0+)
Previous versions (v0.1.x) used rust_xlsxwriter - removed in v0.2.0 for better performance and streaming.
📧 Contact
For questions or suggestions, please create an issue on GitHub.
Made with ❤️ and 🦀 by the Rust community