@nazarkalytiuk/rusc-xlsx 1.0.3

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Nazarii Kalytiuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,289 @@
1
+ # rusc-xlsx
2
+
3
+ [![Test](https://github.com/NazarKalytiuk/napi_rust_xlsxwrighter/actions/workflows/test.yml/badge.svg)](https://github.com/NazarKalytiuk/napi_rust_xlsxwrighter/actions/workflows/test.yml)
4
+ [![npm version](https://img.shields.io/npm/v/rusc-xlsx.svg)](https://www.npmjs.com/package/rusc-xlsx)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ Fast, feature-complete Excel XLSX library for Node.js powered by [rust_xlsxwriter](https://github.com/jmcnamara/rust_xlsxwriter) and NAPI-RS.
8
+
9
+ ## Features
10
+
11
+ ### Core Excel Features
12
+ - **Workbook & Worksheets**: Multiple sheets, naming, read-only mode
13
+ - **Data Types**: Strings, numbers, booleans, dates/times
14
+ - **Formatting**:
15
+ - Font styling (bold, italic, underline, strikethrough, size, color, script)
16
+ - Alignment (horizontal, vertical, rotation, indent, wrap, shrink)
17
+ - Borders (12 styles, individual sides with colors, diagonal)
18
+ - Fills (18 patterns, foreground/background colors)
19
+ - Number formats (currency, percentage, dates, custom)
20
+ - Cell protection (locked/unlocked, hidden formulas)
21
+ - **Layout**: Column widths, row heights, merged cells
22
+ - **Formulas**: Standard, array, and dynamic formulas
23
+ - **Data Validation**: Dropdowns, number ranges, custom rules with messages
24
+ - **Conditional Formatting**:
25
+ - Color scales (2-color, 3-color)
26
+ - Data bars
27
+ - Cell rules (greaterThan, lessThan, between, etc.)
28
+ - Text rules (contains, beginsWith, endsWith)
29
+ - Top/Bottom N values
30
+ - Above/Below average
31
+ - Duplicate/Unique values
32
+ - Icon sets (18 types)
33
+ - Date-based rules (10 types)
34
+ - Formula-based rules
35
+ - **Charts**: 25 chart types (area, bar, column, line, pie, scatter, radar, stock)
36
+ - **Images**: PNG, JPG, GIF, BMP with scaling, positioning, and decorative mode
37
+ - **Tables**: Excel tables with custom columns, total rows, styles (60 styles)
38
+ - **Sparklines**: Line, column, win/lose sparklines with 36 styles
39
+ - **Rich Text**: Multi-format strings within cells
40
+ - **Notes**: Cell comments with custom styling
41
+ - **Hyperlinks**: External URLs and internal sheet links
42
+ - **Page Setup**: Margins, orientation, paper size, headers/footers, print area, scaling
43
+ - **View Controls**: Autofilters, freeze panes, zoom, tab colors, hide/show sheets
44
+
45
+ ### Advanced Features
46
+ - **Named Ranges**: Global and worksheet-scoped named ranges
47
+ - **VBA Macros**: Add VBA projects from binary files
48
+ - **Form Controls**: Interactive buttons with macro assignments
49
+ - **Shapes**: Textbox annotations with positioning
50
+ - **Document Metadata**: Author, title, subject, company, manager, keywords, etc.
51
+ - **Protection**: Worksheet protection with granular permissions
52
+ - **Memory Modes**: Constant and low memory modes for massive datasets
53
+
54
+ ### Performance & Memory
55
+ - **Fast**: Native Rust performance via NAPI-RS
56
+ - **Memory Efficient**: Three memory modes:
57
+ - **Standard**: Full features, optimized for typical datasets
58
+ - **Constant Memory**: ~0.02 MB regardless of size (millions of rows)
59
+ - **Low Memory**: Optimized for repeated strings
60
+ - **TypeScript**: Complete type definitions with IntelliSense support
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ npm install rusc-xlsx
66
+ ```
67
+
68
+ ### Requirements
69
+
70
+ - Node.js >= 16
71
+ - Rust toolchain (for building from source)
72
+
73
+ ## Quick Start
74
+
75
+ ```javascript
76
+ const { Workbook, Format } = require('rusc-xlsx');
77
+
78
+ // Create workbook and worksheet
79
+ const workbook = new Workbook();
80
+ const worksheet = workbook.addWorksheet('Sheet1');
81
+
82
+ // Write data with formatting
83
+ const headerFormat = new Format()
84
+ .setBold()
85
+ .setBackgroundColor('blue')
86
+ .setFontColor('white');
87
+
88
+ worksheet.write(0, 0, 'Name', headerFormat);
89
+ worksheet.write(0, 1, 'Age', headerFormat);
90
+ worksheet.write(1, 0, 'Alice');
91
+ worksheet.write(1, 1, 30);
92
+
93
+ // Save file
94
+ workbook.save('output.xlsx');
95
+ ```
96
+
97
+ ## Memory Modes for Large Datasets
98
+
99
+ ### Standard Mode (Default)
100
+
101
+ ```javascript
102
+ const worksheet = workbook.addWorksheet('Sheet1');
103
+ ```
104
+
105
+ - **Use when**: < 100,000 rows
106
+ - **Memory**: Scales with data size
107
+ - **Features**: Full Excel feature support
108
+
109
+ ### Constant Memory Mode
110
+
111
+ ```javascript
112
+ const worksheet = workbook.addWorksheetWithConstantMemory('Large');
113
+ ```
114
+
115
+ - **Use when**: Millions of rows with memory constraints
116
+ - **Memory**: Constant ~0.02 MB (regardless of size!)
117
+ - **Limitations**: Sequential row writing only, no tables
118
+
119
+ **Example: 1 million rows**
120
+ ```javascript
121
+ const workbook = new Workbook();
122
+ const worksheet = workbook.addWorksheetWithConstantMemory('Data');
123
+
124
+ for (let row = 0; row < 1000000; row++) {
125
+ worksheet.write(row, 0, `Row ${row}`);
126
+ worksheet.write(row, 1, row * 100);
127
+ }
128
+
129
+ workbook.save('large.xlsx');
130
+ ```
131
+
132
+ ### Low Memory Mode
133
+
134
+ ```javascript
135
+ const worksheet = workbook.addWorksheetWithLowMemory('Sales');
136
+ ```
137
+
138
+ - **Use when**: Large datasets with repeated strings
139
+ - **Memory**: Scales with unique strings
140
+ - **Best for**: Categorical data, status fields, repeated names
141
+
142
+ ## TypeScript Support
143
+
144
+ Full TypeScript definitions included:
145
+
146
+ ```typescript
147
+ import { Workbook, Format } from 'rusc-xlsx';
148
+
149
+ const workbook = new Workbook();
150
+ const worksheet = workbook.addWorksheet('Data');
151
+
152
+ const format = new Format();
153
+ format.setFontColor('#FF0000'); // Hex colors supported
154
+ format.setAlign('center'); // IntelliSense shows valid values
155
+ format.setBorder('medium'); // Type-safe
156
+
157
+ worksheet.write(0, 0, 'Hello', format);
158
+ workbook.save('output.xlsx');
159
+ ```
160
+
161
+ ## API Overview
162
+
163
+ ### Workbook
164
+ - `new Workbook()` - Create workbook
165
+ - `addWorksheet([name])` - Add worksheet
166
+ - `addWorksheetWithConstantMemory([name])` - Constant memory mode
167
+ - `addWorksheetWithLowMemory([name])` - Low memory mode
168
+ - `setTempdir(path)` - Set temp directory for memory modes
169
+ - `save(filename)` - Save to file
170
+ - `saveToBuffer()` - Save to Buffer
171
+ - `defineName(name, formula)` - Define named range
172
+ - `readOnlyRecommended()` - Mark as read-only recommended
173
+ - `addVbaProject(path)` - Add VBA macros
174
+ - `setProperties(props)` - Set document metadata
175
+
176
+ ### Worksheet (96 methods)
177
+ - **Writing**: `write()`, `writeString()`, `writeNumber()`, `writeBoolean()`, `writeBlank()`
178
+ - **DateTime**: `writeDatetime()`, `writeDatetimeFromTimestamp()`, `writeDatetimeFromYmd()`, etc.
179
+ - **Formulas**: `writeFormula()`, `writeArrayFormula()`, `writeDynamicFormula()`
180
+ - **Layout**: `setColumnWidth()`, `setRowHeight()`, `mergeRange()`, `setName()`
181
+ - **Features**: `insertNote()`, `addDataValidation()`, `insertChart()`, `insertImage()`, `addTable()`, `insertButton()`, `insertShape()`
182
+ - **Conditional Formatting**: 14 methods for all rule types
183
+ - **Page Setup**: 26 methods for printing, margins, headers, etc.
184
+ - **View**: `autofilter()`, `setFreezePanes()`, `setZoom()`, `setTabColor()`, `hideSheet()`
185
+ - **Hyperlinks**: `writeUrl()`
186
+ - **Protection**: `protect()`, `protectWithPassword()`
187
+ - **Rich Text**: `writeRichString()`
188
+
189
+ ### Format (39 methods)
190
+ - **Font**: `setBold()`, `setItalic()`, `setFontSize()`, `setFontColor()`, `setFontName()`, `setUnderline()`, `setStrikethrough()`, `setFontScript()`
191
+ - **Alignment**: `setAlign()`, `setVerticalAlign()`, `setRotation()`, `setIndent()`, `setTextWrap()`, `setShrink()`
192
+ - **Borders**: `setBorder()`, `setBorderTop/Bottom/Left/Right()`, `setBorderColor()`, `setBorderDiagonal()`
193
+ - **Fill**: `setBackgroundColor()`, `setForegroundColor()`, `setPattern()`
194
+ - **Number**: `setNumFormat()`
195
+ - **Protection**: `setLocked()`, `setUnlocked()`, `setHidden()`
196
+ - **Other**: `setReadingDirection()`, `setQuotePrefix()`
197
+
198
+ ### Supporting Classes
199
+ - **Chart**: 25 chart types with series, titles, legends, 48 styles
200
+ - **Image**: Insert with scaling, positioning, alt text, URLs
201
+ - **Table**: Custom columns, total rows, 60 styles
202
+ - **Sparkline**: 3 types, markers, colors, 36 styles
203
+ - **DataValidation**: All validation types with custom messages
204
+ - **Note**: Comments with author, size, color, visibility
205
+ - **Formula**: Standard, array, dynamic with preset results
206
+ - **RichText**: Multi-format text segments
207
+ - **ProtectionOptions**: 16 granular permissions
208
+ - **DocProperties**: 10 metadata fields
209
+ - **Button**: Form controls with VBA macros
210
+ - **Shape**: Textbox shapes for annotations
211
+
212
+ ## Examples
213
+
214
+ See the `examples/` directory for complete examples:
215
+ - `basic.js` - Simple workbook creation
216
+ - `formatting.js` - Cell formatting
217
+ - `advanced-features.js` - Charts, images, tables
218
+ - `conditional-formatting-and-page-setup.js` - Conditional formatting
219
+ - `constant-memory.js` - Large datasets
220
+ - `typescript-example.ts` - TypeScript usage
221
+
222
+ ## Building from Source
223
+
224
+ ```bash
225
+ # Clone repository
226
+ git clone https://github.com/NazarKalytiuk/napi_rust_xlsxwrighter.git
227
+ cd napi_rust_xlsxwrighter
228
+
229
+ # Install dependencies
230
+ npm install
231
+
232
+ # Build native module
233
+ npm run build
234
+
235
+ # Run tests (577 tests)
236
+ npm test
237
+
238
+ # Run examples
239
+ node examples/basic.js
240
+ ```
241
+
242
+ ## Performance
243
+
244
+ ### Fast Native Performance
245
+
246
+ Built with Rust and NAPI-RS for native-level performance:
247
+ - **Fast execution**: Native Rust performance via NAPI bindings
248
+ - **Low memory usage**: Optimized memory footprint across all modes
249
+ - **Test performance**: All 577 tests complete in < 1 second
250
+
251
+ ### Memory Modes
252
+
253
+ **Memory Efficiency** (50% strings / 50% numbers):
254
+
255
+ | Rows | Standard | Low Memory | Constant Memory |
256
+ |------|----------|------------|-----------------|
257
+ | 100K | 18.0 MB | 3.0 MB | 0.0215 MB |
258
+ | 1M | 216.8 MB | 41.7 MB | 0.0215 MB |
259
+ | 10M | ~2.2 GB | ~420 MB | 0.0215 MB |
260
+
261
+ **Mode Recommendations:**
262
+ - **< 1K rows**: Default mode (fastest)
263
+ - **1K-100K rows**: Low memory mode (best balance)
264
+ - **> 100K rows**: Constant memory mode (minimal footprint)
265
+ - **Serverless/Cloud**: Low or constant memory modes
266
+
267
+ ## Limitations
268
+
269
+ - ❌ **Read-only**: Cannot read existing Excel files (rust_xlsxwriter is write-only)
270
+ - ❌ **Memory mode constraints**: Constant/low memory modes require sequential row writing
271
+
272
+ ## Contributing
273
+
274
+ Contributions are welcome! Please submit a Pull Request.
275
+
276
+ ## License
277
+
278
+ MIT
279
+
280
+ ## Acknowledgments
281
+
282
+ - [rust_xlsxwriter](https://github.com/jmcnamara/rust_xlsxwriter) - The excellent underlying Rust library
283
+ - [NAPI-RS](https://napi.rs/) - For making Rust/Node.js bindings seamless
284
+
285
+ ## Links
286
+
287
+ - [GitHub Repository](https://github.com/NazarKalytiuk/napi_rust_xlsxwrighter)
288
+ - [rust_xlsxwriter Documentation](https://docs.rs/rust_xlsxwriter/latest/rust_xlsxwriter/)
289
+ - [NAPI-RS Documentation](https://napi.rs/)