@niicojs/excel 0.1.0 → 0.2.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/dist/index.cjs +143 -9
- package/dist/index.d.cts +70 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +70 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +143 -9
- package/package.json +7 -7
- package/src/cell.ts +44 -9
- package/src/index.ts +3 -0
- package/src/types.ts +28 -0
- package/src/workbook.ts +130 -2
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,32 @@ interface PivotCacheField {
|
|
|
130
130
|
* Pivot field axis assignment
|
|
131
131
|
*/
|
|
132
132
|
type PivotFieldAxis = 'row' | 'column' | 'filter' | 'value';
|
|
133
|
+
/**
|
|
134
|
+
* Configuration for creating a sheet from an array of objects
|
|
135
|
+
*/
|
|
136
|
+
interface SheetFromDataConfig<T extends object = Record<string, unknown>> {
|
|
137
|
+
/** Name of the sheet to create */
|
|
138
|
+
name: string;
|
|
139
|
+
/** Array of objects with the same structure */
|
|
140
|
+
data: T[];
|
|
141
|
+
/** Column definitions (optional - defaults to all keys from first object) */
|
|
142
|
+
columns?: ColumnConfig<T>[];
|
|
143
|
+
/** Apply header styling (bold text) (default: true) */
|
|
144
|
+
headerStyle?: boolean;
|
|
145
|
+
/** Starting cell address (default: 'A1') */
|
|
146
|
+
startCell?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Column configuration for sheet data
|
|
150
|
+
*/
|
|
151
|
+
interface ColumnConfig<T = Record<string, unknown>> {
|
|
152
|
+
/** Key from the object to use for this column */
|
|
153
|
+
key: keyof T;
|
|
154
|
+
/** Header text (optional - defaults to key name) */
|
|
155
|
+
header?: string;
|
|
156
|
+
/** Cell style for data cells in this column */
|
|
157
|
+
style?: CellStyle;
|
|
158
|
+
}
|
|
133
159
|
|
|
134
160
|
/**
|
|
135
161
|
* Represents a single cell in a worksheet
|
|
@@ -665,6 +691,49 @@ declare class Workbook {
|
|
|
665
691
|
* Copy a worksheet
|
|
666
692
|
*/
|
|
667
693
|
copySheet(sourceName: string, newName: string): Worksheet;
|
|
694
|
+
/**
|
|
695
|
+
* Create a new worksheet from an array of objects.
|
|
696
|
+
*
|
|
697
|
+
* The first row contains headers (object keys or custom column headers),
|
|
698
|
+
* and subsequent rows contain the object values.
|
|
699
|
+
*
|
|
700
|
+
* @param config - Configuration for the sheet creation
|
|
701
|
+
* @returns The created Worksheet
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* const data = [
|
|
706
|
+
* { name: 'Alice', age: 30, city: 'Paris' },
|
|
707
|
+
* { name: 'Bob', age: 25, city: 'London' },
|
|
708
|
+
* { name: 'Charlie', age: 35, city: 'Berlin' },
|
|
709
|
+
* ];
|
|
710
|
+
*
|
|
711
|
+
* // Simple usage - all object keys become columns
|
|
712
|
+
* const sheet = wb.addSheetFromData({
|
|
713
|
+
* name: 'People',
|
|
714
|
+
* data: data,
|
|
715
|
+
* });
|
|
716
|
+
*
|
|
717
|
+
* // With custom column configuration
|
|
718
|
+
* const sheet2 = wb.addSheetFromData({
|
|
719
|
+
* name: 'People Custom',
|
|
720
|
+
* data: data,
|
|
721
|
+
* columns: [
|
|
722
|
+
* { key: 'name', header: 'Full Name' },
|
|
723
|
+
* { key: 'age', header: 'Age (years)' },
|
|
724
|
+
* ],
|
|
725
|
+
* });
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
addSheetFromData<T extends object>(config: SheetFromDataConfig<T>): Worksheet;
|
|
729
|
+
/**
|
|
730
|
+
* Infer column configuration from the first data object
|
|
731
|
+
*/
|
|
732
|
+
private _inferColumns;
|
|
733
|
+
/**
|
|
734
|
+
* Convert an unknown value to a CellValue
|
|
735
|
+
*/
|
|
736
|
+
private _toCellValue;
|
|
668
737
|
/**
|
|
669
738
|
* Create a pivot table from source data.
|
|
670
739
|
*
|
|
@@ -741,5 +810,5 @@ declare const parseRange: (range: string) => RangeAddress;
|
|
|
741
810
|
declare const toRange: (range: RangeAddress) => string;
|
|
742
811
|
|
|
743
812
|
export { Cell, PivotCache, PivotTable, Range, SharedStrings, Styles, Workbook, Worksheet, parseAddress, parseRange, toAddress, toRange };
|
|
744
|
-
export type { AggregationType, Alignment, BorderStyle, BorderType, CellAddress, CellError, CellStyle, CellType, CellValue, ErrorType, PivotFieldAxis, PivotTableConfig, PivotValueConfig, RangeAddress };
|
|
813
|
+
export type { AggregationType, Alignment, BorderStyle, BorderType, CellAddress, CellError, CellStyle, CellType, CellValue, ColumnConfig, ErrorType, PivotFieldAxis, PivotTableConfig, PivotValueConfig, RangeAddress, SheetFromDataConfig };
|
|
745
814
|
//# sourceMappingURL=index.d.ts.map
|