xlsx-handlebars 0.2.1

A Rust library for processing XLSX files with Handlebars templates, supporting WASM, Node.js, Deno, and browsers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
# xlsx-handlebars

[![Crates.io](https://img.shields.io/crates/v/xlsx-handlebars.svg)](https://crates.io/crates/xlsx-handlebars)
[![Documentation](https://docs.rs/xlsx-handlebars/badge.svg)](https://docs.rs/xlsx-handlebars)
[![License](https://img.shields.io/crates/l/xlsx-handlebars.svg)](https://github.com/sail-sail/xlsx-handlebars#license)

English | [δΈ­ζ–‡ζ–‡ζ‘£]README_CN.md | [Demo]https://sail-sail.github.io/xlsx-handlebars-demo/ 

A Rust library for processing XLSX files with Handlebars templates, supporting multiple platforms:
- πŸ¦€ Rust Native
- 🌐 WebAssembly (WASM)
- πŸ“¦ npm Package
- 🟒 Node.js
- πŸ¦• Deno
- 🌍 Browser
- πŸ“‹ JSR (JavaScript Registry)

## Features

- ⚑ **High Performance**: Renders 100,000 rows in just 2.12 seconds (~47,000 rows/sec) - 14-28x faster than Python, 7-14x faster than JavaScript
- βœ… **Smart Merge**: Automatically handles Handlebars syntax split by XML tags
- βœ… **XLSX Validation**: Built-in file format validation to ensure valid input files
- βœ… **Handlebars Support**: Full template engine with variables, conditions, loops, and Helper functions
- βœ… **Cross-Platform**: Rust native + WASM support for multiple runtimes
- βœ… **TypeScript**: Complete type definitions and IntelliSense
- βœ… **Zero Dependencies**: WASM binary with no external dependencies

## Installation

### Rust

```bash
cargo add xlsx-handlebars
```

### npm

```bash
npm install xlsx-handlebars
```

### Deno

```typescript
import init, { render_template } from "jsr:@sail/xlsx-handlebars";
```

## Usage Examples

### Rust

```rust
use xlsx_handlebars::render_template;
use serde_json::json;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Read XLSX template file
    let template_bytes = std::fs::read("template.xlsx")?;
    
    // Prepare data
    let data = json!({
        "name": "John Doe",
        "company": "ABC Tech Inc.",
        "position": "Software Engineer",
        "projects": [
            {"name": "Project A", "status": "Completed"},
            {"name": "Project B", "status": "In Progress"}
        ],
        "has_bonus": true,
        "bonus_amount": 5000
    });
    
    // Render template
    let result = render_template(template_bytes, &data)?;
    
    // Save result
    std::fs::write("output.xlsx", result)?;
    
    Ok(())
}
```

### JavaScript/TypeScript (Node.js)

```javascript
import init, { render_template } from 'xlsx-handlebars';
import fs from 'fs';

async function processTemplate() {
    // Initialize WASM module
    await init();
    
    // Read template file
    const templateBytes = fs.readFileSync('template.xlsx');
    
    // Prepare data
    const data = {
        name: "Jane Smith",
        company: "XYZ Technology Ltd.",
        position: "Senior Developer",
        projects: [
            { name: "E-commerce Platform", status: "Completed" },
            { name: "Mobile App", status: "In Development" }
        ],
        has_bonus: true,
        bonus_amount: 8000
    };
    
    // Render template
    const result = render_template(templateBytes, JSON.stringify(data));
    
    // Save result
    fs.writeFileSync('output.xlsx', new Uint8Array(result));
}

processTemplate().catch(console.error);
```

### Deno

```typescript
import init, { render_template } from "https://deno.land/x/xlsx_handlebars/mod.ts";

async function processTemplate() {
    // Initialize WASM module
    await init();
    
    // Read template file
    const templateBytes = await Deno.readFile("template.xlsx");
    
    // Prepare data
    const data = {
        name: "Alice Johnson",
        department: "R&D",
        projects: [
            { name: "AI Customer Service", status: "Live" },
            { name: "Data Visualization Platform", status: "In Development" }
        ]
    };
    
    // Render template
    const result = render_template(templateBytes, JSON.stringify(data));
    
    // Save result
    await Deno.writeFile("output.xlsx", new Uint8Array(result));
}

if (import.meta.main) {
    await processTemplate();
}
```

### Browser

```html
<!DOCTYPE html>
<html>
<head>
    <title>XLSX Handlebars Example</title>
</head>
<body>
    <input type="file" id="fileInput" accept=".xlsx">
    <button onclick="processFile()">Process Template</button>
    
    <script type="module">
        import init, { render_template } from './pkg/xlsx_handlebars.js';
        
        // Initialize WASM
        await init();
        
        window.processFile = async function() {
            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];
            
            if (!file) return;
            
            const arrayBuffer = await file.arrayBuffer();
            const templateBytes = new Uint8Array(arrayBuffer);
            
            const data = {
                name: "John Doe",
                company: "Example Company"
            };
            
            try {
                const result = render_template(templateBytes, JSON.stringify(data));
                
                // Download result
                const blob = new Blob([new Uint8Array(result)], {
                    type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
                });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = 'processed.xlsx';
                a.click();
            } catch (error) {
                console.error('Processing failed:', error);
            }
        };
    </script>
</body>
</html>
```

## Template Syntax

### Basic Variable Substitution

```handlebars
Employee Name: {{name}}
Company: {{company}}
Position: {{position}}
```

### Conditional Rendering

```handlebars
{{#if has_bonus}}
Bonus: ${{bonus_amount}}
{{else}}
No Bonus
{{/if}}

{{#unless is_intern}}
Full-time Employee
{{/unless}}
```

### Loop Rendering

```handlebars
Project Experience:
{{#each projects}}
- {{name}}: {{description}} ({{status}})
{{/each}}

Skills:
{{#each skills}}
{{@index}}. {{this}}
{{/each}}
```

### Helper Functions

Built-in Helper functions:

```handlebars
<!-- Basic helpers -->
{{upper name}}           <!-- Convert to uppercase -->
{{lower company}}        <!-- Convert to lowercase -->
{{len projects}}         <!-- Array length -->
{{#if (eq status "completed")}}Completed{{/if}}    <!-- Equality comparison -->
{{#if (gt score 90)}}Excellent{{/if}}              <!-- Greater than comparison -->
{{#if (lt age 30)}}Young{{/if}}                    <!-- Less than comparison -->

<!-- String concatenation -->
{{concat "Hello" " " "World"}}                     <!-- String concatenation -->
{{concat "Total: " count}}                         <!-- Mix strings and variables -->

<!-- Excel-specific helpers -->
{{num employee.salary}}                            <!-- Mark cell as number type -->
{{formula "=SUM(A1:B1)"}}                         <!-- Static Excel formula -->
{{formula (concat "=SUM(" (_c) "1:" (_c) "10)")}} <!-- Dynamic formula with current column -->
{{mergeCell "C4:D5"}}                             <!-- Merge cells C4 to D5 -->
{{img logo.data 100 100}}                          <!-- Insert image with width and height -->

<!-- Column name conversion helpers -->
{{toColumnName "A" 5}}                             <!-- A + 5 offset = F -->
{{toColumnName (_c) 3}}                            <!-- Current column + 3 offset -->
{{toColumnIndex "AA"}}                             <!-- AA column index = 27 -->
```

#### Excel Formula Helpers

**Static Formula**:
```handlebars
<!-- In Excel cell -->
{{formula "=SUM(A1:B1)"}}
{{formula "=AVERAGE(C2:C10)"}}
{{formula "=IF(D1>100,\"High\",\"Low\")"}}
```

**Dynamic Formula with `concat`**:
```handlebars
<!-- Dynamic row reference -->
{{formula (concat "=A" (_r) "*B" (_r))}}

<!-- Dynamic column reference -->
{{formula (concat "=SUM(" (_c) "2:" (_c) "10)")}}

<!-- Complex dynamic formula -->
{{formula (concat "=IF(" (_cr) ">100,\"High\",\"Low\")")}}
```

**Available position helpers**:
- `(_c)` - Current column letter (A, B, C, ...)
- `(_r)` - Current row number (1, 2, 3, ...)
- `(_cr)` - Current cell reference (A1, B2, C3, ...)

#### Column Name Conversion Helpers

**`toColumnName`** - Convert column name or index to a new column name with optional offset:

```handlebars
<!-- Basic usage: offset from specified column -->
{{toColumnName "A" 0}}     <!-- A (no offset) -->
{{toColumnName "A" 5}}     <!-- F (A + 5) -->
{{toColumnName "Z" 1}}     <!-- AA (Z + 1) -->

<!-- Use with current column -->
{{toColumnName (_c) 3}}    <!-- Current column + 3 offset -->

<!-- Application in dynamic formulas -->
{{formula (concat "=SUM(" (_c) "1:" (toColumnName (_c) 3) "1)")}}
<!-- Example: If current column is B, generates formula =SUM(B1:E1) -->
```

**`toColumnIndex`** - Convert column name to column index (1-based):

```handlebars
{{toColumnIndex "A"}}      <!-- 1 -->
{{toColumnIndex "Z"}}      <!-- 26 -->
{{toColumnIndex "AA"}}     <!-- 27 -->
{{toColumnIndex "AB"}}     <!-- 28 -->
```

#### Merge Cells Helper

**`mergeCell`** - Mark cell ranges that need to be merged:

```handlebars
<!-- Static cell merging -->
{{mergeCell "C4:D5"}}      <!-- Merge C4 to D5 region -->
{{mergeCell "F4:G4"}}      <!-- Merge F4 to G4 region -->

<!-- Dynamic cell merging: from current position -->
{{mergeCell (concat (_c) (_r) ":" (toColumnName (_c) 3) (_r))}}
<!-- Example: If current is B5, merges B5:E5 (4 columns to the right) -->

<!-- Dynamic cell merging: spanning rows and columns -->
{{mergeCell (concat (_c) (_r) ":" (toColumnName (_c) 2) (add (_r) 2))}}
<!-- Example: If current is C3, merges C3:E5 (3Γ—3 region) -->

<!-- Dynamic merging in loops -->
{{#each sections}}
  {{mergeCell (concat "A" (add @index 2) ":D" (add @index 2))}}
  <!-- Merge columns A-D for each section row -->
{{/each}}
```

**Notes**:
- `mergeCell` produces no output, only collects merge information
- Merge range format must be `StartCell:EndCell` (e.g., `"A1:B2"`)
- Duplicate merge ranges are automatically deduplicated
- Merge information is automatically added to the Excel file after rendering

#### Hyperlink Helper

**`hyperlink`** - Add hyperlinks to Excel cells:

```handlebars
<!-- Basic usage: link to another worksheet -->
{{hyperlink (_cr) "Sheet2!A1" "View Details"}}

<!-- Link to external URL (requires pre-configuration in template) -->
{{hyperlink (_cr) "https://example.com" "Visit Website"}}

<!-- Dynamic links -->
{{#each items}}
  {{hyperlink (_cr) (concat "Details!" name) name}}
{{/each}}
```

**Parameters**:
- First parameter: Cell reference, typically use `(_cr)` for current cell
- Second parameter: Link target (worksheet reference or URL)
- Third parameter: Display text (optional)

**Notes**:
- `hyperlink` produces no output, only collects hyperlink information
- Hyperlinks are automatically added to the Excel file after rendering
- Supports internal worksheet references (e.g., `"Sheet2!A1"`)
- External links require pre-configured relationships in the template Excel file

#### Number Type Helper

Use `{{num value}}` to ensure a cell is treated as a number in Excel:

```handlebars
<!-- Without num: treated as text -->
{{employee.salary}}

<!-- With num: treated as number -->
{{num employee.salary}}
```

This is especially useful when:
- The value might be a string but should be treated as a number
- You want to ensure proper number formatting in Excel
- You need the value to work in formulas

#### Image Insertion Helper

**`img`** - Insert base64-encoded images into Excel:

```handlebars
<!-- Basic usage: insert image with original dimensions -->
{{img logo.data}}

<!-- Specify width and height (in pixels) -->
{{img photo.data 150 200}}

<!-- Use dimensions from data -->
{{img image.data image.width image.height}}
```

**Features**:
- βœ… Supports common image formats: PNG, JPEG, WebP, BMP, TIFF, GIF
- βœ… Auto-detects actual image dimensions
- βœ… Optional width and height specification (in pixels)
- βœ… Image positioned at current cell location
- βœ… Images are not constrained by cell size, maintain aspect ratio
- βœ… Supports multiple images in the same sheet
- βœ… Supports images in multiple sheets
- βœ… Uses UUID to avoid ID conflicts

**Complete Example**:

```javascript
// Prepare image data in JavaScript
import fs from 'fs';

const imageBuffer = fs.readFileSync('logo.png');
const base64Image = imageBuffer.toString('base64');

const data = {
  company: {
    logo: base64Image,
    name: "Tech Company"
  },
  products: [
    {
      name: "Product A",
      photo: base64Image,
      width: 120,
      height: 120
    },
    {
      name: "Product B", 
      photo: base64Image,
      width: 100,
      height: 100
    }
  ]
};

// Use in template
```

```handlebars
<!-- Excel template example -->
Company Logo: {{img company.logo 100 50}}

Product List:
{{#each products}}
Product Name: {{name}}
Image: {{img photo width height}}
{{/each}}
```

**Usage Tips**:
- If only width is specified, height scales proportionally
- If only height is specified, width scales proportionally
- If neither is specified, original image dimensions are used
- Image will be placed at the cell location where `{{img}}` is called
- base64 data should not include the `data:image/png;base64,` prefix, just the pure base64 string

#### Worksheet Management Helpers

**`deleteCurrentSheet`** - Delete the current worksheet being rendered:

```handlebars
<!-- Basic usage -->
{{deleteCurrentSheet}}

<!-- Conditional deletion -->
{{#if shouldDelete}}
  {{deleteCurrentSheet}}
{{/if}}

<!-- Delete inactive sheets -->
{{#unless isActive}}
  {{deleteCurrentSheet}}
{{/unless}}
```

**Features**:
- βœ… Removes worksheet and its relationships from workbook
- βœ… Cleans up related files (rels, content types)
- βœ… Drawing files are preserved (safe approach)
- βœ… Cannot delete the last worksheet (Excel requirement)
- βœ… Delayed execution after all rendering completes

**`setCurrentSheetName`** - Rename the current worksheet:

```handlebars
<!-- Static name -->
{{setCurrentSheetName "Sales Report"}}

<!-- Dynamic name -->
{{setCurrentSheetName (concat department.name " - " year)}}

<!-- Loop-based naming -->
{{#each departments}}
  {{setCurrentSheetName (concat "Department " @index " - " name)}}
{{/each}}
```

**Features**:
- βœ… Auto-filters invalid characters: `\ / ? * [ ]`
- βœ… Auto-limits length to 31 characters
- βœ… Auto-handles duplicate names with numeric suffixes
- βœ… Supports dynamic name generation

**`hideCurrentSheet`** - Hide the current worksheet:

```handlebars
<!-- Normal hide (user can unhide via right-click) -->
{{hideCurrentSheet}}
{{hideCurrentSheet "hidden"}}

<!-- Very hidden (requires VBA to unhide) -->
{{hideCurrentSheet "veryHidden"}}

<!-- Conditional hiding -->
{{#unless (eq userRole "admin")}}
  {{hideCurrentSheet "veryHidden"}}
{{/unless}}
```

**Hide Levels**:
- `hidden` - Normal hide, users can unhide via Excel's right-click menu
- `veryHidden` - Super hide, requires VBA or property editor to unhide

**Features**:
- βœ… Cannot hide all worksheets (Excel requires at least one visible)
- βœ… Two hiding levels: normal and super hidden
- βœ… Useful for permission control and sensitive data

**Common Use Cases**:

```handlebars
<!-- Multi-language reports: delete unused language sheets -->
{{#if (ne language "en-US")}}
  {{deleteCurrentSheet}}
{{/if}}

<!-- Dynamic department reports: rename sheets by department -->
{{setCurrentSheetName (concat department.name " Report")}}

<!-- Permission control: hide admin sheets from regular users -->
{{#unless (eq userRole "admin")}}
  {{hideCurrentSheet "veryHidden"}}
{{/unless}}

<!-- Conditional workflow: delete, rename, or hide based on status -->
{{#if (eq status "inactive")}}
  {{deleteCurrentSheet}}
{{else}}
  {{setCurrentSheetName (concat "Active - " name)}}
  {{#if isInternal}}
    {{hideCurrentSheet}}
  {{/if}}
{{/if}}
```

### Complex Example

```handlebars
=== Employee Report ===

Basic Information:
Name: {{employee.name}}
Department: {{employee.department}}
Position: {{employee.position}}
Hire Date: {{employee.hire_date}}

{{#if employee.has_bonus}}
πŸ’° Bonus: ${{employee.bonus_amount}}
{{/if}}

Project Experience (Total {{len projects}}):
{{#each projects}}
{{@index}}. {{name}}
   Description: {{description}}
   Status: {{status}}
   Team Size: {{team_size}} people
   
{{/each}}

Skills Assessment:
{{#each skills}}
- {{name}}: {{level}}/10 ({{years}} years of experience)
{{/each}}

To remove an entire row in a table, simply add to any cell:
{{removeRow}}


{{#if (gt performance.score 90)}}
πŸŽ‰ Performance Rating: Excellent
{{else if (gt performance.score 80)}}
πŸ‘ Performance Rating: Good
{{else}}
πŸ“ˆ Performance Rating: Needs Improvement
{{/if}}
```

## Build and Development

### Build WASM Package

```bash
# Build all targets
npm run build

# Or build separately
npm run build:web    # Browser version
npm run build:npm    # Node.js version 
npm run build:jsr    # Deno version
```

### Run Examples

```bash
# Rust example
cargo run --example rust_example

# Node.js example
node examples/node_example.js

# Deno example  
deno run --allow-read --allow-write examples/deno_example.ts

# Browser example
cd tests/npm_test
node serve.js
# Then open http://localhost:8080 in your browser
# Select examples/template.xlsx file to test
```

## Utility Functions

xlsx-handlebars provides a set of utility functions to help you work more efficiently with Excel operations.

### Excel Column Name Conversion

Convert between Excel column names and column indices.

```rust
use xlsx_handlebars::{to_column_name, to_column_index};

// Column name increment
assert_eq!(to_column_name("A", 0), "A");
assert_eq!(to_column_name("A", 1), "B");
assert_eq!(to_column_name("Z", 1), "AA");
assert_eq!(to_column_name("AA", 1), "AB");

// Column name to index (1-based)
assert_eq!(to_column_index("A"), 1);
assert_eq!(to_column_index("Z"), 26);
assert_eq!(to_column_index("AA"), 27);
assert_eq!(to_column_index("BA"), 53);
```

**JavaScript/TypeScript Example**:

```javascript
import { wasm_to_column_name, wasm_to_column_index } from 'xlsx-handlebars';

// Column name increment
console.log(wasm_to_column_name("A", 1));  // "B"
console.log(wasm_to_column_name("Z", 1));  // "AA"

// Column name to index
console.log(wasm_to_column_index("AA"));   // 27
console.log(wasm_to_column_index("BA"));   // 53
```

### Excel Date Conversion

Convert between Unix timestamps and Excel date serial numbers. Excel uses serial numbers starting from 1900-01-01 to represent dates.

```rust
use xlsx_handlebars::{timestamp_to_excel_date, excel_date_to_timestamp};

// Timestamp to Excel date
let timestamp = 1704067200000i64;  // 2024-01-01 00:00:00 UTC
let excel_date = timestamp_to_excel_date(timestamp);
println!("Excel date serial number: {}", excel_date);  // 45294.0

// Excel date to timestamp
if let Some(ts) = excel_date_to_timestamp(45294.0) {
    println!("Timestamp: {}", ts);  // 1704067200000
}
```

**JavaScript/TypeScript Example**:

```javascript
import { 
    wasm_timestamp_to_excel_date, 
    wasm_excel_date_to_timestamp 
} from 'xlsx-handlebars';

// Date to Excel serial number
const date = new Date('2024-01-01T00:00:00Z');
const excelDate = wasm_timestamp_to_excel_date(date.getTime());
console.log('Excel date:', excelDate);  // 45294.0

// Excel serial number to date
const timestamp = wasm_excel_date_to_timestamp(45294.0);
if (timestamp !== null) {
    const convertedDate = new Date(timestamp);
    console.log('Date:', convertedDate.toISOString());
}
```

**Common Use Cases**:

```rust
// Dynamically generate cell references
let start_col = "B";
let num_cols = 5;
for i in 0..num_cols {
    let col_name = to_column_name(start_col, i);
    let col_index = to_column_index(&col_name);
    println!("Column {}: name={}, index={}", i, col_name, col_index);
}
```

```rust
// Include dates in template data
use serde_json::json;

let date_timestamp = 1704067200000i64;  // 2024-01-01
let excel_date = timestamp_to_excel_date(date_timestamp);

let data = json!({
    "report_date": excel_date,
    "employee": {
        "name": "John Doe",
        "hire_date": timestamp_to_excel_date(1609459200000i64)  // 2021-01-01
    }
});
```

These utility functions help you:
- βœ… Dynamically generate cell references and formulas
- βœ… Handle Excel date formats
- βœ… Avoid loading heavy external libraries
- βœ… Support both Rust and JavaScript/TypeScript

## Technical Features

## Performance and Compatibility

### Blazing Fast Performance ⚑

xlsx-handlebars delivers **industry-leading performance** powered by Rust:

| Data Size | Processing Time | Throughput |
|-----------|----------------|------------|
| 1,000 rows | ~0.02s | Real-time generation |
| 10,000 rows | ~0.21s | Online exports |
| 100,000 rows | ~2.12s | Batch processing |
| 1,000,000 rows | ~21s | Big data reports |

**Performance Comparison** (100,000 rows):

| Technology | Time | Speed vs xlsx-handlebars |
|-----------|------|-------------------------|
| **xlsx-handlebars (Rust)** | **2.12s** | **1x (baseline)** ⭐ |
| Python (openpyxl) | 30-60s | 14-28x slower |
| JavaScript (xlsx.js) | 15-30s | 7-14x slower |
| Java (Apache POI) | 8-15s | 3-7x slower |
| C# (EPPlus) | 5-10s | 2-4x slower |

**Why So Fast?**
- πŸ¦€ **Rust's Zero-Cost Abstractions**: Compile-time optimizations with no runtime overhead
- πŸ”„ **Streaming Architecture**: Process ZIP entries directly in memory without file I/O
- ⚑ **Event-Driven XML Parsing**: Uses quick-xml for efficient parsing without building full DOM trees
- 🎯 **Single-Pass Rendering**: All template substitutions in one iteration

### Compatibility

- **Zero-Copy**: Efficient memory management between Rust and WASM
- **Streaming**: Suitable for processing large XLSX files
- **Cross-Platform**: Supports Windows, macOS, Linux, Web
- **Modern Browsers**: Supports all modern browsers with WASM support

## License

This project is licensed under the MIT License - see the [LICENSE-MIT](LICENSE-MIT) file for details.

## Support

- πŸ“š [Documentation]https://docs.rs/xlsx-handlebars
- πŸ› [Issues]https://github.com/sail-sail/xlsx-handlebars/issues
- πŸ’¬ [Discussions]https://github.com/sail-sail/xlsx-handlebars/discussions

---

<div align="center">
  <p>
    <strong>xlsx-handlebars</strong> - Making XLSX template processing simple and efficient
  </p>
  <p>
    <a href="https://github.com/sail-sail/xlsx-handlebars">⭐ Star the project</a>
    Β·
    <a href="https://github.com/sail-sail/xlsx-handlebars/issues">πŸ› Report Issues</a>
    Β·
    <a href="https://github.com/sail-sail/xlsx-handlebars/discussions">πŸ’¬ Join Discussions</a>
  </p>
</div>


## Support this project with a donation via Alipay:
![Support this project with a donation](https://www.ejsexcel.com/alipay.jpg)