@niicojs/excel 0.1.0

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) 2026 niico
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,208 @@
1
+ # @niicojs/excel
2
+
3
+ A TypeScript library for Excel/OpenXML manipulation with maximum format preservation.
4
+
5
+ ## Features
6
+
7
+ - Read and write `.xlsx` files
8
+ - Preserve formatting when modifying existing files
9
+ - Full formula support (read/write/preserve)
10
+ - Cell styles (fonts, fills, borders, alignment)
11
+ - Merged cells
12
+ - Sheet operations (add, delete, rename, copy)
13
+ - Create new workbooks from scratch
14
+ - TypeScript-first with full type definitions
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pnpm install @niicojs/excel
20
+ # or
21
+ bun add @niicojs/excel
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ```typescript
27
+ import { Workbook } from '@niicojs/excel';
28
+
29
+ // Create a new workbook
30
+ const wb = Workbook.create();
31
+ const sheet = wb.sheet('Sheet1');
32
+
33
+ // Write data
34
+ sheet.cell('A1').value = 'Hello';
35
+ sheet.cell('B1').value = 42;
36
+ sheet.cell('C1').value = true;
37
+ sheet.cell('D1').value = new Date();
38
+
39
+ // Write formulas
40
+ sheet.cell('A2').formula = 'SUM(B1:B1)';
41
+
42
+ // Write a 2D array
43
+ sheet.cell('A3').values = [
44
+ ['Name', 'Age', 'City'],
45
+ ['Alice', 30, 'NYC'],
46
+ ['Bob', 25, 'LA'],
47
+ ];
48
+
49
+ // Save to file
50
+ await wb.toFile('output.xlsx');
51
+ ```
52
+
53
+ ## Loading Existing Files
54
+
55
+ ```typescript
56
+ import { Workbook } from '@niicojs/excel';
57
+
58
+ // Load from file
59
+ const wb = await Workbook.fromFile('template.xlsx');
60
+
61
+ // Or load from buffer
62
+ const buffer = await fetch('https://example.com/file.xlsx').then((r) => r.arrayBuffer());
63
+ const wb = await Workbook.fromBuffer(new Uint8Array(buffer));
64
+
65
+ // Read data
66
+ const sheet = wb.sheet('Sheet1');
67
+ console.log(sheet.cell('A1').value); // The cell value
68
+ console.log(sheet.cell('A1').formula); // The formula (if any)
69
+ console.log(sheet.cell('A1').type); // 'string' | 'number' | 'boolean' | 'date' | 'error' | 'empty'
70
+ ```
71
+
72
+ ## Working with Ranges
73
+
74
+ ```typescript
75
+ const sheet = wb.sheet(0);
76
+
77
+ // Read a range
78
+ const values = sheet.range('A1:C10').values; // 2D array
79
+
80
+ // Write to a range
81
+ sheet.range('A1:B2').values = [
82
+ [1, 2],
83
+ [3, 4],
84
+ ];
85
+
86
+ // Get formulas from a range
87
+ const formulas = sheet.range('A1:C10').formulas;
88
+ ```
89
+
90
+ ## Styling Cells
91
+
92
+ ```typescript
93
+ const sheet = wb.sheet(0);
94
+
95
+ // Apply styles to a cell
96
+ sheet.cell('A1').style = {
97
+ bold: true,
98
+ italic: true,
99
+ fontSize: 14,
100
+ fontName: 'Arial',
101
+ fontColor: '#FF0000',
102
+ fill: '#FFFF00',
103
+ border: {
104
+ top: 'thin',
105
+ bottom: 'medium',
106
+ left: 'thin',
107
+ right: 'thin',
108
+ },
109
+ alignment: {
110
+ horizontal: 'center',
111
+ vertical: 'middle',
112
+ wrapText: true,
113
+ },
114
+ numberFormat: '#,##0.00',
115
+ };
116
+
117
+ // Apply styles to a range
118
+ sheet.range('A1:C1').style = { bold: true, fill: '#CCCCCC' };
119
+ ```
120
+
121
+ ## Merged Cells
122
+
123
+ ```typescript
124
+ const sheet = wb.sheet(0);
125
+
126
+ // Merge cells
127
+ sheet.mergeCells('A1:C1');
128
+
129
+ // Or using two addresses
130
+ sheet.mergeCells('A1', 'C1');
131
+
132
+ // Unmerge
133
+ sheet.unmergeCells('A1:C1');
134
+
135
+ // Get all merged regions
136
+ console.log(sheet.mergedCells); // ['A1:C3', 'D5:E10', ...]
137
+ ```
138
+
139
+ ## Sheet Operations
140
+
141
+ ```typescript
142
+ const wb = Workbook.create();
143
+
144
+ // Add sheets
145
+ wb.addSheet('Data');
146
+ wb.addSheet('Summary', 0); // Insert at index 0
147
+
148
+ // Get sheet names
149
+ console.log(wb.sheetNames); // ['Summary', 'Sheet1', 'Data']
150
+
151
+ // Access sheets
152
+ const sheet = wb.sheet('Data'); // By name
153
+ const sheet = wb.sheet(0); // By index
154
+
155
+ // Rename sheet
156
+ wb.renameSheet('Data', 'RawData');
157
+
158
+ // Copy sheet
159
+ wb.copySheet('RawData', 'RawData_Backup');
160
+
161
+ // Delete sheet
162
+ wb.deleteSheet('Summary');
163
+ ```
164
+
165
+ ## Saving
166
+
167
+ ```typescript
168
+ // Save to file
169
+ await wb.toFile('output.xlsx');
170
+
171
+ // Save to buffer (Uint8Array)
172
+ const buffer = await wb.toBuffer();
173
+ ```
174
+
175
+ ## Type Definitions
176
+
177
+ ```typescript
178
+ // Cell values
179
+ type CellValue = number | string | boolean | Date | null | CellError;
180
+
181
+ interface CellError {
182
+ error: '#NULL!' | '#DIV/0!' | '#VALUE!' | '#REF!' | '#NAME?' | '#NUM!' | '#N/A';
183
+ }
184
+
185
+ // Cell types
186
+ type CellType = 'number' | 'string' | 'boolean' | 'date' | 'error' | 'empty';
187
+
188
+ // Border types
189
+ type BorderType = 'thin' | 'medium' | 'thick' | 'double' | 'dotted' | 'dashed';
190
+ ```
191
+
192
+ ## Format Preservation
193
+
194
+ When modifying existing Excel files, this library preserves:
195
+
196
+ - Cell formatting and styles
197
+ - Formulas
198
+ - Charts and images
199
+ - Merged cells
200
+ - Conditional formatting
201
+ - Data validation
202
+ - And other Excel features
203
+
204
+ This is achieved by only modifying what's necessary and keeping the original XML structure intact.
205
+
206
+ ## License
207
+
208
+ MIT