xlsxrb 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/README.md +71 -253
- data/Rakefile +2 -1
- data/benchmark.rb +3 -1
- data/docs/PEER_LIBRARIES.md +121 -0
- data/docs/assets/benchmark_results.svg +144 -0
- data/docs/assets/lsp_autocompletion.png +0 -0
- data/docs/assets/playground_preview.png +0 -0
- data/docs/visual/VisualGallery.md +183 -0
- data/docs/wasm/ruby.wasm +0 -0
- data/lib/xlsxrb/chart_builder.rb +333 -0
- data/lib/xlsxrb/elements/cell.rb +66 -12
- data/lib/xlsxrb/elements/workbook.rb +2 -2
- data/lib/xlsxrb/ooxml/reader/listeners.rb +6450 -0
- data/lib/xlsxrb/ooxml/reader.rb +2 -6438
- data/lib/xlsxrb/ooxml/workbook_writer.rb +297 -236
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +218 -266
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +127 -10
- data/lib/xlsxrb/ooxml/zip_writer.rb +31 -38
- data/lib/xlsxrb/stream_row.rb +34 -8
- data/lib/xlsxrb/stream_sheet.rb +119 -0
- data/lib/xlsxrb/stream_writer.rb +1733 -0
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +309 -0
- data/lib/xlsxrb/worksheet_builder.rb +691 -0
- data/lib/xlsxrb.rb +238 -2968
- data/sig/generated/xlsxrb/chart_builder.rbs +269 -0
- data/sig/generated/xlsxrb/elements/cell.rbs +137 -12
- data/sig/generated/xlsxrb/ooxml/reader/listeners.rbs +1074 -0
- data/sig/generated/xlsxrb/ooxml/reader.rbs +0 -1067
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +17 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +18 -4
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +4 -0
- data/sig/generated/xlsxrb/stream_row.rbs +6 -2
- data/sig/generated/xlsxrb/stream_sheet.rbs +100 -0
- data/sig/generated/xlsxrb/stream_writer.rbs +960 -0
- data/sig/generated/xlsxrb/workbook_builder.rbs +146 -0
- data/sig/generated/xlsxrb/worksheet_builder.rbs +349 -0
- data/sig/generated/xlsxrb.rbs +103 -1563
- metadata +17 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf81256a8c23f02b4ef5a1f2efb91122850960da349cc1c00bce37d4055486ac
|
|
4
|
+
data.tar.gz: c0fdb2a48e67beb7a59730fe947ca819c5ed72196c858b02a430cb5f85e953c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4e3b7098c50d3d9e5958333f49ad2b8c22399f383067c01b0481fb82e9d1eaa50481de15afe8b2b883d6f0ee1697144ae55d028771eeca159cc38f46626043f
|
|
7
|
+
data.tar.gz: 25c3979864c017334256986e5697c793f40b22b3cdc7419d18e3ef090925f0297909ca8fafc9188cf37769344e656fa7e900cf8da8f3a310599e1cd9ab61ed8b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
## [0.1.11] - 2026-08-19
|
|
2
|
+
|
|
3
|
+
### Performance
|
|
4
|
+
- **Sub-Second Streaming Write (< 1.0s / 1,000,000 cells)**:
|
|
5
|
+
- Achieved sub-second streaming write performance (**0.97 s** median for 1M cells) while maintaining 100% full SST (Shared String Table) XML deduplication and ISO/IEC 29500 compatibility.
|
|
6
|
+
- Implemented 1-Pass Direct ZIP streaming pipeline, eliminating all intermediate tempfiles, disk seek-backs, and extra deflate flush cycles.
|
|
7
|
+
- Added dedicated unstyled fast-path in `WorksheetWriter#write_row_values` with precomputed coordinate and integer lookup tables.
|
|
8
|
+
- Pre-registered default date/time formatting styles, completely eliminating redundant per-row scan loops.
|
|
9
|
+
- Streamlined `ZipWriter` instance variable lookups to eliminate per-chunk hash overhead.
|
|
10
|
+
- Added `alias << row` to `WorksheetProxy` and `StreamWriter` for idiomatic Ruby streaming.
|
|
11
|
+
- **High-Speed Streaming Read (1.61s / 1,000,000 cells)**:
|
|
12
|
+
- Reduced streaming read execution time from **3.40 s** down to **1.61 s** (over 2x speedup).
|
|
13
|
+
- Refactored `Elements::Cell` into an optimized lightweight class with `Cell.fast_create`, reducing 1M cell instantiation overhead by 5.2x (0.92s → 0.17s) while maintaining full pattern matching (`deconstruct`, `deconstruct_keys`) and immutability.
|
|
14
|
+
- Replaced per-byte Ruby scanning in `WorksheetParser.fast_scan_cells_direct` with an Onigmo C-level regular expression scanner (`CELL_FAST_RE`), eliminating 100,000 intermediate XML substring allocations and nested byte loops.
|
|
15
|
+
- Optimized `StreamRow#cells` to populate cell arrays via direct block traversal, eliminating Enumerator object allocations.
|
|
16
|
+
|
|
17
|
+
### Documentation
|
|
18
|
+
- Updated benchmark results, performance comparisons, and linear-scale SVG charts across `README.md` and `docs/PEER_LIBRARIES.md`.
|
|
19
|
+
|
|
20
|
+
## [0.1.10] - 2026-08-19
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- **Peer Libraries Ecosystem Guide ([docs/PEER_LIBRARIES.md](docs/PEER_LIBRARIES.md))**: Introduced a respectful overview of the Ruby XLSX ecosystem featuring official self-descriptions, architectural tradeoffs (SST vs. Inline Strings, Streaming vs. In-Memory), and reproducible benchmarks across 9 popular Ruby XLSX gems.
|
|
24
|
+
- **Visual Assets & Screen Previews**:
|
|
25
|
+
- Embedded interactive WebAssembly Playground live demo preview in `README.md`.
|
|
26
|
+
- Added real-world Ruby LSP autocompletion and RBS type hint preview in `README.md`.
|
|
27
|
+
- Created accurate, neutral linear-scale SVG benchmark performance chart.
|
|
28
|
+
- **Enterprise-Grade Test Suite Expansion**:
|
|
29
|
+
- **ECMA-376 XSD Schema Validation**: Comprehensive XML schema validation suite ensuring strict element ordering and ISO/IEC 29500 compliance.
|
|
30
|
+
- **Contract Testing Suite**: Comprehensive parity verification between Streaming (`Xlsxrb.write`) and In-Memory (`Xlsxrb.build`) APIs.
|
|
31
|
+
- **Property-Based Testing (PBT)**: Expanded automated random generation tests for Row/Column invariants, styles, and edge cases.
|
|
32
|
+
- **Visual Regression Testing (VRT)**: Added new visual baselines for table styles, drawing shapes, and pivot tables.
|
|
33
|
+
- **E2E Interoperability Suite**: Added tests for namespace-prefixed XML streaming, conditional formatting, and table structures.
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- **WebAssembly (ruby.wasm) Compatibility**: Bundled `pp` and `prettyprint` standard libraries in `ruby.wasm` package to resolve REXML LoadError during browser-based evaluation.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
- **Streamlined README**: Refactored README from 363 to 175 lines, focusing on core motivation, clean 4-column feature matrix, concise usage examples, and direct links to specialized documentation.
|
|
40
|
+
|
|
1
41
|
## [0.1.9] - 2026-08-18
|
|
2
42
|
|
|
3
43
|
### Added
|
data/README.md
CHANGED
|
@@ -4,83 +4,61 @@ A Ruby library for reading and writing XLSX files with streaming support.
|
|
|
4
4
|
|
|
5
5
|
## Motivation
|
|
6
6
|
|
|
7
|
-
The Ruby ecosystem already has great XLSX libraries
|
|
8
|
-
|
|
9
|
-
| Library
|
|
10
|
-
|
|
|
11
|
-
| [roo](https://rubygems.org/gems/roo)
|
|
12
|
-
| [creek](https://rubygems.org/gems/creek)
|
|
13
|
-
| [xsv](https://rubygems.org/gems/xsv)
|
|
14
|
-
| [simple_xlsx_reader](https://rubygems.org/gems/simple_xlsx_reader) | ✅ | ❌ |
|
|
15
|
-
| [caxlsx / axlsx](https://rubygems.org/gems/caxlsx)
|
|
16
|
-
| [write_xlsx](https://rubygems.org/gems/write_xlsx)
|
|
17
|
-
| [xlsxtream](https://rubygems.org/gems/xlsxtream)
|
|
18
|
-
| [fast_excel](https://rubygems.org/gems/fast_excel)
|
|
19
|
-
| [rubyXL](https://rubygems.org/gems/rubyXL)
|
|
20
|
-
| **[xlsxrb](https://github.com/niku/xlsxrb)**
|
|
21
|
-
|
|
22
|
-
Each of these libraries makes deliberate
|
|
23
|
-
* **
|
|
24
|
-
* **
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
`xlsxrb` is born from a different premise. We believe that Advanced Agentic AI (AI Coders) can help manage this maintenance demand. By utilizing AI agents to automate rigorous E2E testing, visual regression testing, specification compliance checks, and documentation updates, we can reconcile these competing engineering requirements. This allows us to build and continuously maintain a feature-rich, high-performance, and deeply compatible "all-in-one" XLSX library that remains sustainable for the long run.
|
|
7
|
+
The Ruby ecosystem already has great XLSX libraries, each designed for specific tradeoffs:
|
|
8
|
+
|
|
9
|
+
| Library | Read | Write | Streaming | In-Memory |
|
|
10
|
+
| :--- | :---: | :---: | :---: | :---: |
|
|
11
|
+
| [roo](https://rubygems.org/gems/roo) | ✅ | ❌ | ✅ | ❌ |
|
|
12
|
+
| [creek](https://rubygems.org/gems/creek) | ✅ | ❌ | ✅ | ❌ |
|
|
13
|
+
| [xsv](https://rubygems.org/gems/xsv) | ✅ | ❌ | ✅ | ❌ |
|
|
14
|
+
| [simple_xlsx_reader](https://rubygems.org/gems/simple_xlsx_reader) | ✅ | ❌ | ✅ | ❌ |
|
|
15
|
+
| [caxlsx / axlsx](https://rubygems.org/gems/caxlsx) | ❌ | ✅ | ❌ | ✅ |
|
|
16
|
+
| [write_xlsx](https://rubygems.org/gems/write_xlsx) | ❌ | ✅ | ❌ | ✅ |
|
|
17
|
+
| [xlsxtream](https://rubygems.org/gems/xlsxtream) | ❌ | ✅ | ✅ | ❌ |
|
|
18
|
+
| [fast_excel](https://rubygems.org/gems/fast_excel) | ❌ | ✅ | ✅ | ❌ |
|
|
19
|
+
| [rubyXL](https://rubygems.org/gems/rubyXL) | ✅ | ✅ | ❌ | ✅ |
|
|
20
|
+
| **[xlsxrb](https://github.com/niku/xlsxrb)** | **✅** | **✅** | **✅** | **✅** |
|
|
21
|
+
|
|
22
|
+
Each of these libraries makes deliberate architectural choices:
|
|
23
|
+
* **Streaming Model**: Writes or reads rows sequentially on-the-fly to maintain a constant $O(1)$, low-memory footprint regardless of dataset size.
|
|
24
|
+
* **In-Memory Model**: Builds a complete document object model, offering flexible random access, cell updates, and document templates at the cost of memory usage on large spreadsheets.
|
|
25
|
+
|
|
26
|
+
Traditionally, maintaining an all-in-one gem that offers both reading and writing across both streaming and in-memory models, alongside rich OOXML features, high performance, and strict compatibility, presents an inherent open-source challenge: the cumulative maintenance overhead often exceeds the capacity of individual human maintainers.
|
|
27
|
+
|
|
28
|
+
`xlsxrb` is built on a modern premise: **Advanced Agentic AI (AI Coders) can sustainably handle this maintenance demand.** By utilizing AI agents to automate end-to-end testing, visual regression testing, specification compliance verification, and documentation updates, `xlsxrb` delivers a fast, specification-compliant, and fully-featured XLSX library built for long-term sustainability.
|
|
31
29
|
|
|
32
30
|
### Design Principles
|
|
33
31
|
|
|
34
|
-
- Minimal Dependencies
|
|
35
|
-
- Streaming Support
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
- Modern Ruby 4.0+: Built for the future with Ruby 4.0 or higher.
|
|
32
|
+
- **Minimal Dependencies**: Zero core logic dependencies. Built purely on the Ruby standard library and bundled gems (`zlib`, `rexml`, etc.). The only runtime dependency is `opentelemetry-api` (zero-overhead no-op when unconfigured).
|
|
33
|
+
- **Streaming Support**: True $O(1)$ constant memory streaming for both reading and writing massive spreadsheets.
|
|
34
|
+
- **Strict OpenXML Interoperability**: Fully compliant with ISO/IEC 29500 (ECMA-376) and validated continuously against the official Microsoft [Open XML SDK](https://github.com/dotnet/Open-XML-SDK).
|
|
35
|
+
- **AI-Assisted Sustainability**: Leveraging AI coding agents for automated quality assurance, E2E validation, and continuous feature expansion.
|
|
36
|
+
- **Modern Ruby**: Built for Ruby 4.0 or higher.
|
|
40
37
|
|
|
41
38
|
## Installation
|
|
42
39
|
|
|
43
40
|
```bash
|
|
44
41
|
bundle add xlsxrb
|
|
42
|
+
# Or without Bundler: gem install xlsxrb
|
|
45
43
|
```
|
|
46
44
|
|
|
47
|
-
Or without Bundler:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
gem install xlsxrb
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
On Ruby 4+, some components used by `xlsxrb` and its test suite are shipped as bundled gems rather than built-in default libraries. When using Bundler, those bundled gems are resolved and installed in the usual way.
|
|
54
|
-
|
|
55
45
|
## Interactive Playground (WebAssembly)
|
|
56
46
|
|
|
57
|
-
|
|
47
|
+
Try `xlsxrb` directly in your browser without installing anything!
|
|
58
48
|
|
|
59
49
|
[👉 Try the Live Demo / Interactive Playground](https://niku.github.io/xlsxrb/docs/visual/VisualGallery_md.html)
|
|
60
50
|
|
|
61
|
-
|
|
51
|
+
<p align="center">
|
|
52
|
+
<img src="docs/assets/playground_preview.png" width="100%" alt="Interactive WebAssembly Playground with Live LibreOffice Preview"/>
|
|
53
|
+
</p>
|
|
62
54
|
|
|
63
|
-
|
|
64
|
-
1. Generate the WebAssembly bundle and interactive RDoc:
|
|
65
|
-
```bash
|
|
66
|
-
bundle exec rake doc
|
|
67
|
-
```
|
|
68
|
-
2. Start the local preview server:
|
|
69
|
-
```bash
|
|
70
|
-
bundle exec rake doc:preview
|
|
71
|
-
```
|
|
72
|
-
3. Open [http://localhost:8000](http://localhost:8000) in your browser, hover over any code block, and click the "Live Preview" or "Download XLSX" buttons!
|
|
55
|
+
You can also browse 50+ rendered visual examples across all features in the [Visual Examples Gallery](docs/visual/VisualGallery.md).
|
|
73
56
|
|
|
74
57
|
## Usage
|
|
75
58
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
For visual demonstrations of various features, check the [Visual Examples Gallery](docs/visual/VisualGallery.md).
|
|
59
|
+
### Quick Start: Streaming (Recommended for Large Files)
|
|
79
60
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
#### Streaming Write
|
|
83
|
-
Generate large files efficiently with $O(1)$ constant memory by writing data directly to the stream:
|
|
61
|
+
#### Streaming Write ($O(1)$ Memory)
|
|
84
62
|
```ruby
|
|
85
63
|
require "xlsxrb"
|
|
86
64
|
|
|
@@ -93,12 +71,10 @@ Xlsxrb.write("large_output.xlsx") do |writer|
|
|
|
93
71
|
end
|
|
94
72
|
```
|
|
95
73
|
|
|
96
|
-
#### Streaming Read
|
|
97
|
-
Read rows and cells lazily one at a time with $O(1)$ constant memory (even for wide sheets with thousands of columns):
|
|
74
|
+
#### Streaming Read ($O(1)$ Memory)
|
|
98
75
|
```ruby
|
|
99
76
|
require "xlsxrb"
|
|
100
77
|
|
|
101
|
-
# Stream row-by-row and cell-by-cell (O(1) memory)
|
|
102
78
|
Xlsxrb.read("large_file.xlsx") do |sheet|
|
|
103
79
|
sheet.each_row do |row|
|
|
104
80
|
row.each_cell do |cell|
|
|
@@ -106,39 +82,14 @@ Xlsxrb.read("large_file.xlsx") do |sheet|
|
|
|
106
82
|
end
|
|
107
83
|
end
|
|
108
84
|
end
|
|
109
|
-
|
|
110
|
-
# Or stream all cells across the sheet directly
|
|
111
|
-
Xlsxrb.read("large_file.xlsx") do |sheet|
|
|
112
|
-
sheet.each_cell do |cell|
|
|
113
|
-
puts "#{cell.ref} = #{cell.value}"
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
85
|
```
|
|
117
86
|
|
|
118
|
-
###
|
|
119
|
-
|
|
120
|
-
`xlsxrb` provides clean, standard Ruby interfaces (`Enumerable`, `Row#to_a`, `sheet["A1"]`) that feel natural to every Ruby developer without learning complex library-specific APIs:
|
|
87
|
+
### In-Memory Building & Modifying
|
|
121
88
|
|
|
122
|
-
####
|
|
89
|
+
#### Creating & Exporting (Rails / Mailers)
|
|
123
90
|
```ruby
|
|
124
91
|
require "xlsxrb"
|
|
125
92
|
|
|
126
|
-
# 1. Read from file path, IO, or raw binary string (O(1) constant memory streaming)
|
|
127
|
-
workbook = Xlsxrb.read("data.xlsx")
|
|
128
|
-
sheet = workbook.sheets.first
|
|
129
|
-
|
|
130
|
-
# 2. Extract sheet data into 2D array of values via standard Enumerable
|
|
131
|
-
matrix = sheet.map(&:to_a) # => [["Name", "Score"], ["Alice", 100], ["Bob", 95]]
|
|
132
|
-
|
|
133
|
-
# 3. Explicitly load into memory for coordinate random access (e.g. sheet["A1"])
|
|
134
|
-
doc_sheet = sheet.load
|
|
135
|
-
doc_sheet["A1"] # => #<Xlsxrb::Elements::Cell value="Name" ...>
|
|
136
|
-
doc_sheet["A1"].value # => "Name"
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
#### Writing & In-Memory Export (Rails & Mailers)
|
|
140
|
-
```ruby
|
|
141
|
-
# Build workbook
|
|
142
93
|
wb = Xlsxrb.build do |b|
|
|
143
94
|
b.sheet("Report") do |s|
|
|
144
95
|
s.row(["Metric", "Value"])
|
|
@@ -146,217 +97,84 @@ wb = Xlsxrb.build do |b|
|
|
|
146
97
|
end
|
|
147
98
|
end
|
|
148
99
|
|
|
149
|
-
# Save
|
|
100
|
+
# Save to file or get binary string for Rails send_data
|
|
150
101
|
Xlsxrb.write("report.xlsx", wb)
|
|
151
|
-
|
|
152
|
-
# Or export to binary string (ideal for Rails send_data & ActionMailer):
|
|
153
102
|
binary_data = Xlsxrb.write(wb)
|
|
154
103
|
```
|
|
155
104
|
|
|
156
|
-
### In-Memory Building & Modifying
|
|
157
|
-
|
|
158
|
-
`xlsxrb` provides a powerful, immutable-by-default API for modifying existing Excel files or building templates in-memory.
|
|
159
|
-
|
|
160
105
|
#### Modifying an Existing File
|
|
161
|
-
You can update specific cells or sheets using the functional `Xlsxrb.modify` API, which yields the parsed `Elements::Workbook`.
|
|
162
|
-
|
|
163
106
|
```ruby
|
|
164
107
|
require "xlsxrb"
|
|
165
108
|
|
|
166
|
-
# Create a template.xlsx for this example
|
|
167
|
-
Xlsxrb.build { |builder| builder.sheet("Invoice") }.write("template.xlsx")
|
|
168
|
-
|
|
169
109
|
Xlsxrb.modify("template.xlsx", "output.xlsx") do |workbook|
|
|
170
110
|
workbook.update_sheet("Invoice") do |sheet|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
sheet = sheet.update_cell("C5", value: Date.today)
|
|
174
|
-
|
|
175
|
-
# Or append new rows
|
|
176
|
-
sheet.with(rows: sheet.rows + [
|
|
177
|
-
Xlsxrb::Elements::Row.new(index: sheet.rows.size, cells: [])
|
|
178
|
-
])
|
|
111
|
+
sheet.update_cell("C4", value: "INV-10042")
|
|
112
|
+
.update_cell("C5", value: Date.today)
|
|
179
113
|
end
|
|
180
114
|
end
|
|
181
115
|
```
|
|
182
116
|
|
|
183
|
-
|
|
184
|
-
You can directly apply inline styles or use Ranges for multiple columns without boilerplate:
|
|
117
|
+
### Password Protection & Encryption ([MS-OFFCRYPTO])
|
|
185
118
|
|
|
186
|
-
|
|
187
|
-
Xlsxrb.build do |builder|
|
|
188
|
-
# Use [] accessor for sheets
|
|
189
|
-
builder["Report"].row(
|
|
190
|
-
["ID", "Name", "Score", "Rank"],
|
|
191
|
-
# Apply 'header' style to first two columns, and bold inline style to the third
|
|
192
|
-
styles: { 0..1 => "header", 2 => { font: { bold: true, color: "red" } } }
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
# Set multiple column widths at once using Ranges
|
|
196
|
-
builder["Report"].column("A".."D", width: 15.0)
|
|
197
|
-
end
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Password Protection & Document Encryption ([MS-OFFCRYPTO])
|
|
201
|
-
|
|
202
|
-
`xlsxrb` natively supports reading and writing password-protected Excel files with zero external C-extension dependencies, fully compliant with **[MS-OFFCRYPTO]** (Standard Encryption & Agile Encryption) and **[MS-CFB]** (Compound File Binary Format):
|
|
119
|
+
Natively supports reading and writing encrypted XLSX files (Standard & Agile Encryption) with zero external C-extensions:
|
|
203
120
|
|
|
204
|
-
#### Writing Password-Protected Spreadsheets
|
|
205
121
|
```ruby
|
|
206
|
-
|
|
207
|
-
Xlsxrb.write("confidential.xlsx", password: "SecretPassword123") do |writer|
|
|
208
|
-
writer.sheet("Financials") do |sheet|
|
|
209
|
-
sheet.row(["Account", "Balance"])
|
|
210
|
-
sheet.row(["Assets", 5_000_000])
|
|
211
|
-
end
|
|
212
|
-
end
|
|
122
|
+
require "xlsxrb"
|
|
213
123
|
|
|
214
|
-
#
|
|
215
|
-
|
|
216
|
-
|
|
124
|
+
# Write password-protected file
|
|
125
|
+
Xlsxrb.write("confidential.xlsx", password: "SecretPassword123") do |writer|
|
|
126
|
+
writer.sheet("Financials") { |sheet| sheet.row(["Assets", 5_000_000]) }
|
|
217
127
|
end
|
|
218
|
-
encrypted_binary = Xlsxrb.write(wb, password: "SecretPassword123")
|
|
219
|
-
```
|
|
220
128
|
|
|
221
|
-
|
|
222
|
-
```ruby
|
|
223
|
-
# 1. Read directly with password (O(1) constant memory streaming)
|
|
129
|
+
# Read password-protected file
|
|
224
130
|
Xlsxrb.read("confidential.xlsx", password: "SecretPassword123") do |sheet|
|
|
225
131
|
sheet.each_row { |row| puts row.cells.map(&:value) }
|
|
226
132
|
end
|
|
227
|
-
|
|
228
|
-
# 2. In-Memory load with password
|
|
229
|
-
workbook = Xlsxrb.read("confidential.xlsx", password: "SecretPassword123").load
|
|
230
|
-
puts workbook.sheets.first["A1"].value
|
|
231
|
-
|
|
232
|
-
# Attempting to read without password or with invalid password raises clear exceptions:
|
|
233
|
-
# Xlsxrb::EncryptedFileError -> Missing password
|
|
234
|
-
# Xlsxrb::InvalidPasswordError -> Incorrect password
|
|
235
133
|
```
|
|
236
134
|
|
|
237
135
|
### IDE Autocompletion & Ruby LSP Support
|
|
238
136
|
|
|
239
|
-
|
|
137
|
+
Includes a native **Ruby LSP Add-on** and full **RBS signatures** for zero-configuration method autocompletion and hover documentation in VS Code and other editors:
|
|
240
138
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
Xlsxrb.write("output.xlsx") do |writer| # or |wb|
|
|
245
|
-
writer.sheet("Data") do |sheet| # or |s|
|
|
246
|
-
sheet.row(["Product", "Price"], styles: :bold)
|
|
247
|
-
sheet.auto_filter("A1:B100")
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
```
|
|
139
|
+
<p align="center">
|
|
140
|
+
<img src="docs/assets/lsp_autocompletion.png" width="100%" alt="Ruby LSP Autocompletion & Type Signature Hints in VS Code"/>
|
|
141
|
+
</p>
|
|
251
142
|
|
|
252
143
|
## Feature Support & ECMA-376 Compliance
|
|
253
144
|
|
|
254
|
-
`xlsxrb`
|
|
255
|
-
|
|
256
|
-
*
|
|
257
|
-
* Data & Controls: Auto Filters, Data Validations (dropdowns, range limits), Sheet Protection.
|
|
258
|
-
* Formatting & Styling: Rich Text, Cell Tables, Conditional Formatting (color scales, data bars, icon sets).
|
|
259
|
-
* Graphics & Charts: Embedded Images, Shapes & Drawings, Sparklines, Charts (Line, Bar, Pie, Area, Radar, Scatter).
|
|
260
|
-
* Workbook Level: Defined Names, Print Areas, Workbook Protection, and Document Metadata (core, app, custom properties).
|
|
145
|
+
`xlsxrb` supports nearly all major business spreadsheet features:
|
|
146
|
+
* **Layout & Structure**: Formulas, Hyperlinks, Merge Cells, Freeze/Split Panes, Page Setup, Auto Filters, Data Validations, Sheet/Workbook Protection.
|
|
147
|
+
* **Styling & Media**: Rich Text, Cell Styles & Fills, Conditional Formatting (color scales, data bars), Embedded Images, Charts (Line, Bar, Pie, Radar, Scatter).
|
|
261
148
|
|
|
262
|
-
For
|
|
149
|
+
For full details, see [docs/SPEC_SOURCES.md](docs/SPEC_SOURCES.md).
|
|
263
150
|
|
|
264
151
|
## Benchmarks
|
|
265
152
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
### Write Performance (1,000,000 cells)
|
|
269
|
-
|
|
270
|
-
| Library | Model | Write String Storage | Time (Median) | Time (Mean) | Peak Memory | GC Count |
|
|
271
|
-
| ---------------------- | ----------- | -------------------- | ------------- | ----------- | ----------- | -------- |
|
|
272
|
-
| xlsxtream 3.1.0 | Streaming | Inline String | 1.19 s | 1.20 s | 18.2 MB | 1072.0 |
|
|
273
|
-
| xlsxrb (Streaming) | Streaming | SST (Shared) | 1.73 s | 1.65 s | 94.4 MB | 39.0 |
|
|
274
|
-
| fast_excel 0.5.0 (C) | Streaming | SST (Shared) | 1.89 s | 1.89 s | 148.2 MB | 245.0 |
|
|
275
|
-
| xlsxrb (In-Memory) | In-Memory | SST (Shared) | 3.84 s | 3.83 s | 278.3 MB | 32.0 |
|
|
276
|
-
| write_xlsx 1.15.0 | In-Memory | SST (Shared) | 4.32 s | 4.34 s | 201.2 MB | 33.0 |
|
|
277
|
-
| caxlsx 4.5.0 | In-Memory | Inline String | 5.15 s | 5.12 s | 188.6 MB | 23.0 |
|
|
278
|
-
| rubyXL 3.4.38 | In-Memory | Inline String | 38.81 s | 37.82 s | 2186.8 MB | 103.0 |
|
|
279
|
-
|
|
280
|
-
> **Note**: All libraries are evaluated in their **default, out-of-the-box configuration**. Under the same Microsoft Excel-standard Shared String Table (SST) architecture, Pure Ruby `xlsxrb` (Streaming: 1.73s, In-Memory: 3.84s) writes 1,000,000 cells faster than the C-extension `fast_excel` (1.89s) and in-memory gems like `write_xlsx` (4.32s) and `caxlsx` (5.15s).
|
|
153
|
+
Benchmark processing 1,000,000 cells (100,000 rows × 10 cols) across popular Ruby gems:
|
|
281
154
|
|
|
282
|
-
|
|
155
|
+
<p align="center">
|
|
156
|
+
<img src="docs/assets/benchmark_results.svg" width="100%" alt="Ruby XLSX Performance Benchmarks"/>
|
|
157
|
+
</p>
|
|
283
158
|
|
|
284
|
-
|
|
285
|
-
| ------------------------ | ----------- | ------------- | ----------- | ----------- | -------- |
|
|
286
|
-
| xlsxrb (Streaming) | Streaming | 3.17 s | 3.22 s | 91.4 MB | 43.0 |
|
|
287
|
-
| simple_xlsx_reader 5.1.0 | Streaming | 4.48 s | 4.45 s | 38.5 MB | 1669.0 |
|
|
288
|
-
| xlsxrb (In-Memory) | In-Memory | 5.71 s | 5.89 s | 224.8 MB | 63.0 |
|
|
289
|
-
| creek 2.6.3 | Streaming | 8.14 s | 8.02 s | 834.6 MB | 477.0 |
|
|
290
|
-
| xsv 1.4.1 | Streaming | 14.61 s | 14.50 s | 76.1 MB | 2224.0 |
|
|
291
|
-
| roo 3.0.0 | Streaming | 15.69 s | 13.36 s | 119.7 MB | 441.0 |
|
|
292
|
-
| rubyXL 3.4.38 | In-Memory | 37.13 s | 40.35 s | 2537.6 MB | 146.0 |
|
|
159
|
+
For detailed metrics (peak memory, GC count, mean/median times) and architectural tradeoffs (SST vs. Inline Strings), see [docs/PEER_LIBRARIES.md](docs/PEER_LIBRARIES.md).
|
|
293
160
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
The benchmark suite leverages [`bundler/inline`](https://bundler.io/v2.5/guides/bundler_in_a_single_file_ruby_script.html) to automatically manage and download all peer ecosystem gems without modifying the project's core `Gemfile` or requiring manual global `gem install` steps. Each library is executed in an isolated subprocess (`Bundler.with_unbundled_env`) across multiple runs with standard business dataset rows (integers, strings, floats, booleans, dates) to ensure clean memory and GC measurements without cross-contamination.
|
|
297
|
-
|
|
298
|
-
To run the complete benchmark suite:
|
|
299
|
-
```bash
|
|
300
|
-
ruby benchmark.rb 100000 10
|
|
301
|
-
```
|
|
161
|
+
To reproduce locally: `ruby benchmark.rb 100000 10`
|
|
302
162
|
|
|
303
|
-
##
|
|
163
|
+
## Quality Assurance & Testing
|
|
304
164
|
|
|
305
|
-
|
|
165
|
+
Backed by an enterprise-grade QA architecture to guarantee absolute reliability:
|
|
166
|
+
* **Official Microsoft Open XML SDK Validation**: Validates generated OOXML structures against Microsoft's official SDK.
|
|
167
|
+
* **Visual Regression Testing (VRT)**: Headless LibreOffice Calc pixel-by-pixel rendering checks.
|
|
168
|
+
* **Contract & Round-Trip Tests**: Verifies parity between Streaming and In-Memory APIs and round-trip read/write accuracy.
|
|
169
|
+
* **Security & DoS Protection**: Formula injection mitigation and ZIP bomb protection.
|
|
306
170
|
|
|
307
|
-
|
|
171
|
+
For full architectural details, see [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) and [docs/QUALITY_ASSURANCE.md](docs/QUALITY_ASSURANCE.md).
|
|
308
172
|
|
|
309
|
-
|
|
173
|
+
## Development & Contributing
|
|
310
174
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
If you absolutely need external links to update automatically, you can explicitly override this (though **it is highly discouraged due to security risks**):
|
|
314
|
-
|
|
315
|
-
```ruby
|
|
316
|
-
Xlsxrb.write("file.xlsx") do |wb|
|
|
317
|
-
# WARNING: Enabling this can expose users to malicious external reference vulnerabilities!
|
|
318
|
-
wb.workbook_property(:update_links, "always")
|
|
319
|
-
# ...
|
|
320
|
-
end
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
## Testing & Quality Assurance
|
|
324
|
-
|
|
325
|
-
To support reliability, compliance with the ECMA-376 specification, and consistent updates, `xlsxrb` is backed by a highly rigorous, enterprise-grade Quality Assurance (QA) and testing architecture.
|
|
326
|
-
|
|
327
|
-
### Multi-Tier Testing Strategy
|
|
328
|
-
* **Round-Trip Testing**: Unit tests verify that every generated sheet can be reliably parsed back by the reader with identical content and styling.
|
|
329
|
-
* **Contract Consistency**: Ensures semantic output consistency between the Streaming (`Xlsxrb.write`) and In-Memory (`Xlsxrb.build`) APIs.
|
|
330
|
-
* **Property-Based Testing (PBT)**: Automatically generates random data to catch edge cases (e.g., huge numbers, special characters) preventing unexpected crashes.
|
|
331
|
-
* **Concurrency Validation**: Thread and Ractor safety checks to guarantee no global variable pollution during parallel execution.
|
|
332
|
-
* **Security & DoS Protection**: Hardened against malicious files, including memory exhaustion (ZIP Bombs) and infinite parsing loops.
|
|
333
|
-
|
|
334
|
-
### Strict Interoperability & Rendering
|
|
335
|
-
* **Official Open XML SDK Validation (E2E)**: Every generated spreadsheet is structurally validated against the official Microsoft Open XML SDK to prevent file corruption warnings in Microsoft Excel.
|
|
336
|
-
* **Visual Regression Testing (VRT)**: Spreadsheets are rendered via a headless LibreOffice Calc engine and compared pixel-by-pixel against visual baselines to catch subtle rendering regressions.
|
|
337
|
-
|
|
338
|
-
### Performance & Types
|
|
339
|
-
* **Continuous Performance & Memory Validation**: Memory retention and processing throughput are profiled in CI on large datasets to prevent regressions and OOM leaks.
|
|
340
|
-
* **Runtime Type Validation**: Strong dynamic typing using `RBS::Test` to ensure the library's types are perfectly sound at runtime.
|
|
341
|
-
|
|
342
|
-
For a comprehensive breakdown of our QA matrix, see [docs/QUALITY_ASSURANCE.md](docs/QUALITY_ASSURANCE.md). For details on running tests locally, see [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md).
|
|
343
|
-
|
|
344
|
-
## Development
|
|
345
|
-
|
|
346
|
-
We welcome contributions! The project is configured with a ready-to-use Dev Container to streamline local environment setup.
|
|
347
|
-
|
|
348
|
-
For contribution guidelines, E2E testing policies, and the step-by-step development workflow (including how to run the Dev Container from your terminal), please refer to [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md).
|
|
349
|
-
|
|
350
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
351
|
-
|
|
352
|
-
## Contributing
|
|
353
|
-
|
|
354
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/niku/xlsxrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
|
|
175
|
+
See [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) for local setup (Dev Container support), testing workflows, and contribution guidelines.
|
|
355
176
|
|
|
356
177
|
## License
|
|
357
178
|
|
|
358
179
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
359
180
|
|
|
360
|
-
## Code of Conduct
|
|
361
|
-
|
|
362
|
-
Everyone interacting in the Xlsxrb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
|
@@ -295,7 +295,8 @@ task :wasm do
|
|
|
295
295
|
# B. Copy necessary standard libraries dynamically from host's $LOAD_PATH
|
|
296
296
|
stdlib_files = [
|
|
297
297
|
"date.rb", "delegate.rb", "forwardable.rb", "securerandom.rb",
|
|
298
|
-
"random/formatter.rb", "set.rb", "tempfile.rb", "tmpdir.rb", "fileutils.rb"
|
|
298
|
+
"random/formatter.rb", "set.rb", "tempfile.rb", "tmpdir.rb", "fileutils.rb",
|
|
299
|
+
"pp.rb", "prettyprint.rb"
|
|
299
300
|
]
|
|
300
301
|
stdlib_files.each do |name|
|
|
301
302
|
path = $LOAD_PATH.find { |p| File.exist?(File.join(p, name)) }
|
data/benchmark.rb
CHANGED
|
@@ -9,6 +9,7 @@ require "bundler/inline"
|
|
|
9
9
|
puts "Ensuring benchmark peer ecosystem gems are available (bundler/inline)..."
|
|
10
10
|
gemfile(true) do
|
|
11
11
|
source "https://rubygems.org"
|
|
12
|
+
gem "rubyzip", ">= 2.3.0"
|
|
12
13
|
gem "caxlsx", "4.5.0"
|
|
13
14
|
gem "xlsxtream", "3.1.0"
|
|
14
15
|
gem "fast_excel", "0.5.0", platform: :mri
|
|
@@ -187,7 +188,7 @@ RUNNER_SCRIPT = <<~'RUBY'
|
|
|
187
188
|
when ["xlsxrb_inmemory", "read"]
|
|
188
189
|
require_relative "lib/xlsxrb"
|
|
189
190
|
measure do
|
|
190
|
-
wb = Xlsxrb.read(filename)
|
|
191
|
+
wb = Xlsxrb.read(filename).load
|
|
191
192
|
count = 0
|
|
192
193
|
wb.sheets.each do |sheet|
|
|
193
194
|
sheet.rows.each do |row|
|
|
@@ -237,6 +238,7 @@ RUNNER_SCRIPT = <<~'RUBY'
|
|
|
237
238
|
end
|
|
238
239
|
end
|
|
239
240
|
when ["simple_xlsx_reader", "read"]
|
|
241
|
+
gem "rubyzip", "~> 1.3.0"
|
|
240
242
|
require "simple_xlsx_reader"
|
|
241
243
|
measure do
|
|
242
244
|
doc = SimpleXlsxReader.open(filename)
|