excelstream
🦀 High-performance Rust library for Excel import/export with streaming support
✨ Features
- 🚀 Streaming Read - Read large Excel files without loading entire content into memory
- 💾 Streaming Write - Write Excel files row by row with optimized memory usage
- ⚡ Fast Writer - Custom optimized writer 13-24% faster than rust_xlsxwriter for large datasets
- 🎯 Memory Constrained - Configurable memory limits for Kubernetes pods with limited resources
- 📊 Multi-format Support - XLSX, XLS, ODS
- 🔒 Type-safe - Leverage Rust's type system
- ⚡ Zero-copy - Minimize memory allocations
- 📝 Multi-sheet - Support multiple sheets in one workbook
- 🎨 Formatting - Basic cell formatting support
📦 Installation
Add to your Cargo.toml:
[]
= "0.1.0"
🚀 Quick Start
Reading Excel Files (Streaming)
use ExcelReader;
Writing Excel Files (Streaming)
use ExcelWriter;
High-Performance Writing (Fast Writer)
For maximum performance with large datasets (100K+ rows):
use FastWorkbook;
Performance: Fast Writer achieves 255K rows/sec (1M rows in 3.9 seconds), 13-24% faster than standard writer.
See Fast Writer Documentation for details.
Memory-Constrained Writing (For Kubernetes Pods)
For pods with limited memory (< 512MB), use auto memory configuration:
use create_workbook_auto;
Manual configuration for specific memory limits:
use FastWorkbook;
let mut workbook = new?;
// For pods < 512MB RAM
workbook.set_flush_interval; // Flush every 100 rows
workbook.set_max_buffer_size; // 256KB buffer
workbook.add_worksheet?;
// ... write data ...
workbook.close?;
Kubernetes deployment:
env:
- name: MEMORY_LIMIT_MB
value: "512"
See Memory-Constrained Guide for details.
Writing with Typed Values
use ExcelWriter;
use CellValue;
Multi-sheet workbook
use ExcelWriterBuilder;
📚 Examples
The examples/ directory contains detailed examples:
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 streamingfast_writer_test.rs- Fast writer performance benchmarkswriter_comparison.rs- Compare standard vs fast writermemory_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
Running examples:
# Create sample data first
# Read Excel file
# Streaming with large files
# Fast writer benchmarks
# Memory-constrained writing
MEMORY_LIMIT_MB=512
# Multi-sheet workbooks
🔧 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
new(path)- Create new writerwrite_row(data)- Write row with stringswrite_row_typed(cells)- Write row with typed valueswrite_header(headers)- Write header with formattingadd_sheet(name)- Add new sheetset_column_width(col, width)- Set column widthsave()- Save workbook to file
FastWorkbook (High Performance)
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
Memory Helpers
create_workbook_auto(path)- Auto-detect memory config from envcreate_workbook_with_profile(path, profile)- Use specific memory profileMemoryProfile::Low- For pods < 512MBMemoryProfile::Medium- For pods 512MB-1GBMemoryProfile::High- For pods > 1GB
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
The library is designed for high performance:
- Streaming I/O: Doesn't load entire file into memory
- Zero-copy where possible: Minimize allocations
- Iterator-based: Lazy evaluation, process only when needed
- Rust's ownership: Memory safety without runtime overhead
- Fast Writer: 13-24% faster than rust_xlsxwriter (255K rows/sec)
- Memory Constrained: Configurable for pods with limited RAM
Benchmarks
Standard vs Fast Writer (100K rows, 5 columns):
| Writer | Time | Speed | Memory |
|---|---|---|---|
| Standard | 491ms | 203K rows/s | ~300MB |
| Fast | 434ms | 230K rows/s | ~250MB |
| Improvement | -11.6% | +13.1% | -16.7% |
Fast Writer with different data (1M rows, 19 columns):
| Configuration | Time | Speed | Memory Peak |
|---|---|---|---|
| Default (1000 flush) | 9.9s | 101K rows/s | ~250MB |
| Balanced (500 flush) | 10.9s | 91K rows/s | ~150MB |
| Low memory (100 flush) | 10.5s | 95K rows/s | ~80MB |
See Performance Documentation for details.
📖 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 filesrust_xlsxwriter- Standard Excel writerzip- Custom fast writer ZIP handlingthiserror- Error handling
🚀 Production Ready
- ✅ Tested with 1M+ row datasets
- ✅ 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
- rust_xlsxwriter - Excel writer
📧 Contact
For questions or suggestions, please create an issue on GitHub.
Made with ❤️ and 🦀 by the Rust community