xlkit 1.0.5 → 1.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.d.ts CHANGED
@@ -1,3 +1,283 @@
1
- export * from './types';
2
- export * from './Sheetflow';
3
- //# sourceMappingURL=index.d.ts.map
1
+ import ExcelJS, { Cell, Worksheet } from 'exceljs';
2
+
3
+ declare class BrowserOutput {
4
+ private workbook;
5
+ constructor(workbook: ExcelJS.Workbook);
6
+ /**
7
+ * ブラウザでダウンロード
8
+ */
9
+ download(fileName: string): Promise<void>;
10
+ }
11
+
12
+ declare class NodeOutput {
13
+ private workbook;
14
+ constructor(workbook: ExcelJS.Workbook);
15
+ /**
16
+ * ファイルに保存
17
+ */
18
+ saveToFile(filePath: string): Promise<void>;
19
+ /**
20
+ * Bufferとして取得
21
+ */
22
+ toBuffer(): Promise<Buffer>;
23
+ }
24
+
25
+ type ImageSource = Buffer | string;
26
+ type ImageOptions = {
27
+ source: ImageSource;
28
+ width?: number;
29
+ height?: number;
30
+ row?: number;
31
+ col?: number;
32
+ };
33
+
34
+ type AlignType = "left" | "center" | "right";
35
+ type FormatType = "string" | "number" | "date";
36
+ type CellStyle = {
37
+ fontFamily?: string;
38
+ fontSize?: number;
39
+ bold?: boolean;
40
+ italic?: boolean;
41
+ underline?: boolean;
42
+ strike?: boolean;
43
+ color?: string;
44
+ fill?: string;
45
+ align?: AlignType;
46
+ format?: FormatType;
47
+ decimalPlaces?: number;
48
+ thousandsSeparator?: boolean;
49
+ };
50
+ type LineStyle = "thin" | "medium" | "thick" | "dotted" | "dashed" | "double";
51
+ type BorderStyle = {
52
+ outline?: LineStyle;
53
+ headerBody?: LineStyle;
54
+ headerInner?: LineStyle;
55
+ bodyInner?: LineStyle;
56
+ borderColor?: string;
57
+ };
58
+ type TableStyle = {
59
+ header?: CellStyle;
60
+ body?: CellStyle;
61
+ };
62
+
63
+ type LeafColumn<T> = {
64
+ key: keyof T & string;
65
+ label: string;
66
+ style?: CellStyle;
67
+ mergeSameValues?: boolean;
68
+ };
69
+ type ParentColumn<T> = {
70
+ label: string;
71
+ children: Column<T>[];
72
+ };
73
+ type Column<T> = LeafColumn<T> | ParentColumn<T>;
74
+
75
+ type TablePreset = "basic" | "minimal" | "striped";
76
+ type AutoWidthOption = "all" | "body" | false;
77
+ type TableOptions<T> = {
78
+ preset?: TablePreset;
79
+ columns: Column<T>[];
80
+ data: (T & {
81
+ _style?: Partial<Record<keyof T, CellStyle>>;
82
+ })[];
83
+ autoWidth?: AutoWidthOption;
84
+ mergeSameValues?: boolean;
85
+ style?: TableStyle;
86
+ border?: BorderStyle;
87
+ conditionalStyle?: (row: T, col: keyof T) => CellStyle | Record<string, never>;
88
+ };
89
+
90
+ type StyledCell = {
91
+ value: string | number | boolean;
92
+ style?: CellStyle;
93
+ };
94
+ type TextInput = string | StyledCell;
95
+
96
+ type BlockType = "table" | "text" | "image" | "space";
97
+ type Block = {
98
+ type: "table";
99
+ options: TableOptions<Record<string, unknown>>;
100
+ } | {
101
+ type: "text";
102
+ input: TextInput;
103
+ } | {
104
+ type: "image";
105
+ options: ImageOptions;
106
+ } | {
107
+ type: "space";
108
+ lines: number;
109
+ };
110
+ type SheetState = {
111
+ name: string;
112
+ blocks: Block[];
113
+ };
114
+ type WorkbookState = {
115
+ sheets: SheetState[];
116
+ };
117
+
118
+ declare class SheetBuilder {
119
+ private workbook;
120
+ private sheetState;
121
+ constructor(workbook: WorkbookBuilder, sheetState: SheetState);
122
+ /**
123
+ * テーブルを追加
124
+ */
125
+ table<T>(options: TableOptions<T>): this;
126
+ /**
127
+ * テキストを追加
128
+ */
129
+ text(input: TextInput): this;
130
+ /**
131
+ * 画像を追加
132
+ */
133
+ image(options: ImageOptions): this;
134
+ /**
135
+ * 空行を追加
136
+ */
137
+ space(lines?: number): this;
138
+ /**
139
+ * 新しいシートを追加(WorkbookBuilderに委譲)
140
+ */
141
+ sheet(name?: string): SheetBuilder;
142
+ /**
143
+ * ブラウザ向け出力オブジェクトを取得(WorkbookBuilderに委譲)
144
+ */
145
+ getBrowser(): Promise<BrowserOutput>;
146
+ /**
147
+ * Node.js向け出力オブジェクトを取得(WorkbookBuilderに委譲)
148
+ */
149
+ getNode(): Promise<NodeOutput>;
150
+ }
151
+
152
+ declare class WorkbookBuilder {
153
+ private state;
154
+ constructor();
155
+ /**
156
+ * シートを追加する
157
+ * @param name シート名(省略時は "Sheet1", "Sheet2", ...)
158
+ */
159
+ sheet(name?: string): SheetBuilder;
160
+ /**
161
+ * ワークブックの状態を取得(内部用)
162
+ */
163
+ getState(): WorkbookState;
164
+ /**
165
+ * ブラウザ向け出力オブジェクトを取得
166
+ */
167
+ getBrowser(): Promise<BrowserOutput>;
168
+ /**
169
+ * Node.js向け出力オブジェクトを取得
170
+ */
171
+ getNode(): Promise<NodeOutput>;
172
+ }
173
+ /**
174
+ * xlkit ファクトリ関数
175
+ */
176
+ declare function xlkit(): WorkbookBuilder;
177
+
178
+ /**
179
+ * セルの値とスタイルを保持
180
+ */
181
+ declare class CellReader {
182
+ private cell;
183
+ constructor(cell: Cell);
184
+ /**
185
+ * セルの値を取得
186
+ */
187
+ get value(): string | number | boolean | null;
188
+ /**
189
+ * セルのスタイルを取得
190
+ */
191
+ get style(): CellStyle | undefined;
192
+ /**
193
+ * 数値フォーマットから format を検出
194
+ */
195
+ private detectFormat;
196
+ /**
197
+ * セルの罫線情報を取得
198
+ */
199
+ get border(): CellBorder | undefined;
200
+ }
201
+ /**
202
+ * セルの罫線情報
203
+ */
204
+ type CellBorder = {
205
+ top?: {
206
+ style: LineStyle;
207
+ color?: string;
208
+ };
209
+ bottom?: {
210
+ style: LineStyle;
211
+ color?: string;
212
+ };
213
+ left?: {
214
+ style: LineStyle;
215
+ color?: string;
216
+ };
217
+ right?: {
218
+ style: LineStyle;
219
+ color?: string;
220
+ };
221
+ };
222
+
223
+ /**
224
+ * シートの読み取り
225
+ */
226
+ declare class SheetReader {
227
+ private worksheet;
228
+ constructor(worksheet: Worksheet);
229
+ /**
230
+ * シート名を取得
231
+ */
232
+ get name(): string;
233
+ /**
234
+ * セルを取得(A1形式)
235
+ */
236
+ cell(address: string): CellReader;
237
+ /**
238
+ * セルを取得(行・列番号)
239
+ */
240
+ cellAt(row: number, col: number): CellReader;
241
+ /**
242
+ * マージされたセル範囲を取得
243
+ */
244
+ get mergedCells(): string[];
245
+ /**
246
+ * 行数を取得
247
+ */
248
+ get rowCount(): number;
249
+ /**
250
+ * 列数を取得
251
+ */
252
+ get columnCount(): number;
253
+ }
254
+
255
+ /**
256
+ * ワークブックの読み取り
257
+ */
258
+ declare class WorkbookReader {
259
+ private workbook;
260
+ constructor(workbook: ExcelJS.Workbook);
261
+ /**
262
+ * シート名の配列を取得
263
+ */
264
+ get sheetNames(): string[];
265
+ /**
266
+ * シートを取得(名前指定)
267
+ */
268
+ sheet(name: string): SheetReader;
269
+ /**
270
+ * シートを取得(インデックス指定、0-indexed)
271
+ */
272
+ sheetAt(index: number): SheetReader;
273
+ /**
274
+ * シート数を取得
275
+ */
276
+ get sheetCount(): number;
277
+ }
278
+ /**
279
+ * Excelファイルを読み取る
280
+ */
281
+ declare function read(source: Buffer | string): Promise<WorkbookReader>;
282
+
283
+ export { type AlignType, type AutoWidthOption, type Block, type BlockType, type BorderStyle, type CellBorder, CellReader, type CellStyle, type Column, type FormatType, type ImageOptions, type ImageSource, type LeafColumn, type LineStyle, type ParentColumn, SheetReader, type SheetState, type StyledCell, type TableOptions, type TablePreset, type TableStyle, type TextInput, WorkbookReader, type WorkbookState, read, xlkit };