@niicojs/excel 0.3.4 → 0.3.6
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 +20 -20
- package/README.md +8 -2
- package/dist/index.cjs +1191 -1266
- package/dist/index.d.cts +171 -324
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +171 -324
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1191 -1267
- package/package.json +4 -4
- package/src/index.ts +8 -10
- package/src/pivot-table.ts +619 -524
- package/src/shared-strings.ts +33 -9
- package/src/styles.ts +38 -9
- package/src/types.ts +295 -323
- package/src/utils/address.ts +48 -0
- package/src/utils/format.ts +8 -7
- package/src/utils/xml.ts +7 -4
- package/src/utils/zip.ts +153 -11
- package/src/workbook.ts +330 -350
- package/src/worksheet.ts +1003 -935
- package/src/pivot-cache.ts +0 -449
package/src/types.ts
CHANGED
|
@@ -1,332 +1,293 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cell value types - what a cell can contain
|
|
3
|
-
*/
|
|
4
|
-
export type CellValue = number | string | boolean | Date | null | CellError;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Represents an Excel error value
|
|
8
|
-
*/
|
|
9
|
-
export interface CellError {
|
|
10
|
-
error: ErrorType;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type ErrorType = '#NULL!' | '#DIV/0!' | '#VALUE!' | '#REF!' | '#NAME?' | '#NUM!' | '#N/A' | '#GETTING_DATA';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Discriminator for cell content type
|
|
17
|
-
*/
|
|
18
|
-
export type CellType = 'number' | 'string' | 'boolean' | 'date' | 'error' | 'empty';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Date handling strategy when serializing cell values.
|
|
22
|
-
*/
|
|
23
|
-
export type DateHandling = 'jsDate' | 'excelSerial' | 'isoString';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Style definition for cells
|
|
27
|
-
*/
|
|
28
|
-
export interface CellStyle {
|
|
29
|
-
bold?: boolean;
|
|
30
|
-
italic?: boolean;
|
|
31
|
-
underline?: boolean | 'single' | 'double';
|
|
32
|
-
strike?: boolean;
|
|
33
|
-
fontSize?: number;
|
|
34
|
-
fontName?: string;
|
|
35
|
-
fontColor?: string;
|
|
36
|
-
fontColorTheme?: number;
|
|
37
|
-
fontColorTint?: number;
|
|
38
|
-
fontColorIndexed?: number;
|
|
39
|
-
fill?: string;
|
|
40
|
-
fillTheme?: number;
|
|
41
|
-
fillTint?: number;
|
|
42
|
-
fillIndexed?: number;
|
|
43
|
-
fillBgColor?: string;
|
|
44
|
-
fillBgTheme?: number;
|
|
45
|
-
fillBgTint?: number;
|
|
46
|
-
fillBgIndexed?: number;
|
|
47
|
-
border?: BorderStyle;
|
|
48
|
-
alignment?: Alignment;
|
|
49
|
-
numberFormat?: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface BorderStyle {
|
|
53
|
-
top?: BorderType;
|
|
54
|
-
bottom?: BorderType;
|
|
55
|
-
left?: BorderType;
|
|
56
|
-
right?: BorderType;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type BorderType = 'thin' | 'medium' | 'thick' | 'double' | 'dotted' | 'dashed';
|
|
60
|
-
|
|
61
|
-
export interface Alignment {
|
|
62
|
-
horizontal?: 'left' | 'center' | 'right' | 'justify';
|
|
63
|
-
vertical?: 'top' | 'middle' | 'bottom';
|
|
64
|
-
wrapText?: boolean;
|
|
65
|
-
textRotation?: number;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Cell address with 0-indexed row and column
|
|
70
|
-
*/
|
|
71
|
-
export interface CellAddress {
|
|
72
|
-
row: number;
|
|
73
|
-
col: number;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Range address with start and end cells
|
|
78
|
-
*/
|
|
79
|
-
export interface RangeAddress {
|
|
80
|
-
start: CellAddress;
|
|
81
|
-
end: CellAddress;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Internal cell data representation
|
|
86
|
-
*/
|
|
87
|
-
export interface CellData {
|
|
88
|
-
/** Cell type: n=number, s=string (shared), str=inline string, b=boolean, e=error, d=date */
|
|
89
|
-
t?: 'n' | 's' | 'str' | 'b' | 'e' | 'd';
|
|
90
|
-
/** Raw value */
|
|
91
|
-
v?: number | string | boolean;
|
|
92
|
-
/** Formula (without leading =) */
|
|
93
|
-
f?: string;
|
|
94
|
-
/** Style index */
|
|
95
|
-
s?: number;
|
|
96
|
-
/** Formatted text (cached) */
|
|
97
|
-
w?: string;
|
|
98
|
-
/** Number format */
|
|
99
|
-
z?: string;
|
|
100
|
-
/** Array formula range */
|
|
101
|
-
F?: string;
|
|
102
|
-
/** Dynamic array formula flag */
|
|
103
|
-
D?: boolean;
|
|
104
|
-
/** Shared formula index */
|
|
105
|
-
si?: number;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Sheet definition from workbook.xml
|
|
110
|
-
*/
|
|
111
|
-
export interface SheetDefinition {
|
|
112
|
-
name: string;
|
|
113
|
-
sheetId: number;
|
|
114
|
-
rId: string;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Relationship definition
|
|
119
|
-
*/
|
|
120
|
-
export interface Relationship {
|
|
121
|
-
id: string;
|
|
122
|
-
type: string;
|
|
123
|
-
target: string;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
*
|
|
128
|
-
*/
|
|
129
|
-
export
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Cell value types - what a cell can contain
|
|
3
|
+
*/
|
|
4
|
+
export type CellValue = number | string | boolean | Date | null | CellError;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents an Excel error value
|
|
8
|
+
*/
|
|
9
|
+
export interface CellError {
|
|
10
|
+
error: ErrorType;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ErrorType = '#NULL!' | '#DIV/0!' | '#VALUE!' | '#REF!' | '#NAME?' | '#NUM!' | '#N/A' | '#GETTING_DATA';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Discriminator for cell content type
|
|
17
|
+
*/
|
|
18
|
+
export type CellType = 'number' | 'string' | 'boolean' | 'date' | 'error' | 'empty';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Date handling strategy when serializing cell values.
|
|
22
|
+
*/
|
|
23
|
+
export type DateHandling = 'jsDate' | 'excelSerial' | 'isoString';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Style definition for cells
|
|
27
|
+
*/
|
|
28
|
+
export interface CellStyle {
|
|
29
|
+
bold?: boolean;
|
|
30
|
+
italic?: boolean;
|
|
31
|
+
underline?: boolean | 'single' | 'double';
|
|
32
|
+
strike?: boolean;
|
|
33
|
+
fontSize?: number;
|
|
34
|
+
fontName?: string;
|
|
35
|
+
fontColor?: string;
|
|
36
|
+
fontColorTheme?: number;
|
|
37
|
+
fontColorTint?: number;
|
|
38
|
+
fontColorIndexed?: number;
|
|
39
|
+
fill?: string;
|
|
40
|
+
fillTheme?: number;
|
|
41
|
+
fillTint?: number;
|
|
42
|
+
fillIndexed?: number;
|
|
43
|
+
fillBgColor?: string;
|
|
44
|
+
fillBgTheme?: number;
|
|
45
|
+
fillBgTint?: number;
|
|
46
|
+
fillBgIndexed?: number;
|
|
47
|
+
border?: BorderStyle;
|
|
48
|
+
alignment?: Alignment;
|
|
49
|
+
numberFormat?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface BorderStyle {
|
|
53
|
+
top?: BorderType;
|
|
54
|
+
bottom?: BorderType;
|
|
55
|
+
left?: BorderType;
|
|
56
|
+
right?: BorderType;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type BorderType = 'thin' | 'medium' | 'thick' | 'double' | 'dotted' | 'dashed';
|
|
60
|
+
|
|
61
|
+
export interface Alignment {
|
|
62
|
+
horizontal?: 'left' | 'center' | 'right' | 'justify';
|
|
63
|
+
vertical?: 'top' | 'middle' | 'bottom';
|
|
64
|
+
wrapText?: boolean;
|
|
65
|
+
textRotation?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Cell address with 0-indexed row and column
|
|
70
|
+
*/
|
|
71
|
+
export interface CellAddress {
|
|
72
|
+
row: number;
|
|
73
|
+
col: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Range address with start and end cells
|
|
78
|
+
*/
|
|
79
|
+
export interface RangeAddress {
|
|
80
|
+
start: CellAddress;
|
|
81
|
+
end: CellAddress;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Internal cell data representation
|
|
86
|
+
*/
|
|
87
|
+
export interface CellData {
|
|
88
|
+
/** Cell type: n=number, s=string (shared), str=inline string, b=boolean, e=error, d=date */
|
|
89
|
+
t?: 'n' | 's' | 'str' | 'b' | 'e' | 'd';
|
|
90
|
+
/** Raw value */
|
|
91
|
+
v?: number | string | boolean;
|
|
92
|
+
/** Formula (without leading =) */
|
|
93
|
+
f?: string;
|
|
94
|
+
/** Style index */
|
|
95
|
+
s?: number;
|
|
96
|
+
/** Formatted text (cached) */
|
|
97
|
+
w?: string;
|
|
98
|
+
/** Number format */
|
|
99
|
+
z?: string;
|
|
100
|
+
/** Array formula range */
|
|
101
|
+
F?: string;
|
|
102
|
+
/** Dynamic array formula flag */
|
|
103
|
+
D?: boolean;
|
|
104
|
+
/** Shared formula index */
|
|
105
|
+
si?: number;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sheet definition from workbook.xml
|
|
110
|
+
*/
|
|
111
|
+
export interface SheetDefinition {
|
|
112
|
+
name: string;
|
|
113
|
+
sheetId: number;
|
|
114
|
+
rId: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Relationship definition
|
|
119
|
+
*/
|
|
120
|
+
export interface Relationship {
|
|
121
|
+
id: string;
|
|
122
|
+
type: string;
|
|
123
|
+
target: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Configuration for creating a sheet from an array of objects
|
|
128
|
+
*/
|
|
129
|
+
export interface SheetFromDataConfig<T extends object = Record<string, unknown>> {
|
|
130
|
+
/** Name of the sheet to create */
|
|
131
|
+
name: string;
|
|
132
|
+
/** Array of objects with the same structure */
|
|
133
|
+
data: T[];
|
|
134
|
+
/** Column definitions (optional - defaults to all keys from first object) */
|
|
135
|
+
columns?: ColumnConfig<T>[];
|
|
136
|
+
/** Apply header styling (bold text) (default: true) */
|
|
137
|
+
headerStyle?: boolean;
|
|
138
|
+
/** Starting cell address (default: 'A1') */
|
|
139
|
+
startCell?: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Column configuration for sheet data
|
|
144
|
+
*/
|
|
145
|
+
export interface ColumnConfig<T = Record<string, unknown>> {
|
|
146
|
+
/** Key from the object to use for this column */
|
|
147
|
+
key: keyof T;
|
|
148
|
+
/** Header text (optional - defaults to key name) */
|
|
149
|
+
header?: string;
|
|
150
|
+
/** Cell style for data cells in this column */
|
|
151
|
+
style?: CellStyle;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Rich cell value with optional formula and style.
|
|
156
|
+
* Use this when you need to set value, formula, or style for individual cells.
|
|
157
|
+
*/
|
|
158
|
+
export interface RichCellValue {
|
|
159
|
+
/** Cell value */
|
|
160
|
+
value?: CellValue;
|
|
161
|
+
/** Formula (without leading '=') */
|
|
162
|
+
formula?: string;
|
|
163
|
+
/** Cell style */
|
|
164
|
+
style?: CellStyle;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Configuration for creating an Excel Table (ListObject)
|
|
169
|
+
*/
|
|
170
|
+
export interface TableConfig {
|
|
171
|
+
/** Table name (must be unique within the workbook) */
|
|
172
|
+
name: string;
|
|
173
|
+
/** Data range including headers (e.g., "A1:D10") */
|
|
174
|
+
range: string;
|
|
175
|
+
/** First row contains headers (default: true) */
|
|
176
|
+
headerRow?: boolean;
|
|
177
|
+
/** Show total row at the bottom (default: false) */
|
|
178
|
+
totalRow?: boolean;
|
|
179
|
+
/** Table style configuration */
|
|
180
|
+
style?: TableStyleConfig;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Table style configuration options
|
|
185
|
+
*/
|
|
186
|
+
export interface TableStyleConfig {
|
|
187
|
+
/** Built-in table style name (e.g., "TableStyleMedium2", "TableStyleLight1") */
|
|
188
|
+
name?: string;
|
|
189
|
+
/** Show banded/alternating row colors (default: true) */
|
|
190
|
+
showRowStripes?: boolean;
|
|
191
|
+
/** Show banded/alternating column colors (default: false) */
|
|
192
|
+
showColumnStripes?: boolean;
|
|
193
|
+
/** Highlight first column with special formatting (default: false) */
|
|
194
|
+
showFirstColumn?: boolean;
|
|
195
|
+
/** Highlight last column with special formatting (default: false) */
|
|
196
|
+
showLastColumn?: boolean;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Pivot table aggregation functions.
|
|
201
|
+
*/
|
|
202
|
+
export type PivotAggregationType = 'sum' | 'count' | 'average' | 'min' | 'max';
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Pivot field sort order.
|
|
206
|
+
*/
|
|
207
|
+
export type PivotSortOrder = 'asc' | 'desc';
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Filter definition for pivot fields.
|
|
211
|
+
* Use either include or exclude, not both.
|
|
212
|
+
*/
|
|
213
|
+
export type PivotFieldFilter = { include: string[] } | { exclude: string[] };
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Value field configuration for pivot tables.
|
|
217
|
+
*/
|
|
218
|
+
export interface PivotValueConfig {
|
|
219
|
+
/** Source field name */
|
|
220
|
+
field: string;
|
|
221
|
+
/** Aggregation type (default: 'sum') */
|
|
222
|
+
aggregation?: PivotAggregationType;
|
|
223
|
+
/** Display name for the value field */
|
|
224
|
+
name?: string;
|
|
225
|
+
/** Number format to apply to values */
|
|
226
|
+
numberFormat?: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Configuration for creating a PivotTable.
|
|
231
|
+
*/
|
|
161
232
|
export interface PivotTableConfig {
|
|
162
|
-
/**
|
|
233
|
+
/** Pivot table name */
|
|
163
234
|
name: string;
|
|
164
|
-
/** Source data range with sheet name
|
|
235
|
+
/** Source data range with sheet name, e.g. "Data!A1:E100" */
|
|
165
236
|
source: string;
|
|
166
|
-
/** Target cell
|
|
237
|
+
/** Target cell with sheet name, e.g. "Summary!A3" */
|
|
167
238
|
target: string;
|
|
168
|
-
/** Refresh
|
|
239
|
+
/** Refresh pivot when opening workbook (default: true) */
|
|
169
240
|
refreshOnLoad?: boolean;
|
|
170
|
-
/** Save pivot cache data in the file (default: true) */
|
|
171
|
-
saveData?: boolean;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Internal representation of a pivot cache field
|
|
176
|
-
*/
|
|
177
|
-
export interface PivotCacheField {
|
|
178
|
-
/** Field name (from header row) */
|
|
179
|
-
name: string;
|
|
180
|
-
/** Field index (0-based) */
|
|
181
|
-
index: number;
|
|
182
|
-
/** Whether this field contains numbers */
|
|
183
|
-
isNumeric: boolean;
|
|
184
|
-
/** Whether this field contains dates */
|
|
185
|
-
isDate: boolean;
|
|
186
|
-
/** Whether this field contains boolean values */
|
|
187
|
-
hasBoolean: boolean;
|
|
188
|
-
/** Whether this field contains blank (null/undefined) values */
|
|
189
|
-
hasBlank: boolean;
|
|
190
|
-
/** Number format ID for this field (cache field numFmtId) */
|
|
191
|
-
numFmtId?: number;
|
|
192
|
-
/** Unique string values (for shared items) */
|
|
193
|
-
sharedItems: string[];
|
|
194
|
-
/** Min numeric value */
|
|
195
|
-
minValue?: number;
|
|
196
|
-
/** Max numeric value */
|
|
197
|
-
maxValue?: number;
|
|
198
|
-
/** Min date value (for date fields) */
|
|
199
|
-
minDate?: Date;
|
|
200
|
-
/** Max date value (for date fields) */
|
|
201
|
-
maxDate?: Date;
|
|
202
241
|
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
*
|
|
206
|
-
*/
|
|
207
|
-
export type
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Configuration for
|
|
211
|
-
*/
|
|
212
|
-
export interface
|
|
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
|
-
export interface TableConfig {
|
|
254
|
-
/** Table name (must be unique within the workbook) */
|
|
255
|
-
name: string;
|
|
256
|
-
/** Data range including headers (e.g., "A1:D10") */
|
|
257
|
-
range: string;
|
|
258
|
-
/** First row contains headers (default: true) */
|
|
259
|
-
headerRow?: boolean;
|
|
260
|
-
/** Show total row at the bottom (default: false) */
|
|
261
|
-
totalRow?: boolean;
|
|
262
|
-
/** Table style configuration */
|
|
263
|
-
style?: TableStyleConfig;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Table style configuration options
|
|
268
|
-
*/
|
|
269
|
-
export interface TableStyleConfig {
|
|
270
|
-
/** Built-in table style name (e.g., "TableStyleMedium2", "TableStyleLight1") */
|
|
271
|
-
name?: string;
|
|
272
|
-
/** Show banded/alternating row colors (default: true) */
|
|
273
|
-
showRowStripes?: boolean;
|
|
274
|
-
/** Show banded/alternating column colors (default: false) */
|
|
275
|
-
showColumnStripes?: boolean;
|
|
276
|
-
/** Highlight first column with special formatting (default: false) */
|
|
277
|
-
showFirstColumn?: boolean;
|
|
278
|
-
/** Highlight last column with special formatting (default: false) */
|
|
279
|
-
showLastColumn?: boolean;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Aggregation functions available for table total row
|
|
284
|
-
*/
|
|
285
|
-
export type TableTotalFunction = 'sum' | 'count' | 'average' | 'min' | 'max' | 'stdDev' | 'var' | 'countNums' | 'none';
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Configuration for converting a sheet to JSON objects.
|
|
289
|
-
*/
|
|
290
|
-
export interface SheetToJsonConfig {
|
|
291
|
-
/**
|
|
292
|
-
* Field names to use for each column.
|
|
293
|
-
* If provided, the first row of data starts at row 1 (or startRow).
|
|
294
|
-
* If not provided, the first row is used as field names.
|
|
295
|
-
*/
|
|
296
|
-
fields?: string[];
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Starting row (0-based). Defaults to 0.
|
|
300
|
-
* If fields are not provided, this row contains the headers.
|
|
301
|
-
* If fields are provided, this is the first data row.
|
|
302
|
-
*/
|
|
303
|
-
startRow?: number;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Starting column (0-based). Defaults to 0.
|
|
307
|
-
*/
|
|
308
|
-
startCol?: number;
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Ending row (0-based, inclusive). Defaults to the last row with data.
|
|
312
|
-
*/
|
|
313
|
-
endRow?: number;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Ending column (0-based, inclusive). Defaults to the last column with data.
|
|
317
|
-
*/
|
|
318
|
-
endCol?: number;
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* If true, stop reading when an empty row is encountered. Defaults to true.
|
|
322
|
-
*/
|
|
323
|
-
stopOnEmptyRow?: boolean;
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* How to serialize Date values. Defaults to 'jsDate'.
|
|
327
|
-
*/
|
|
328
|
-
dateHandling?: DateHandling;
|
|
329
|
-
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Aggregation functions available for table total row
|
|
245
|
+
*/
|
|
246
|
+
export type TableTotalFunction = 'sum' | 'count' | 'average' | 'min' | 'max' | 'stdDev' | 'var' | 'countNums' | 'none';
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Configuration for converting a sheet to JSON objects.
|
|
250
|
+
*/
|
|
251
|
+
export interface SheetToJsonConfig {
|
|
252
|
+
/**
|
|
253
|
+
* Field names to use for each column.
|
|
254
|
+
* If provided, the first row of data starts at row 1 (or startRow).
|
|
255
|
+
* If not provided, the first row is used as field names.
|
|
256
|
+
*/
|
|
257
|
+
fields?: string[];
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Starting row (0-based). Defaults to 0.
|
|
261
|
+
* If fields are not provided, this row contains the headers.
|
|
262
|
+
* If fields are provided, this is the first data row.
|
|
263
|
+
*/
|
|
264
|
+
startRow?: number;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Starting column (0-based). Defaults to 0.
|
|
268
|
+
*/
|
|
269
|
+
startCol?: number;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Ending row (0-based, inclusive). Defaults to the last row with data.
|
|
273
|
+
*/
|
|
274
|
+
endRow?: number;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Ending column (0-based, inclusive). Defaults to the last column with data.
|
|
278
|
+
*/
|
|
279
|
+
endCol?: number;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* If true, stop reading when an empty row is encountered. Defaults to true.
|
|
283
|
+
*/
|
|
284
|
+
stopOnEmptyRow?: boolean;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* How to serialize Date values. Defaults to 'jsDate'.
|
|
288
|
+
*/
|
|
289
|
+
dateHandling?: DateHandling;
|
|
290
|
+
|
|
330
291
|
/**
|
|
331
292
|
* If true, return formatted text (as displayed in Excel) instead of raw values.
|
|
332
293
|
* All values will be returned as strings. Defaults to false.
|
|
@@ -339,3 +300,14 @@ export interface SheetToJsonConfig {
|
|
|
339
300
|
*/
|
|
340
301
|
locale?: string;
|
|
341
302
|
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Options for reading a workbook from file/buffer.
|
|
306
|
+
*/
|
|
307
|
+
export interface WorkbookReadOptions {
|
|
308
|
+
/**
|
|
309
|
+
* Enable lazy parsing of ZIP entries and XML parts.
|
|
310
|
+
* Defaults to true.
|
|
311
|
+
*/
|
|
312
|
+
lazy?: boolean;
|
|
313
|
+
}
|
package/src/utils/address.ts
CHANGED
|
@@ -94,6 +94,54 @@ export const toRange = (range: RangeAddress): string => {
|
|
|
94
94
|
return `${start}:${end}`;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Parses a qualified sheet + address reference.
|
|
99
|
+
* Supports Sheet!A1 and 'Sheet Name'!A1.
|
|
100
|
+
*/
|
|
101
|
+
export const parseSheetAddress = (reference: string): { sheet: string; address: CellAddress } => {
|
|
102
|
+
const exclamationIndex = reference.lastIndexOf('!');
|
|
103
|
+
if (exclamationIndex <= 0 || exclamationIndex >= reference.length - 1) {
|
|
104
|
+
throw new Error(`Invalid sheet address reference: ${reference}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const rawSheet = reference.slice(0, exclamationIndex);
|
|
108
|
+
const addressPart = reference.slice(exclamationIndex + 1);
|
|
109
|
+
const sheet = unquoteSheetName(rawSheet);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
sheet,
|
|
113
|
+
address: parseAddress(addressPart),
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Parses a qualified sheet + range reference.
|
|
119
|
+
* Supports Sheet!A1:B10 and 'Sheet Name'!A1:B10.
|
|
120
|
+
*/
|
|
121
|
+
export const parseSheetRange = (reference: string): { sheet: string; range: RangeAddress } => {
|
|
122
|
+
const exclamationIndex = reference.lastIndexOf('!');
|
|
123
|
+
if (exclamationIndex <= 0 || exclamationIndex >= reference.length - 1) {
|
|
124
|
+
throw new Error(`Invalid sheet range reference: ${reference}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const rawSheet = reference.slice(0, exclamationIndex);
|
|
128
|
+
const rangePart = reference.slice(exclamationIndex + 1);
|
|
129
|
+
const sheet = unquoteSheetName(rawSheet);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
sheet,
|
|
133
|
+
range: parseRange(rangePart),
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const unquoteSheetName = (sheet: string): string => {
|
|
138
|
+
const trimmed = sheet.trim();
|
|
139
|
+
if (trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length >= 2) {
|
|
140
|
+
return trimmed.slice(1, -1).replace(/''/g, "'");
|
|
141
|
+
}
|
|
142
|
+
return trimmed;
|
|
143
|
+
};
|
|
144
|
+
|
|
97
145
|
/**
|
|
98
146
|
* Normalizes a range so start is always top-left and end is bottom-right
|
|
99
147
|
*/
|