@simplysm/excel 14.0.48 → 14.0.50

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.
@@ -1,453 +0,0 @@
1
- # Core Classes
2
-
3
- ## `ExcelWorkbook`
4
-
5
- Excel 워크북 처리 클래스. 내부적으로 ZIP 리소스를 관리하므로 사용 후 반드시 `try-finally` 블록에서 `close()`를 호출해야 한다.
6
-
7
- ```typescript
8
- export class ExcelWorkbook {
9
- readonly zipCache: ZipCache;
10
-
11
- constructor(arg?: Blob | Bytes);
12
-
13
- async getWorksheetNames(): Promise<string[]>;
14
- async addWorksheet(name: string): Promise<ExcelWorksheet>;
15
- async getWorksheet(nameOrIndex: string | number): Promise<ExcelWorksheet>;
16
- async toBytes(): Promise<Bytes>;
17
- async toBlob(): Promise<Blob>;
18
- async close(): Promise<void>;
19
- }
20
- ```
21
-
22
- ### Constructor
23
-
24
- | Parameter | Type | Description |
25
- |-----------|------|-------------|
26
- | `arg` | `Blob \| Bytes \| undefined` | 기존 Excel 파일 데이터. 생략하면 새 워크북을 생성한다 |
27
-
28
- ### Methods
29
-
30
- #### `getWorksheetNames()`
31
-
32
- 워크북의 모든 워크시트 이름을 배열로 반환한다.
33
-
34
- #### `addWorksheet(name)`
35
-
36
- 새 워크시트를 생성하여 `ExcelWorksheet` 인스턴스를 반환한다.
37
-
38
- | Parameter | Type | Description |
39
- |-----------|------|-------------|
40
- | `name` | `string` | 워크시트 이름 |
41
-
42
- #### `getWorksheet(nameOrIndex)`
43
-
44
- 이름 또는 0 기반 인덱스로 워크시트를 조회하여 반환한다. 찾을 수 없으면 에러를 던진다.
45
-
46
- | Parameter | Type | Description |
47
- |-----------|------|-------------|
48
- | `nameOrIndex` | `string \| number` | 워크시트 이름 또는 0 기반 인덱스 |
49
-
50
- #### `toBytes()`
51
-
52
- 워크북을 `Bytes`(Uint8Array)로 내보낸다.
53
-
54
- #### `toBlob()`
55
-
56
- 워크북을 `Blob`으로 내보낸다. MIME 타입은 `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`이다.
57
-
58
- #### `close()`
59
-
60
- ZIP 리더와 내부 캐시를 정리한다. 이미 닫힌 워크북에 대해 호출해도 안전하다 (no-op). 닫힌 워크북의 메서드를 호출하면 에러가 발생한다.
61
-
62
- ---
63
-
64
- ## `ExcelWorksheet`
65
-
66
- Excel 워크시트를 나타내는 클래스. 셀 접근, 행/열 복사, 데이터 테이블 처리, 이미지 삽입, 뷰 설정 기능을 제공한다.
67
-
68
- ```typescript
69
- export class ExcelWorksheet {
70
- constructor(zipCache: ZipCache, relId: number, targetFileName: string);
71
-
72
- // Name
73
- async getName(): Promise<string>;
74
- async setName(newName: string): Promise<void>;
75
-
76
- // Cell Access (0 기반)
77
- row(r: number): ExcelRow;
78
- cell(r: number, c: number): ExcelCell;
79
- col(c: number): ExcelCol;
80
-
81
- // Copy
82
- async copyRowStyle(srcR: number, targetR: number): Promise<void>;
83
- async copyCellStyle(srcAddr: ExcelAddressPoint, targetAddr: ExcelAddressPoint): Promise<void>;
84
- async copyRow(srcR: number, targetR: number): Promise<void>;
85
- async copyCell(srcAddr: ExcelAddressPoint, targetAddr: ExcelAddressPoint): Promise<void>;
86
- async insertCopyRow(srcR: number, targetR: number): Promise<void>;
87
-
88
- // Range
89
- async getRange(): Promise<ExcelAddressRangePoint>;
90
- async getCells(): Promise<ExcelCell[][]>;
91
-
92
- // Data
93
- async getDataTable(opt?: {
94
- headerRowIndex?: number;
95
- checkEndColIndex?: number;
96
- usableHeaderNameFn?: (headerName: string) => boolean;
97
- }): Promise<Record<string, ExcelValueType>[]>;
98
- async setDataMatrix(matrix: ExcelValueType[][]): Promise<void>;
99
- async setRecords(records: Record<string, ExcelValueType>[]): Promise<void>;
100
-
101
- // View
102
- async setZoom(percent: number): Promise<void>;
103
- async freezeAt(point: { r?: number; c?: number }): Promise<void>;
104
-
105
- // Image
106
- async addImage(opts: {
107
- bytes: Bytes;
108
- ext: string;
109
- from: { r: number; c: number; rOff?: number | string; cOff?: number | string };
110
- to?: { r: number; c: number; rOff?: number | string; cOff?: number | string };
111
- }): Promise<void>;
112
- }
113
- ```
114
-
115
- ### Name Methods
116
-
117
- #### `getName()`
118
-
119
- 워크시트 이름을 반환한다.
120
-
121
- #### `setName(newName)`
122
-
123
- 워크시트 이름을 변경한다.
124
-
125
- | Parameter | Type | Description |
126
- |-----------|------|-------------|
127
- | `newName` | `string` | 새 워크시트 이름 |
128
-
129
- ### Cell Access Methods
130
-
131
- 모든 좌표는 0 기반 인덱스이다.
132
-
133
- #### `row(r)`
134
-
135
- 행 객체를 반환한다.
136
-
137
- | Parameter | Type | Description |
138
- |-----------|------|-------------|
139
- | `r` | `number` | 행 인덱스 (0 기반) |
140
-
141
- #### `cell(r, c)`
142
-
143
- 셀 객체를 반환한다. 동일 좌표에 대해 항상 동일한 `ExcelCell` 인스턴스를 반환한다.
144
-
145
- | Parameter | Type | Description |
146
- |-----------|------|-------------|
147
- | `r` | `number` | 행 인덱스 (0 기반) |
148
- | `c` | `number` | 열 인덱스 (0 기반) |
149
-
150
- #### `col(c)`
151
-
152
- 열 객체를 반환한다.
153
-
154
- | Parameter | Type | Description |
155
- |-----------|------|-------------|
156
- | `c` | `number` | 열 인덱스 (0 기반) |
157
-
158
- ### Copy Methods
159
-
160
- #### `copyRowStyle(srcR, targetR)`
161
-
162
- 원본 행의 스타일을 대상 행으로 복사한다. 데이터 범위 내의 모든 열에 대해 셀 스타일을 복사한다.
163
-
164
- | Parameter | Type | Description |
165
- |-----------|------|-------------|
166
- | `srcR` | `number` | 원본 행 인덱스 (0 기반) |
167
- | `targetR` | `number` | 대상 행 인덱스 (0 기반) |
168
-
169
- #### `copyCellStyle(srcAddr, targetAddr)`
170
-
171
- 원본 셀의 스타일을 대상 셀로 복사한다.
172
-
173
- | Parameter | Type | Description |
174
- |-----------|------|-------------|
175
- | `srcAddr` | `ExcelAddressPoint` | 원본 셀 좌표 |
176
- | `targetAddr` | `ExcelAddressPoint` | 대상 셀 좌표 |
177
-
178
- #### `copyRow(srcR, targetR)`
179
-
180
- 원본 행을 대상 행으로 복사한다 (덮어쓰기).
181
-
182
- | Parameter | Type | Description |
183
- |-----------|------|-------------|
184
- | `srcR` | `number` | 원본 행 인덱스 (0 기반) |
185
- | `targetR` | `number` | 대상 행 인덱스 (0 기반) |
186
-
187
- #### `copyCell(srcAddr, targetAddr)`
188
-
189
- 원본 셀을 대상 셀로 복사한다.
190
-
191
- | Parameter | Type | Description |
192
- |-----------|------|-------------|
193
- | `srcAddr` | `ExcelAddressPoint` | 원본 셀 좌표 |
194
- | `targetAddr` | `ExcelAddressPoint` | 대상 셀 좌표 |
195
-
196
- #### `insertCopyRow(srcR, targetR)`
197
-
198
- 원본 행을 대상 위치에 삽입 복사한다. 대상 위치 이하의 기존 행은 한 칸 아래로 밀린다. 병합 셀도 자동으로 이동/확장된다.
199
-
200
- | Parameter | Type | Description |
201
- |-----------|------|-------------|
202
- | `srcR` | `number` | 복사할 원본 행 인덱스 (0 기반) |
203
- | `targetR` | `number` | 삽입할 대상 행 인덱스 (0 기반) |
204
-
205
- **병합 셀 처리:**
206
- - 삽입 지점을 관통하는 다중행 병합은 자동으로 1행 확장됨
207
- - 원본 행의 단일행 병합만 대상 행에 복사됨
208
-
209
- ### Range Methods
210
-
211
- #### `getRange()`
212
-
213
- 워크시트의 데이터 범위를 `ExcelAddressRangePoint`로 반환한다.
214
-
215
- #### `getCells()`
216
-
217
- 모든 셀을 2차원 배열(`ExcelCell[][]`)로 반환한다.
218
-
219
- ### Data Methods
220
-
221
- #### `getDataTable(opt?)`
222
-
223
- 워크시트 데이터를 테이블(레코드 배열)로 반환한다. 지정된 헤더 행(기본값: 첫 번째 행)을 기준으로 이하의 데이터를 읽는다.
224
-
225
- | Parameter | Type | Description |
226
- |-----------|------|-------------|
227
- | `opt.headerRowIndex` | `number \| undefined` | 헤더 행 인덱스 (기본값: 데이터 범위의 시작 행) |
228
- | `opt.checkEndColIndex` | `number \| undefined` | 데이터 끝을 판단할 열 인덱스. 이 열이 비어있는 행을 만나면 데이터가 끝난 것으로 판단한다 |
229
- | `opt.usableHeaderNameFn` | `(headerName: string) => boolean \| undefined` | 사용 가능한 헤더를 필터링하는 함수. 반환값이 `false`인 헤더는 제외된다 |
230
-
231
- **반환값:** `Record<string, ExcelValueType>[]` - 헤더를 키로 하는 레코드 배열
232
-
233
- #### `setDataMatrix(matrix)`
234
-
235
- 2차원 배열 데이터를 워크시트에 쓴다. (0, 0) 위치부터 시작하여 데이터를 기록한다.
236
-
237
- | Parameter | Type | Description |
238
- |-----------|------|-------------|
239
- | `matrix` | `ExcelValueType[][]` | 2차원 배열 데이터 (행 우선, `matrix[0]`이 첫 번째 행) |
240
-
241
- #### `setRecords(records)`
242
-
243
- 레코드 배열을 워크시트에 쓴다. 첫 번째 행(r=0)에 헤더가 자동 생성되고, 이후 행(r=1...)에 데이터가 기록된다. 모든 레코드의 필드를 수집하여 헤더로 사용한다.
244
-
245
- | Parameter | Type | Description |
246
- |-----------|------|-------------|
247
- | `records` | `Record<string, ExcelValueType>[]` | 레코드 배열 |
248
-
249
- ### View Methods
250
-
251
- #### `setZoom(percent)`
252
-
253
- 워크시트 확대/축소 비율을 설정한다.
254
-
255
- | Parameter | Type | Description |
256
- |-----------|------|-------------|
257
- | `percent` | `number` | 확대/축소 퍼센트 |
258
-
259
- #### `freezeAt(point)`
260
-
261
- 행/열 틀 고정을 설정한다.
262
-
263
- | Parameter | Type | Description |
264
- |-----------|------|-------------|
265
- | `point.r` | `number \| undefined` | 고정할 행 인덱스 (0 기반) |
266
- | `point.c` | `number \| undefined` | 고정할 열 인덱스 (0 기반) |
267
-
268
- ### Image Methods
269
-
270
- #### `addImage(opts)`
271
-
272
- 워크시트에 이미지를 삽입한다. 같은 시트의 첫 이미지 호출 시 `drawing1.xml` 생성, 이후 이미지는 동일 drawing에 추가된다.
273
-
274
- | Parameter | Type | Description |
275
- |-----------|------|-------------|
276
- | `opts.bytes` | `Bytes` | 이미지 바이너리 데이터 |
277
- | `opts.ext` | `string` | 이미지 확장자 (예: `"png"`, `"jpg"`, `"gif"`) |
278
- | `opts.from` | `{ r: number; c: number; rOff?: number \| string; cOff?: number \| string }` | 이미지 시작 위치. `r`/`c`는 0 기반 행/열 인덱스, `rOff`/`cOff`는 선택적 EMU 오프셋 |
279
- | `opts.to` | `{ r: number; c: number; rOff?: number \| string; cOff?: number \| string } \| undefined` | 이미지 끝 위치. 생략 시 기본값은 `{ r: from.r + 1, c: from.c + 1 }`이다 |
280
-
281
- **이미지 파일 관리:**
282
- - 이미지는 `xl/media/image1.ext`, `xl/media/image2.ext` 등으로 자동 관리됨
283
- - 기존 파일명과 중복되지 않도록 인덱스 자동 증가
284
-
285
- ---
286
-
287
- ## `ExcelCell`
288
-
289
- Excel 셀을 나타내는 클래스. 값 읽기/쓰기, 수식, 스타일, 셀 병합 기능을 제공한다. 모든 메서드가 `async`인 이유는 셀 타입에 따라 필요한 XML만 선택적으로 로드하는 Lazy Loading 아키텍처 때문이다.
290
-
291
- ```typescript
292
- export class ExcelCell {
293
- readonly addr: ExcelAddressPoint;
294
-
295
- constructor(zipCache: ZipCache, targetFileName: string, r: number, c: number);
296
-
297
- // Value
298
- async setValue(val: ExcelValueType): Promise<void>;
299
- async getValue(): Promise<ExcelValueType>;
300
- async setFormula(val: string | undefined): Promise<void>;
301
- async getFormula(): Promise<string | undefined>;
302
-
303
- // Merge
304
- async merge(r: number, c: number): Promise<void>;
305
-
306
- // Style
307
- async getStyleId(): Promise<string | undefined>;
308
- async setStyleId(styleId: string | undefined): Promise<void>;
309
- async setStyle(opts: ExcelStyleOptions): Promise<void>;
310
- }
311
- ```
312
-
313
- ### Properties
314
-
315
- | Property | Type | Description |
316
- |----------|------|-------------|
317
- | `addr` | `ExcelAddressPoint` | 셀 주소 (0 기반 행/열 인덱스) |
318
-
319
- ### Value Methods
320
-
321
- #### `setValue(val)`
322
-
323
- 셀 값을 설정한다. `undefined`를 전달하면 셀이 삭제된다. `DateOnly`, `DateTime`, `Time` 인스턴스를 전달하면 내부적으로 Excel 날짜 숫자로 변환하고 적절한 numFmt를 설정한다.
324
-
325
- | Parameter | Type | Description |
326
- |-----------|------|-------------|
327
- | `val` | `ExcelValueType` | 셀 값 (`number \| string \| DateOnly \| DateTime \| Time \| boolean \| undefined`) |
328
-
329
- #### `getValue()`
330
-
331
- 셀 값을 반환한다. 셀 타입과 스타일에 따라 적절한 JavaScript 타입으로 변환한다. 비어있는 셀은 `undefined`를 반환한다.
332
-
333
- #### `setFormula(val)`
334
-
335
- 셀에 수식을 설정한다. `undefined`를 전달하면 수식이 제거된다.
336
-
337
- | Parameter | Type | Description |
338
- |-----------|------|-------------|
339
- | `val` | `string \| undefined` | 수식 문자열 (예: `"SUM(A1:A10)"`) |
340
-
341
- #### `getFormula()`
342
-
343
- 셀 수식을 반환한다. 수식이 없으면 `undefined`를 반환한다.
344
-
345
- ### Merge Methods
346
-
347
- #### `merge(r, c)`
348
-
349
- 현재 셀에서 지정된 끝 좌표까지 셀을 병합한다.
350
-
351
- | Parameter | Type | Description |
352
- |-----------|------|-------------|
353
- | `r` | `number` | 병합 끝 행 인덱스 (0 기반) |
354
- | `c` | `number` | 병합 끝 열 인덱스 (0 기반) |
355
-
356
- ### Style Methods
357
-
358
- #### `getStyleId()`
359
-
360
- 셀의 스타일 ID를 반환한다. 스타일이 없으면 `undefined`를 반환한다.
361
-
362
- #### `setStyleId(styleId)`
363
-
364
- 셀의 스타일 ID를 직접 설정한다.
365
-
366
- | Parameter | Type | Description |
367
- |-----------|------|-------------|
368
- | `styleId` | `string \| undefined` | 스타일 ID |
369
-
370
- #### `setStyle(opts)`
371
-
372
- 셀 스타일을 설정한다. 기존 스타일이 있으면 클론 후 병합한다.
373
-
374
- 커스텀 Excel formatCode를 지정하려면 `numberFormatCode`를 사용한다:
375
-
376
- ```typescript
377
- await cell.setStyle({ numberFormatCode: "0.000000" }); // 소수점 6자리
378
- await cell.setStyle({ numberFormatCode: "#,##0.00" }); // 천 단위 구분 + 2자리
379
- await cell.setStyle({ numberFormatCode: "0.00%" }); // 퍼센트
380
- ```
381
-
382
- `numberFormat`(프리셋)과 `numberFormatCode`(커스텀)가 동시에 지정되면 `numberFormatCode`가 우선 적용된다.
383
-
384
- | Parameter | Type | Description |
385
- |-----------|------|-------------|
386
- | `opts` | `ExcelStyleOptions` | 스타일 옵션 (배경색, 테두리, 정렬, 숫자 형식) |
387
-
388
- ---
389
-
390
- ## `ExcelRow`
391
-
392
- Excel 워크시트의 행을 나타내는 클래스. 셀 접근 기능을 제공한다.
393
-
394
- ```typescript
395
- export class ExcelRow {
396
- constructor(zipCache: ZipCache, targetFileName: string, r: number, cellFactory: (c: number) => ExcelCell);
397
-
398
- cell(c: number): ExcelCell;
399
- async getCells(): Promise<ExcelCell[]>;
400
- }
401
- ```
402
-
403
- ### Methods
404
-
405
- #### `cell(c)`
406
-
407
- 지정된 열 인덱스의 셀을 반환한다.
408
-
409
- | Parameter | Type | Description |
410
- |-----------|------|-------------|
411
- | `c` | `number` | 열 인덱스 (0 기반) |
412
-
413
- #### `getCells()`
414
-
415
- 행의 모든 셀을 배열로 반환한다. 데이터 범위 내의 모든 열에 대한 셀이 포함된다.
416
-
417
- ---
418
-
419
- ## `ExcelCol`
420
-
421
- Excel 워크시트의 열을 나타내는 클래스. 셀 접근 및 열 너비 설정 기능을 제공한다.
422
-
423
- ```typescript
424
- export class ExcelCol {
425
- constructor(zipCache: ZipCache, targetFileName: string, c: number, cellFactory: (r: number) => ExcelCell);
426
-
427
- cell(r: number): ExcelCell;
428
- async getCells(): Promise<ExcelCell[]>;
429
- async setWidth(size: number): Promise<void>;
430
- }
431
- ```
432
-
433
- ### Methods
434
-
435
- #### `cell(r)`
436
-
437
- 지정된 행 인덱스의 셀을 반환한다.
438
-
439
- | Parameter | Type | Description |
440
- |-----------|------|-------------|
441
- | `r` | `number` | 행 인덱스 (0 기반) |
442
-
443
- #### `getCells()`
444
-
445
- 열의 모든 셀을 배열로 반환한다. 데이터 범위 내의 모든 행에 대한 셀이 포함된다.
446
-
447
- #### `setWidth(size)`
448
-
449
- 열 너비를 설정한다.
450
-
451
- | Parameter | Type | Description |
452
- |-----------|------|-------------|
453
- | `size` | `number` | 열 너비 |