@niicojs/excel 0.3.0 → 0.3.1
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 +585 -585
- package/dist/index.cjs +498 -489
- package/dist/index.d.cts +5 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +498 -489
- package/package.json +1 -1
- package/src/index.ts +45 -45
- package/src/pivot-cache.ts +300 -300
- package/src/pivot-table.ts +684 -684
- package/src/range.ts +154 -154
- package/src/shared-strings.ts +178 -178
- package/src/styles.ts +819 -819
- package/src/table.ts +386 -386
- package/src/types.ts +313 -307
- package/src/utils/address.ts +121 -121
- package/src/utils/xml.ts +140 -140
- package/src/workbook.ts +1390 -1390
- package/src/worksheet.ts +879 -869
package/src/types.ts
CHANGED
|
@@ -1,310 +1,310 @@
|
|
|
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
|
-
* Pivot table aggregation functions
|
|
128
|
-
*/
|
|
129
|
-
export type AggregationType = 'sum' | 'count' | 'average' | 'min' | 'max';
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Sort order for pivot fields.
|
|
133
|
-
*/
|
|
134
|
-
export type PivotSortOrder = 'asc' | 'desc';
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Filter configuration for pivot fields.
|
|
138
|
-
*/
|
|
139
|
-
export interface PivotFieldFilter {
|
|
140
|
-
include?: string[];
|
|
141
|
-
exclude?: string[];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Configuration for a value field in a pivot table
|
|
146
|
-
*/
|
|
147
|
-
export interface PivotValueConfig {
|
|
148
|
-
/** Source field name (column header) */
|
|
149
|
-
field: string;
|
|
150
|
-
/** Aggregation function (default: 'sum') */
|
|
151
|
-
aggregation?: AggregationType;
|
|
152
|
-
/** Display name (e.g., "Sum of Sales") */
|
|
153
|
-
name?: string;
|
|
154
|
-
/** Number format (e.g., '$#,##0.00', '0.00%') */
|
|
155
|
-
numberFormat?: string;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Configuration for creating a pivot table
|
|
160
|
-
*/
|
|
161
|
-
export interface PivotTableConfig {
|
|
162
|
-
/** Name of the pivot table */
|
|
163
|
-
name: string;
|
|
164
|
-
/** Source data range with sheet name (e.g., "Sheet1!A1:D100") */
|
|
165
|
-
source: string;
|
|
166
|
-
/** Target cell where pivot table will be placed (e.g., "Sheet2!A3") */
|
|
167
|
-
target: string;
|
|
168
|
-
/** Refresh the pivot table data when the file is opened (default: true) */
|
|
169
|
-
refreshOnLoad?: boolean;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Internal representation of a pivot cache field
|
|
174
|
-
*/
|
|
175
|
-
export interface PivotCacheField {
|
|
176
|
-
/** Field name (from header row) */
|
|
177
|
-
name: string;
|
|
178
|
-
/** Field index (0-based) */
|
|
179
|
-
index: number;
|
|
180
|
-
/** Whether this field contains numbers */
|
|
181
|
-
isNumeric: boolean;
|
|
182
|
-
/** Whether this field contains dates */
|
|
183
|
-
isDate: boolean;
|
|
184
|
-
/** Unique string values (for shared items) */
|
|
185
|
-
sharedItems: string[];
|
|
186
|
-
/** Min numeric value */
|
|
187
|
-
minValue?: number;
|
|
188
|
-
/** Max numeric value */
|
|
189
|
-
maxValue?: number;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Pivot field axis assignment
|
|
194
|
-
*/
|
|
195
|
-
export type PivotFieldAxis = 'row' | 'column' | 'filter' | 'value';
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Configuration for creating a sheet from an array of objects
|
|
199
|
-
*/
|
|
200
|
-
export interface SheetFromDataConfig<T extends object = Record<string, unknown>> {
|
|
201
|
-
/** Name of the sheet to create */
|
|
202
|
-
name: string;
|
|
203
|
-
/** Array of objects with the same structure */
|
|
204
|
-
data: T[];
|
|
205
|
-
/** Column definitions (optional - defaults to all keys from first object) */
|
|
206
|
-
columns?: ColumnConfig<T>[];
|
|
207
|
-
/** Apply header styling (bold text) (default: true) */
|
|
208
|
-
headerStyle?: boolean;
|
|
209
|
-
/** Starting cell address (default: 'A1') */
|
|
210
|
-
startCell?: string;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Column configuration for sheet data
|
|
215
|
-
*/
|
|
216
|
-
export interface ColumnConfig<T = Record<string, unknown>> {
|
|
217
|
-
/** Key from the object to use for this column */
|
|
218
|
-
key: keyof T;
|
|
219
|
-
/** Header text (optional - defaults to key name) */
|
|
220
|
-
header?: string;
|
|
221
|
-
/** Cell style for data cells in this column */
|
|
222
|
-
style?: CellStyle;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Rich cell value with optional formula and style.
|
|
227
|
-
* Use this when you need to set value, formula, or style for individual cells.
|
|
228
|
-
*/
|
|
229
|
-
export interface RichCellValue {
|
|
230
|
-
/** Cell value */
|
|
231
|
-
value?: CellValue;
|
|
232
|
-
/** Formula (without leading '=') */
|
|
233
|
-
formula?: string;
|
|
234
|
-
/** Cell style */
|
|
235
|
-
style?: CellStyle;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Configuration for creating an Excel Table (ListObject)
|
|
240
|
-
*/
|
|
241
|
-
export interface TableConfig {
|
|
242
|
-
/** Table name (must be unique within the workbook) */
|
|
243
|
-
name: string;
|
|
244
|
-
/** Data range including headers (e.g., "A1:D10") */
|
|
245
|
-
range: string;
|
|
246
|
-
/** First row contains headers (default: true) */
|
|
247
|
-
headerRow?: boolean;
|
|
248
|
-
/** Show total row at the bottom (default: false) */
|
|
249
|
-
totalRow?: boolean;
|
|
250
|
-
/** Table style configuration */
|
|
251
|
-
style?: TableStyleConfig;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Table style configuration options
|
|
256
|
-
*/
|
|
257
|
-
export interface TableStyleConfig {
|
|
258
|
-
/** Built-in table style name (e.g., "TableStyleMedium2", "TableStyleLight1") */
|
|
259
|
-
name?: string;
|
|
260
|
-
/** Show banded/alternating row colors (default: true) */
|
|
261
|
-
showRowStripes?: boolean;
|
|
262
|
-
/** Show banded/alternating column colors (default: false) */
|
|
263
|
-
showColumnStripes?: boolean;
|
|
264
|
-
/** Highlight first column with special formatting (default: false) */
|
|
265
|
-
showFirstColumn?: boolean;
|
|
266
|
-
/** Highlight last column with special formatting (default: false) */
|
|
267
|
-
showLastColumn?: boolean;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Aggregation functions available for table total row
|
|
272
|
-
*/
|
|
273
|
-
export type TableTotalFunction = 'sum' | 'count' | 'average' | 'min' | 'max' | 'stdDev' | 'var' | 'countNums' | 'none';
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Configuration for converting a sheet to JSON objects.
|
|
277
|
-
*/
|
|
278
|
-
export interface SheetToJsonConfig {
|
|
279
|
-
/**
|
|
280
|
-
* Field names to use for each column.
|
|
281
|
-
* If provided, the first row of data starts at row 1 (or startRow).
|
|
282
|
-
* If not provided, the first row is used as field names.
|
|
283
|
-
*/
|
|
284
|
-
fields?: string[];
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Starting row (0-based). Defaults to 0.
|
|
288
|
-
* If fields are not provided, this row contains the headers.
|
|
289
|
-
* If fields are provided, this is the first data row.
|
|
290
|
-
*/
|
|
291
|
-
startRow?: number;
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Starting column (0-based). Defaults to 0.
|
|
295
|
-
*/
|
|
296
|
-
startCol?: number;
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Ending row (0-based, inclusive). Defaults to the last row with data.
|
|
300
|
-
*/
|
|
301
|
-
endRow?: number;
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Ending column (0-based, inclusive). Defaults to the last column with data.
|
|
305
|
-
*/
|
|
306
|
-
endCol?: number;
|
|
307
|
-
|
|
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
|
+
* Pivot table aggregation functions
|
|
128
|
+
*/
|
|
129
|
+
export type AggregationType = 'sum' | 'count' | 'average' | 'min' | 'max';
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Sort order for pivot fields.
|
|
133
|
+
*/
|
|
134
|
+
export type PivotSortOrder = 'asc' | 'desc';
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Filter configuration for pivot fields.
|
|
138
|
+
*/
|
|
139
|
+
export interface PivotFieldFilter {
|
|
140
|
+
include?: string[];
|
|
141
|
+
exclude?: string[];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Configuration for a value field in a pivot table
|
|
146
|
+
*/
|
|
147
|
+
export interface PivotValueConfig {
|
|
148
|
+
/** Source field name (column header) */
|
|
149
|
+
field: string;
|
|
150
|
+
/** Aggregation function (default: 'sum') */
|
|
151
|
+
aggregation?: AggregationType;
|
|
152
|
+
/** Display name (e.g., "Sum of Sales") */
|
|
153
|
+
name?: string;
|
|
154
|
+
/** Number format (e.g., '$#,##0.00', '0.00%') */
|
|
155
|
+
numberFormat?: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Configuration for creating a pivot table
|
|
160
|
+
*/
|
|
161
|
+
export interface PivotTableConfig {
|
|
162
|
+
/** Name of the pivot table */
|
|
163
|
+
name: string;
|
|
164
|
+
/** Source data range with sheet name (e.g., "Sheet1!A1:D100") */
|
|
165
|
+
source: string;
|
|
166
|
+
/** Target cell where pivot table will be placed (e.g., "Sheet2!A3") */
|
|
167
|
+
target: string;
|
|
168
|
+
/** Refresh the pivot table data when the file is opened (default: true) */
|
|
169
|
+
refreshOnLoad?: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Internal representation of a pivot cache field
|
|
174
|
+
*/
|
|
175
|
+
export interface PivotCacheField {
|
|
176
|
+
/** Field name (from header row) */
|
|
177
|
+
name: string;
|
|
178
|
+
/** Field index (0-based) */
|
|
179
|
+
index: number;
|
|
180
|
+
/** Whether this field contains numbers */
|
|
181
|
+
isNumeric: boolean;
|
|
182
|
+
/** Whether this field contains dates */
|
|
183
|
+
isDate: boolean;
|
|
184
|
+
/** Unique string values (for shared items) */
|
|
185
|
+
sharedItems: string[];
|
|
186
|
+
/** Min numeric value */
|
|
187
|
+
minValue?: number;
|
|
188
|
+
/** Max numeric value */
|
|
189
|
+
maxValue?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Pivot field axis assignment
|
|
194
|
+
*/
|
|
195
|
+
export type PivotFieldAxis = 'row' | 'column' | 'filter' | 'value';
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Configuration for creating a sheet from an array of objects
|
|
199
|
+
*/
|
|
200
|
+
export interface SheetFromDataConfig<T extends object = Record<string, unknown>> {
|
|
201
|
+
/** Name of the sheet to create */
|
|
202
|
+
name: string;
|
|
203
|
+
/** Array of objects with the same structure */
|
|
204
|
+
data: T[];
|
|
205
|
+
/** Column definitions (optional - defaults to all keys from first object) */
|
|
206
|
+
columns?: ColumnConfig<T>[];
|
|
207
|
+
/** Apply header styling (bold text) (default: true) */
|
|
208
|
+
headerStyle?: boolean;
|
|
209
|
+
/** Starting cell address (default: 'A1') */
|
|
210
|
+
startCell?: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Column configuration for sheet data
|
|
215
|
+
*/
|
|
216
|
+
export interface ColumnConfig<T = Record<string, unknown>> {
|
|
217
|
+
/** Key from the object to use for this column */
|
|
218
|
+
key: keyof T;
|
|
219
|
+
/** Header text (optional - defaults to key name) */
|
|
220
|
+
header?: string;
|
|
221
|
+
/** Cell style for data cells in this column */
|
|
222
|
+
style?: CellStyle;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Rich cell value with optional formula and style.
|
|
227
|
+
* Use this when you need to set value, formula, or style for individual cells.
|
|
228
|
+
*/
|
|
229
|
+
export interface RichCellValue {
|
|
230
|
+
/** Cell value */
|
|
231
|
+
value?: CellValue;
|
|
232
|
+
/** Formula (without leading '=') */
|
|
233
|
+
formula?: string;
|
|
234
|
+
/** Cell style */
|
|
235
|
+
style?: CellStyle;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Configuration for creating an Excel Table (ListObject)
|
|
240
|
+
*/
|
|
241
|
+
export interface TableConfig {
|
|
242
|
+
/** Table name (must be unique within the workbook) */
|
|
243
|
+
name: string;
|
|
244
|
+
/** Data range including headers (e.g., "A1:D10") */
|
|
245
|
+
range: string;
|
|
246
|
+
/** First row contains headers (default: true) */
|
|
247
|
+
headerRow?: boolean;
|
|
248
|
+
/** Show total row at the bottom (default: false) */
|
|
249
|
+
totalRow?: boolean;
|
|
250
|
+
/** Table style configuration */
|
|
251
|
+
style?: TableStyleConfig;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Table style configuration options
|
|
256
|
+
*/
|
|
257
|
+
export interface TableStyleConfig {
|
|
258
|
+
/** Built-in table style name (e.g., "TableStyleMedium2", "TableStyleLight1") */
|
|
259
|
+
name?: string;
|
|
260
|
+
/** Show banded/alternating row colors (default: true) */
|
|
261
|
+
showRowStripes?: boolean;
|
|
262
|
+
/** Show banded/alternating column colors (default: false) */
|
|
263
|
+
showColumnStripes?: boolean;
|
|
264
|
+
/** Highlight first column with special formatting (default: false) */
|
|
265
|
+
showFirstColumn?: boolean;
|
|
266
|
+
/** Highlight last column with special formatting (default: false) */
|
|
267
|
+
showLastColumn?: boolean;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Aggregation functions available for table total row
|
|
272
|
+
*/
|
|
273
|
+
export type TableTotalFunction = 'sum' | 'count' | 'average' | 'min' | 'max' | 'stdDev' | 'var' | 'countNums' | 'none';
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Configuration for converting a sheet to JSON objects.
|
|
277
|
+
*/
|
|
278
|
+
export interface SheetToJsonConfig {
|
|
279
|
+
/**
|
|
280
|
+
* Field names to use for each column.
|
|
281
|
+
* If provided, the first row of data starts at row 1 (or startRow).
|
|
282
|
+
* If not provided, the first row is used as field names.
|
|
283
|
+
*/
|
|
284
|
+
fields?: string[];
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Starting row (0-based). Defaults to 0.
|
|
288
|
+
* If fields are not provided, this row contains the headers.
|
|
289
|
+
* If fields are provided, this is the first data row.
|
|
290
|
+
*/
|
|
291
|
+
startRow?: number;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Starting column (0-based). Defaults to 0.
|
|
295
|
+
*/
|
|
296
|
+
startCol?: number;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Ending row (0-based, inclusive). Defaults to the last row with data.
|
|
300
|
+
*/
|
|
301
|
+
endRow?: number;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Ending column (0-based, inclusive). Defaults to the last column with data.
|
|
305
|
+
*/
|
|
306
|
+
endCol?: number;
|
|
307
|
+
|
|
308
308
|
/**
|
|
309
309
|
* If true, stop reading when an empty row is encountered. Defaults to true.
|
|
310
310
|
*/
|
|
@@ -314,4 +314,10 @@ export interface SheetToJsonConfig {
|
|
|
314
314
|
* How to serialize Date values. Defaults to 'jsDate'.
|
|
315
315
|
*/
|
|
316
316
|
dateHandling?: DateHandling;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* If true, return formatted text (as displayed in Excel) instead of raw values.
|
|
320
|
+
* All values will be returned as strings. Defaults to false.
|
|
321
|
+
*/
|
|
322
|
+
asText?: boolean;
|
|
317
323
|
}
|