sheetra 1.0.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 +201 -0
- package/README.md +32 -0
- package/dist/index.esm.js +2392 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2419 -0
- package/dist/index.js.map +1 -0
- package/dist/types/builders/export-builder.d.ts +20 -0
- package/dist/types/builders/section-builder.d.ts +142 -0
- package/dist/types/builders/sheet-builder.d.ts +297 -0
- package/dist/types/core/cell.d.ts +16 -0
- package/dist/types/core/column.d.ts +13 -0
- package/dist/types/core/row.d.ts +20 -0
- package/dist/types/core/styles.d.ts +23 -0
- package/dist/types/core/workbook.d.ts +19 -0
- package/dist/types/core/worksheet.d.ts +32 -0
- package/dist/types/formatters/date-formatter.d.ts +7 -0
- package/dist/types/formatters/index.d.ts +3 -0
- package/dist/types/formatters/number-formatter.d.ts +6 -0
- package/dist/types/formatters/string-formatter.d.ts +310 -0
- package/dist/types/index.d.ts +1730 -0
- package/dist/types/types/cell.types.d.ts +288 -0
- package/dist/types/types/export.types.d.ts +303 -0
- package/dist/types/types/index.d.ts +13 -0
- package/dist/types/types/workbook.types.d.ts +500 -0
- package/dist/types/utils/constants.d.ts +10 -0
- package/dist/types/utils/helpers.d.ts +36 -0
- package/dist/types/utils/validators.d.ts +3 -0
- package/dist/types/writers/csv-writer.d.ts +6 -0
- package/dist/types/writers/excel-writer.d.ts +16 -0
- package/dist/types/writers/index.d.ts +4 -0
- package/dist/types/writers/json-writer.d.ts +6 -0
- package/package.json +88 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Worksheet } from '../core/worksheet';
|
|
2
|
+
import { CellStyle, CellData, PrintOptions, HeaderFooter, TableConfig, DataValidation, ConditionalFormatRule, ChartConfig, Drawing } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* SheetBuilder provides a fluent API for building Excel worksheets
|
|
5
|
+
*/
|
|
6
|
+
export declare class SheetBuilder {
|
|
7
|
+
private worksheet;
|
|
8
|
+
private currentRow;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new SheetBuilder instance
|
|
11
|
+
* @param name Worksheet name
|
|
12
|
+
*/
|
|
13
|
+
constructor(name?: string);
|
|
14
|
+
/**
|
|
15
|
+
* Get the underlying worksheet
|
|
16
|
+
*/
|
|
17
|
+
getWorksheet(): Worksheet;
|
|
18
|
+
/**
|
|
19
|
+
* Set the worksheet name
|
|
20
|
+
*/
|
|
21
|
+
setName(name: string): this;
|
|
22
|
+
/**
|
|
23
|
+
* Add a header row with styling
|
|
24
|
+
* @param headers Array of header text
|
|
25
|
+
* @param style Optional style for all headers
|
|
26
|
+
*/
|
|
27
|
+
addHeaderRow(headers: string[], style?: CellStyle): this;
|
|
28
|
+
/**
|
|
29
|
+
* Add a title row
|
|
30
|
+
* @param title Title text
|
|
31
|
+
* @param colSpan Number of columns to span
|
|
32
|
+
*/
|
|
33
|
+
addTitle(title: string, colSpan?: number): this;
|
|
34
|
+
/**
|
|
35
|
+
* Add a subtitle row
|
|
36
|
+
* @param subtitle Subtitle text
|
|
37
|
+
* @param colSpan Number of columns to span
|
|
38
|
+
*/
|
|
39
|
+
addSubtitle(subtitle: string, colSpan?: number): this;
|
|
40
|
+
/**
|
|
41
|
+
* Add a row of data
|
|
42
|
+
* @param data Array of cell values
|
|
43
|
+
* @param styles Optional array of styles per cell
|
|
44
|
+
*/
|
|
45
|
+
addRow(data: any[], styles?: (CellStyle | undefined)[]): this;
|
|
46
|
+
/**
|
|
47
|
+
* Add multiple rows of data
|
|
48
|
+
* @param rows Array of row data
|
|
49
|
+
* @param styles Optional array of styles per row or per cell
|
|
50
|
+
*/
|
|
51
|
+
addRows(rows: any[][], styles?: (CellStyle | CellStyle[] | undefined)[]): this;
|
|
52
|
+
/**
|
|
53
|
+
* Add data from objects
|
|
54
|
+
* @param data Array of objects
|
|
55
|
+
* @param fields Fields to extract (keys or dot notation paths)
|
|
56
|
+
* @param headers Optional header labels
|
|
57
|
+
*/
|
|
58
|
+
addObjects<T extends Record<string, any>>(data: T[], fields: (keyof T | string)[], headers?: string[]): this;
|
|
59
|
+
/**
|
|
60
|
+
* Add a section with header and data
|
|
61
|
+
* @param title Section title
|
|
62
|
+
* @param data Section data
|
|
63
|
+
* @param fields Fields to display
|
|
64
|
+
* @param level Outline level
|
|
65
|
+
*/
|
|
66
|
+
addSection(title: string, data: any[], fields: string[], level?: number): this;
|
|
67
|
+
/**
|
|
68
|
+
* Add grouped data with sub-sections
|
|
69
|
+
* @param data Data to group
|
|
70
|
+
* @param groupBy Field to group by
|
|
71
|
+
* @param fields Fields to display
|
|
72
|
+
* @param level Outline level
|
|
73
|
+
*/
|
|
74
|
+
addGroupedData(data: any[], groupBy: string, fields: string[], level?: number): this;
|
|
75
|
+
/**
|
|
76
|
+
* Add summary row for a group
|
|
77
|
+
*/
|
|
78
|
+
private addGroupSummary;
|
|
79
|
+
/**
|
|
80
|
+
* Add a summary row with totals
|
|
81
|
+
* @param fields Fields to summarize
|
|
82
|
+
* @param functions Summary functions (sum, average, count, min, max)
|
|
83
|
+
* @param label Summary label
|
|
84
|
+
*/
|
|
85
|
+
addSummaryRow(fields: string[], functions: Array<'sum' | 'average' | 'count' | 'min' | 'max'>, label?: string): this;
|
|
86
|
+
/**
|
|
87
|
+
* Set column widths
|
|
88
|
+
* @param widths Array of column widths
|
|
89
|
+
*/
|
|
90
|
+
setColumnWidths(widths: number[]): this;
|
|
91
|
+
/**
|
|
92
|
+
* Auto-size columns based on content
|
|
93
|
+
* @param maxWidth Maximum width in characters
|
|
94
|
+
*/
|
|
95
|
+
autoSizeColumns(maxWidth?: number): this;
|
|
96
|
+
/**
|
|
97
|
+
* Set column to auto-fit
|
|
98
|
+
* @param colIndex Column index
|
|
99
|
+
*/
|
|
100
|
+
setColumnAutoFit(colIndex: number): this;
|
|
101
|
+
/**
|
|
102
|
+
* Hide a column
|
|
103
|
+
* @param colIndex Column index
|
|
104
|
+
*/
|
|
105
|
+
hideColumn(colIndex: number): this;
|
|
106
|
+
/**
|
|
107
|
+
* Hide a row
|
|
108
|
+
* @param rowIndex Row index
|
|
109
|
+
*/
|
|
110
|
+
hideRow(rowIndex: number): this;
|
|
111
|
+
/**
|
|
112
|
+
* Set outline level for a row
|
|
113
|
+
* @param rowIndex Row index
|
|
114
|
+
* @param level Outline level (0-7)
|
|
115
|
+
* @param collapsed Whether the outline is collapsed
|
|
116
|
+
*/
|
|
117
|
+
setRowOutlineLevel(rowIndex: number, level: number, collapsed?: boolean): this;
|
|
118
|
+
/**
|
|
119
|
+
* Set outline level for a column
|
|
120
|
+
* @param colIndex Column index
|
|
121
|
+
* @param level Outline level (0-7)
|
|
122
|
+
* @param collapsed Whether the outline is collapsed
|
|
123
|
+
*/
|
|
124
|
+
setColumnOutlineLevel(colIndex: number, level: number, collapsed?: boolean): this;
|
|
125
|
+
/**
|
|
126
|
+
* Create an outline group for rows
|
|
127
|
+
* @param startRow Start row index
|
|
128
|
+
* @param endRow End row index
|
|
129
|
+
* @param level Outline level
|
|
130
|
+
* @param collapsed Whether the group is collapsed
|
|
131
|
+
*/
|
|
132
|
+
groupRows(startRow: number, endRow: number, level?: number, collapsed?: boolean): this;
|
|
133
|
+
/**
|
|
134
|
+
* Create an outline group for columns
|
|
135
|
+
* @param startCol Start column index
|
|
136
|
+
* @param endCol End column index
|
|
137
|
+
* @param level Outline level
|
|
138
|
+
* @param collapsed Whether the group is collapsed
|
|
139
|
+
*/
|
|
140
|
+
groupColumns(startCol: number, endCol: number, level?: number, collapsed?: boolean): this;
|
|
141
|
+
/**
|
|
142
|
+
* Merge cells
|
|
143
|
+
* @param startRow Start row
|
|
144
|
+
* @param startCol Start column
|
|
145
|
+
* @param endRow End row
|
|
146
|
+
* @param endCol End column
|
|
147
|
+
*/
|
|
148
|
+
mergeCells(startRow: number, startCol: number, endRow: number, endCol: number): this;
|
|
149
|
+
/**
|
|
150
|
+
* Freeze panes
|
|
151
|
+
* @param rows Number of rows to freeze
|
|
152
|
+
* @param columns Number of columns to freeze
|
|
153
|
+
*/
|
|
154
|
+
freezePanes(rows?: number, columns?: number): this;
|
|
155
|
+
/**
|
|
156
|
+
* Set print options
|
|
157
|
+
* @param options Print options
|
|
158
|
+
*/
|
|
159
|
+
setPrintOptions(options: PrintOptions): this;
|
|
160
|
+
/**
|
|
161
|
+
* Set header and footer
|
|
162
|
+
* @param headerFooter Header/footer configuration
|
|
163
|
+
*/
|
|
164
|
+
setHeaderFooter(headerFooter: HeaderFooter): this;
|
|
165
|
+
/**
|
|
166
|
+
* Add auto-filter
|
|
167
|
+
* @param startRow Start row
|
|
168
|
+
* @param startCol Start column
|
|
169
|
+
* @param endRow End row
|
|
170
|
+
* @param endCol End column
|
|
171
|
+
*/
|
|
172
|
+
addAutoFilter(startRow: number, startCol: number, endRow: number, endCol: number): this;
|
|
173
|
+
/**
|
|
174
|
+
* Add a table
|
|
175
|
+
* @param config Table configuration
|
|
176
|
+
*/
|
|
177
|
+
addTable(config: TableConfig): this;
|
|
178
|
+
/**
|
|
179
|
+
* Add data validation to a cell or range
|
|
180
|
+
* @param range Cell range (e.g., 'A1:B10')
|
|
181
|
+
* @param validation Data validation rules
|
|
182
|
+
*/
|
|
183
|
+
addDataValidation(range: string, validation: DataValidation): this;
|
|
184
|
+
/**
|
|
185
|
+
* Add conditional formatting
|
|
186
|
+
* @param range Cell range
|
|
187
|
+
* @param rules Conditional formatting rules
|
|
188
|
+
*/
|
|
189
|
+
addConditionalFormatting(range: string, rules: ConditionalFormatRule[]): this;
|
|
190
|
+
/**
|
|
191
|
+
* Add a chart
|
|
192
|
+
* @param config Chart configuration
|
|
193
|
+
*/
|
|
194
|
+
addChart(config: ChartConfig): this;
|
|
195
|
+
/**
|
|
196
|
+
* Add an image or drawing
|
|
197
|
+
* @param drawing Drawing configuration
|
|
198
|
+
*/
|
|
199
|
+
addDrawing(drawing: Drawing): this;
|
|
200
|
+
/**
|
|
201
|
+
* Set cell value with style
|
|
202
|
+
* @param row Row index
|
|
203
|
+
* @param col Column index
|
|
204
|
+
* @param value Cell value
|
|
205
|
+
* @param style Cell style
|
|
206
|
+
*/
|
|
207
|
+
setCell(row: number, col: number, value: any, style?: CellStyle): this;
|
|
208
|
+
/**
|
|
209
|
+
* Get cell value
|
|
210
|
+
* @param row Row index
|
|
211
|
+
* @param col Column index
|
|
212
|
+
*/
|
|
213
|
+
getCell(row: number, col: number): CellData | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Add a comment to a cell
|
|
216
|
+
* @param row Row index
|
|
217
|
+
* @param col Column index
|
|
218
|
+
* @param comment Comment text
|
|
219
|
+
* @param author Comment author
|
|
220
|
+
*/
|
|
221
|
+
addComment(row: number, col: number, comment: string, author?: string): this;
|
|
222
|
+
/**
|
|
223
|
+
* Add a hyperlink to a cell
|
|
224
|
+
* @param row Row index
|
|
225
|
+
* @param col Column index
|
|
226
|
+
* @param url Hyperlink URL
|
|
227
|
+
* @param displayText Display text (optional)
|
|
228
|
+
*/
|
|
229
|
+
addHyperlink(row: number, col: number, url: string, displayText?: string): this;
|
|
230
|
+
/**
|
|
231
|
+
* Apply a style to a range
|
|
232
|
+
* @param startRow Start row
|
|
233
|
+
* @param startCol Start column
|
|
234
|
+
* @param endRow End row
|
|
235
|
+
* @param endCol End column
|
|
236
|
+
* @param style Style to apply
|
|
237
|
+
*/
|
|
238
|
+
applyStyleToRange(startRow: number, startCol: number, endRow: number, endCol: number, style: CellStyle): this;
|
|
239
|
+
/**
|
|
240
|
+
* Insert a blank row
|
|
241
|
+
* @param count Number of blank rows to insert
|
|
242
|
+
*/
|
|
243
|
+
insertBlankRows(count?: number): this;
|
|
244
|
+
/**
|
|
245
|
+
* Create a new row
|
|
246
|
+
*/
|
|
247
|
+
private createRow;
|
|
248
|
+
/**
|
|
249
|
+
* Get or create a column
|
|
250
|
+
*/
|
|
251
|
+
private getOrCreateColumn;
|
|
252
|
+
/**
|
|
253
|
+
* Get nested value from object using dot notation
|
|
254
|
+
*/
|
|
255
|
+
private getNestedValue;
|
|
256
|
+
/**
|
|
257
|
+
* Format field name for display
|
|
258
|
+
*/
|
|
259
|
+
private formatFieldName;
|
|
260
|
+
/**
|
|
261
|
+
* Group data by field
|
|
262
|
+
*/
|
|
263
|
+
private groupData;
|
|
264
|
+
/**
|
|
265
|
+
* Convert column index to letter (A, B, C, ...)
|
|
266
|
+
*/
|
|
267
|
+
private columnToLetter;
|
|
268
|
+
/**
|
|
269
|
+
* Get column range for formula (e.g., A:A)
|
|
270
|
+
*/
|
|
271
|
+
private getColumnRange;
|
|
272
|
+
/**
|
|
273
|
+
* Build and return the worksheet
|
|
274
|
+
*/
|
|
275
|
+
build(): Worksheet;
|
|
276
|
+
/**
|
|
277
|
+
* Reset the builder
|
|
278
|
+
*/
|
|
279
|
+
reset(): this;
|
|
280
|
+
/**
|
|
281
|
+
* Create a new SheetBuilder instance
|
|
282
|
+
*/
|
|
283
|
+
static create(name?: string): SheetBuilder;
|
|
284
|
+
/**
|
|
285
|
+
* Create from existing worksheet
|
|
286
|
+
*/
|
|
287
|
+
static fromWorksheet(worksheet: Worksheet): SheetBuilder;
|
|
288
|
+
}
|
|
289
|
+
declare module '../types/cell.types' {
|
|
290
|
+
interface CellStyle {
|
|
291
|
+
borderTop?: BorderStyleType | BorderEdge;
|
|
292
|
+
borderBottom?: BorderStyleType | BorderEdge;
|
|
293
|
+
borderLeft?: BorderStyleType | BorderEdge;
|
|
294
|
+
borderRight?: BorderStyleType | BorderEdge;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
export declare function extendStyleBuilder(): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CellData, CellStyle } from '../types';
|
|
2
|
+
export declare class Cell {
|
|
3
|
+
private value;
|
|
4
|
+
private style?;
|
|
5
|
+
private formula?;
|
|
6
|
+
private type;
|
|
7
|
+
constructor(value?: any, style?: CellStyle);
|
|
8
|
+
setValue(value: any): this;
|
|
9
|
+
setStyle(style?: CellStyle): this;
|
|
10
|
+
setFormula(formula: string): this;
|
|
11
|
+
setType(type: 'string' | 'number' | 'date' | 'boolean' | 'formula'): this;
|
|
12
|
+
private inferType;
|
|
13
|
+
getFormattedValue(): string;
|
|
14
|
+
toData(): CellData;
|
|
15
|
+
static fromData(data: CellData): Cell;
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ColumnData } from '../types';
|
|
2
|
+
export declare class Column {
|
|
3
|
+
private width?;
|
|
4
|
+
private hidden;
|
|
5
|
+
private outlineLevel;
|
|
6
|
+
private collapsed;
|
|
7
|
+
constructor(width?: number);
|
|
8
|
+
setWidth(width: number): this;
|
|
9
|
+
setHidden(hidden: boolean): this;
|
|
10
|
+
setOutlineLevel(level: number, collapsed?: boolean): this;
|
|
11
|
+
toData(): ColumnData;
|
|
12
|
+
static fromData(data: ColumnData): Column;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RowData, CellData, CellStyle } from '../types';
|
|
2
|
+
import { Cell } from './cell';
|
|
3
|
+
export declare class Row {
|
|
4
|
+
private cells;
|
|
5
|
+
private height?;
|
|
6
|
+
private hidden;
|
|
7
|
+
private outlineLevel;
|
|
8
|
+
private collapsed;
|
|
9
|
+
constructor(cells?: Cell[]);
|
|
10
|
+
addCell(cell: Cell): this;
|
|
11
|
+
createCell(value?: any, style?: CellStyle): Cell;
|
|
12
|
+
setCell(index: number, value: any, style?: CellStyle): this;
|
|
13
|
+
getCell(index: number): CellData | undefined;
|
|
14
|
+
getCells(): Cell[];
|
|
15
|
+
setHeight(height: number): this;
|
|
16
|
+
setHidden(hidden: boolean): this;
|
|
17
|
+
setOutlineLevel(level: number, collapsed?: boolean): this;
|
|
18
|
+
toData(): RowData;
|
|
19
|
+
static fromData(data: RowData): Row;
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CellStyle, Border, BorderStyle } from '../types';
|
|
2
|
+
export declare class StyleBuilder {
|
|
3
|
+
private style;
|
|
4
|
+
bold(bold?: boolean): this;
|
|
5
|
+
italic(italic?: boolean): this;
|
|
6
|
+
underline(underline?: boolean): this;
|
|
7
|
+
fontSize(size: number): this;
|
|
8
|
+
fontFamily(family: string): this;
|
|
9
|
+
color(color: string): this;
|
|
10
|
+
backgroundColor(color: string): this;
|
|
11
|
+
align(alignment: 'left' | 'center' | 'right'): this;
|
|
12
|
+
verticalAlign(alignment: 'top' | 'middle' | 'bottom'): this;
|
|
13
|
+
wrapText(wrap?: boolean): this;
|
|
14
|
+
border(border: Border): this;
|
|
15
|
+
borderTop(style?: BorderStyle['style'], color?: string): this;
|
|
16
|
+
borderRight(style?: BorderStyle['style'], color?: string): this;
|
|
17
|
+
borderBottom(style?: BorderStyle['style'], color?: string): this;
|
|
18
|
+
borderLeft(style?: BorderStyle['style'], color?: string): this;
|
|
19
|
+
borderAll(style?: BorderStyle['style'], color?: string): this;
|
|
20
|
+
numberFormat(format: string): this;
|
|
21
|
+
build(): CellStyle;
|
|
22
|
+
static create(): StyleBuilder;
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WorkbookData, ExportOptions } from '../types';
|
|
2
|
+
import { Worksheet } from './worksheet';
|
|
3
|
+
export declare class Workbook {
|
|
4
|
+
private sheets;
|
|
5
|
+
private properties;
|
|
6
|
+
constructor(data?: WorkbookData);
|
|
7
|
+
addSheet(sheet: Worksheet): this;
|
|
8
|
+
createSheet(name: string): Worksheet;
|
|
9
|
+
getSheet(index: number): Worksheet | undefined;
|
|
10
|
+
getSheetByName(name: string): Worksheet | undefined;
|
|
11
|
+
removeSheet(index: number): boolean;
|
|
12
|
+
setProperty(key: string, value: any): this;
|
|
13
|
+
toData(): WorkbookData;
|
|
14
|
+
fromData(data: WorkbookData): void;
|
|
15
|
+
export(options?: ExportOptions): Promise<Blob>;
|
|
16
|
+
download(options?: ExportOptions): void;
|
|
17
|
+
static create(): Workbook;
|
|
18
|
+
static fromData(data: WorkbookData): Workbook;
|
|
19
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WorksheetData, CellData, PrintOptions } from '../types';
|
|
2
|
+
import { Row } from './row';
|
|
3
|
+
import { Column } from './column';
|
|
4
|
+
export declare class Worksheet {
|
|
5
|
+
private name;
|
|
6
|
+
private rows;
|
|
7
|
+
private columns;
|
|
8
|
+
private mergedCells;
|
|
9
|
+
private freezePane?;
|
|
10
|
+
private printOptions?;
|
|
11
|
+
constructor(name: string);
|
|
12
|
+
getName(): string;
|
|
13
|
+
setName(name: string): this;
|
|
14
|
+
addRow(row: Row): this;
|
|
15
|
+
createRow(index?: number): Row;
|
|
16
|
+
getRow(index: number): Row | undefined;
|
|
17
|
+
getRows(): Row[];
|
|
18
|
+
removeRow(index: number): boolean;
|
|
19
|
+
addColumn(column: Column): this;
|
|
20
|
+
createColumn(width?: number): Column;
|
|
21
|
+
getColumn(index: number): Column | undefined;
|
|
22
|
+
getColumns(): Column[];
|
|
23
|
+
setCell(row: number, col: number, value: any, style?: any): this;
|
|
24
|
+
getCell(row: number, col: number): CellData | undefined;
|
|
25
|
+
mergeCells(startRow: number, startCol: number, endRow: number, endCol: number): this;
|
|
26
|
+
setFreezePane(row?: number, col?: number): this;
|
|
27
|
+
setPrintOptions(options: PrintOptions): this;
|
|
28
|
+
setOutlineLevel(row: number, level: number, collapsed?: boolean): this;
|
|
29
|
+
setColumnOutlineLevel(col: number, level: number, collapsed?: boolean): this;
|
|
30
|
+
toData(): WorksheetData;
|
|
31
|
+
static fromData(data: WorksheetData): Worksheet;
|
|
32
|
+
}
|