@simplysm/excel 14.0.49 → 14.0.51
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/README.md +26 -48
- package/docs/core-classes/excel-cell.md +73 -0
- package/docs/core-classes/excel-col.md +36 -0
- package/docs/core-classes/excel-row.md +34 -0
- package/docs/core-classes/excel-workbook.md +59 -0
- package/docs/core-classes/excel-worksheet.md +139 -0
- package/docs/types/excel-address-point.md +33 -0
- package/docs/types/excel-style-options.md +57 -0
- package/docs/types/excel-value-type.md +28 -0
- package/docs/types/excel-xml-content-type-data.md +23 -0
- package/docs/types/excel-xml-drawing-data.md +29 -0
- package/docs/types/excel-xml-relationship-data.md +39 -0
- package/docs/types/excel-xml-shared-string-data.md +42 -0
- package/docs/types/excel-xml-style-data.md +97 -0
- package/docs/types/excel-xml-workbook-data.md +22 -0
- package/docs/types/excel-xml-worksheet-data.md +68 -0
- package/docs/types/excel-xml.md +15 -0
- package/docs/utilities/excel-utils.md +93 -0
- package/docs/wrapper/excel-wrapper.md +100 -0
- package/package.json +2 -2
- package/docs/core-classes.md +0 -453
- package/docs/types.md +0 -459
- package/docs/utilities.md +0 -194
- package/docs/wrapper.md +0 -73
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# ExcelXmlSharedStringData
|
|
2
|
+
|
|
3
|
+
`sharedStrings.xml` 데이터 구조이다. 내부 구현에 사용된다.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export interface ExcelXmlSharedStringData {
|
|
7
|
+
sst: {
|
|
8
|
+
$: { xmlns: string };
|
|
9
|
+
si?: ExcelXmlSharedStringDataSi[];
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Type | Description |
|
|
15
|
+
|-------|------|-------------|
|
|
16
|
+
| `sst.$` | `{ xmlns: string }` | 네임스페이스 |
|
|
17
|
+
| `sst.si` | `ExcelXmlSharedStringDataSi[] \| undefined` | 공유 문자열 항목 배열 |
|
|
18
|
+
|
|
19
|
+
## Related Types
|
|
20
|
+
|
|
21
|
+
### `ExcelXmlSharedStringDataSi`
|
|
22
|
+
|
|
23
|
+
SharedString 개별 항목이다. discriminated union으로, `t` 키가 있으면 단순 텍스트, `r` 키가 있으면 서식 있는 텍스트(rich text)이다.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
export type ExcelXmlSharedStringDataSi =
|
|
27
|
+
| { t: ExcelXmlSharedStringDataText }
|
|
28
|
+
| { r: { t: ExcelXmlSharedStringDataText }[] };
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
| Variant | Discriminant | Description |
|
|
32
|
+
|---------|-------------|-------------|
|
|
33
|
+
| `{ t: ... }` | `t` 키 존재 | 단순 텍스트 |
|
|
34
|
+
| `{ r: ... }` | `r` 키 존재 | 서식 있는 텍스트 (run 배열) |
|
|
35
|
+
|
|
36
|
+
### `ExcelXmlSharedStringDataText`
|
|
37
|
+
|
|
38
|
+
SharedString 텍스트 데이터이다. 단순 문자열 또는 공백 보존 속성이 있는 객체이다.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
export type ExcelXmlSharedStringDataText = [string | { $: { space?: "preserve" }; _?: string }];
|
|
42
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# ExcelXmlStyleData
|
|
2
|
+
|
|
3
|
+
`styles.xml` 데이터 구조이다. 내부 구현에 사용된다.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export interface ExcelXmlStyleData {
|
|
7
|
+
styleSheet: {
|
|
8
|
+
$: { xmlns: string };
|
|
9
|
+
numFmts?: [{ $: { count: string }; numFmt?: { $: { numFmtId: string; formatCode: string } }[] }];
|
|
10
|
+
fonts: [{ $: { count: string }; font: {}[] }];
|
|
11
|
+
fills: [{ $: { count: string }; fill: ExcelXmlStyleDataFill[] }];
|
|
12
|
+
borders: [{ $: { count: string }; border: ExcelXmlStyleDataBorder[] }];
|
|
13
|
+
cellXfs: [{ $: { count: string }; xf: ExcelXmlStyleDataXf[] }];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| Field | Type | Description |
|
|
19
|
+
|-------|------|-------------|
|
|
20
|
+
| `styleSheet.numFmts` | `Array \| undefined` | 커스텀 숫자 형식 목록 |
|
|
21
|
+
| `styleSheet.fonts` | `Array` | 폰트 목록 |
|
|
22
|
+
| `styleSheet.fills` | `Array` | 채우기 스타일 목록 |
|
|
23
|
+
| `styleSheet.borders` | `Array` | 테두리 스타일 목록 |
|
|
24
|
+
| `styleSheet.cellXfs` | `Array` | 셀 서식(xf) 목록 |
|
|
25
|
+
|
|
26
|
+
## Related Types
|
|
27
|
+
|
|
28
|
+
### `ExcelXmlStyleDataXf`
|
|
29
|
+
|
|
30
|
+
셀 서식(xf) 데이터이다.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
export interface ExcelXmlStyleDataXf {
|
|
34
|
+
$: {
|
|
35
|
+
numFmtId?: string;
|
|
36
|
+
fontId?: string;
|
|
37
|
+
fillId?: string;
|
|
38
|
+
borderId?: string;
|
|
39
|
+
xfId?: string;
|
|
40
|
+
applyNumberFormat?: string;
|
|
41
|
+
applyFont?: string;
|
|
42
|
+
applyAlignment?: string;
|
|
43
|
+
applyFill?: string;
|
|
44
|
+
applyBorder?: string;
|
|
45
|
+
};
|
|
46
|
+
alignment?: [{ $: { horizontal?: "center" | "left" | "right"; vertical?: "center" | "top" | "bottom" } }];
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
| Field | Type | Description |
|
|
51
|
+
|-------|------|-------------|
|
|
52
|
+
| `$.numFmtId` | `string \| undefined` | 숫자 형식 ID |
|
|
53
|
+
| `$.fontId` | `string \| undefined` | 폰트 ID |
|
|
54
|
+
| `$.fillId` | `string \| undefined` | 채우기 ID |
|
|
55
|
+
| `$.borderId` | `string \| undefined` | 테두리 ID |
|
|
56
|
+
| `$.xfId` | `string \| undefined` | 부모 xf ID |
|
|
57
|
+
| `$.applyNumberFormat` | `string \| undefined` | 숫자 형식 적용 여부 |
|
|
58
|
+
| `$.applyFont` | `string \| undefined` | 폰트 적용 여부 |
|
|
59
|
+
| `$.applyAlignment` | `string \| undefined` | 정렬 적용 여부 |
|
|
60
|
+
| `$.applyFill` | `string \| undefined` | 채우기 적용 여부 |
|
|
61
|
+
| `$.applyBorder` | `string \| undefined` | 테두리 적용 여부 |
|
|
62
|
+
| `alignment` | `Array \| undefined` | 정렬 설정 (horizontal, vertical) |
|
|
63
|
+
|
|
64
|
+
### `ExcelXmlStyleDataFill`
|
|
65
|
+
|
|
66
|
+
채우기 스타일 데이터이다.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
export interface ExcelXmlStyleDataFill {
|
|
70
|
+
patternFill: [{ $: { patternType: "none" | "solid" | "gray125" }; fgColor?: [{ $: { rgb: string } }] }];
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Field | Type | Description |
|
|
75
|
+
|-------|------|-------------|
|
|
76
|
+
| `patternFill[0].$.patternType` | `"none" \| "solid" \| "gray125"` | 패턴 유형 |
|
|
77
|
+
| `patternFill[0].fgColor` | `[{ $: { rgb: string } }] \| undefined` | 전경색 (ARGB) |
|
|
78
|
+
|
|
79
|
+
### `ExcelXmlStyleDataBorder`
|
|
80
|
+
|
|
81
|
+
테두리 스타일 데이터이다. 각 방향은 선택적이며, `style`과 `color`를 가진다.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
export interface ExcelXmlStyleDataBorder {
|
|
85
|
+
top?: [{ $: { style: "thin" | "medium" }; color?: [{ $: { rgb: string } }] }];
|
|
86
|
+
left?: [{ $: { style: "thin" | "medium" }; color?: [{ $: { rgb: string } }] }];
|
|
87
|
+
right?: [{ $: { style: "thin" | "medium" }; color?: [{ $: { rgb: string } }] }];
|
|
88
|
+
bottom?: [{ $: { style: "thin" | "medium" }; color?: [{ $: { rgb: string } }] }];
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
| Field | Type | Description |
|
|
93
|
+
|-------|------|-------------|
|
|
94
|
+
| `top` | `Array \| undefined` | 상단 테두리 (`"thin"` 또는 `"medium"`) |
|
|
95
|
+
| `left` | `Array \| undefined` | 좌측 테두리 |
|
|
96
|
+
| `right` | `Array \| undefined` | 우측 테두리 |
|
|
97
|
+
| `bottom` | `Array \| undefined` | 하단 테두리 |
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ExcelXmlWorkbookData
|
|
2
|
+
|
|
3
|
+
`workbook.xml` 데이터 구조이다. 내부 구현에 사용된다.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export interface ExcelXmlWorkbookData {
|
|
7
|
+
workbook: {
|
|
8
|
+
$: { "xmlns": string; "xmlns:r"?: string };
|
|
9
|
+
bookViews?: [{ workbookView: [{}] }];
|
|
10
|
+
sheets?: [{ sheet: { $: { "name": string; "sheetId": string; "r:id": string } }[] }];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| Field | Type | Description |
|
|
16
|
+
|-------|------|-------------|
|
|
17
|
+
| `workbook.$` | `object` | 네임스페이스 |
|
|
18
|
+
| `workbook.bookViews` | `Array \| undefined` | 워크북 뷰 설정 |
|
|
19
|
+
| `workbook.sheets` | `Array \| undefined` | 시트 목록 |
|
|
20
|
+
| `workbook.sheets[0].sheet[].$.name` | `string` | 시트 이름 |
|
|
21
|
+
| `workbook.sheets[0].sheet[].$.sheetId` | `string` | 시트 ID |
|
|
22
|
+
| `workbook.sheets[0].sheet[].$["r:id"]` | `string` | 관계 ID |
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# ExcelXmlWorksheetData
|
|
2
|
+
|
|
3
|
+
`worksheet*.xml` 데이터 구조이다. 내부 구현에 사용된다.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export interface ExcelXmlWorksheetData {
|
|
7
|
+
worksheet: {
|
|
8
|
+
$: { "xmlns": string; "xmlns:r"?: string };
|
|
9
|
+
dimension?: [{ $: { ref: string } }];
|
|
10
|
+
sheetViews?: [{ sheetView: { $: { workbookViewId: string; zoomScale?: string }; pane?: [{ $: { xSplit?: string; ySplit?: string; topLeftCell?: string; activePane?: string; state?: string } }] }[] }];
|
|
11
|
+
sheetFormatPr?: [{ $: { defaultRowHeight: string } }];
|
|
12
|
+
cols?: [{ col: { $: { min: string; max: string; width?: string; bestFit?: string; customWidth?: string } }[] }];
|
|
13
|
+
sheetData: [{ row?: ExcelRowData[] }];
|
|
14
|
+
mergeCells?: [{ $: { count: string }; mergeCell: { $: { ref: string } }[] }];
|
|
15
|
+
drawing?: { $: { "r:id": string } }[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
| Field | Type | Description |
|
|
21
|
+
|-------|------|-------------|
|
|
22
|
+
| `worksheet.dimension` | `Array \| undefined` | 데이터 범위 (예: `"A1:C10"`) |
|
|
23
|
+
| `worksheet.sheetViews` | `Array \| undefined` | 시트 뷰 설정 (줌, 틀 고정) |
|
|
24
|
+
| `worksheet.sheetFormatPr` | `Array \| undefined` | 기본 행 높이 |
|
|
25
|
+
| `worksheet.cols` | `Array \| undefined` | 열 설정 (너비 등) |
|
|
26
|
+
| `worksheet.sheetData` | `Array` | 행 데이터 |
|
|
27
|
+
| `worksheet.mergeCells` | `Array \| undefined` | 병합 셀 정보 |
|
|
28
|
+
| `worksheet.drawing` | `Array \| undefined` | 드로잉 관계 참조 |
|
|
29
|
+
|
|
30
|
+
## Related Types
|
|
31
|
+
|
|
32
|
+
### `ExcelRowData`
|
|
33
|
+
|
|
34
|
+
행 XML 데이터이다.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
export interface ExcelRowData {
|
|
38
|
+
$: { r: string };
|
|
39
|
+
c?: ExcelCellData[];
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Field | Type | Description |
|
|
44
|
+
|-------|------|-------------|
|
|
45
|
+
| `$.r` | `string` | 행 주소 (1 기반, 예: `"1"`, `"10"`) |
|
|
46
|
+
| `c` | `ExcelCellData[] \| undefined` | 셀 데이터 배열 |
|
|
47
|
+
|
|
48
|
+
### `ExcelCellData`
|
|
49
|
+
|
|
50
|
+
셀 XML 데이터이다.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
export interface ExcelCellData {
|
|
54
|
+
$: { r: string; s?: string; t?: ExcelCellType };
|
|
55
|
+
v?: [string];
|
|
56
|
+
f?: [string];
|
|
57
|
+
is?: { t?: (string | { _?: string })[] }[];
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
| Field | Type | Description |
|
|
62
|
+
|-------|------|-------------|
|
|
63
|
+
| `$.r` | `string` | 셀 주소 (예: `"A1"`, `"B3"`) |
|
|
64
|
+
| `$.s` | `string \| undefined` | 스타일 ID |
|
|
65
|
+
| `$.t` | `ExcelCellType \| undefined` | 셀 타입 |
|
|
66
|
+
| `v` | `[string] \| undefined` | 셀 값 |
|
|
67
|
+
| `f` | `[string] \| undefined` | 수식 |
|
|
68
|
+
| `is` | `Array \| undefined` | 인라인 문자열 데이터 |
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# ExcelXml
|
|
2
|
+
|
|
3
|
+
XML 처리 클래스가 구현하는 인터페이스이다. `xml/` 디렉터리의 내부 클래스들이 이를 구현한다. 외부에서 직접 사용하지 않는다.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export interface ExcelXml {
|
|
7
|
+
readonly data: unknown;
|
|
8
|
+
cleanup(): void;
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
| Field | Type | Description |
|
|
13
|
+
|-------|------|-------------|
|
|
14
|
+
| `data` | `unknown` | XML 파싱된 데이터 (read-only) |
|
|
15
|
+
| `cleanup` | `() => void` | `ZipCache.toBytes()` 직전에 호출되어 직렬화 전 데이터를 정리한다 |
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# ExcelUtils
|
|
2
|
+
|
|
3
|
+
Excel 유틸리티 함수 모음. 셀 주소 변환, 날짜/숫자 변환, 숫자 형식 처리 정적 메서드를 제공한다.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export class ExcelUtils {
|
|
7
|
+
// 주소 변환
|
|
8
|
+
static stringifyAddr(point: ExcelAddressPoint): string;
|
|
9
|
+
static stringifyRowAddr(r: number): string;
|
|
10
|
+
static stringifyColAddr(c: number): string;
|
|
11
|
+
static parseRowAddr(addr: string): number;
|
|
12
|
+
static parseColAddr(addr: string): number;
|
|
13
|
+
static parseCellAddr(addr: string): ExcelAddressPoint;
|
|
14
|
+
static parseRangeAddr(rangeAddr: string): ExcelAddressRangePoint;
|
|
15
|
+
static stringifyRangeAddr(point: ExcelAddressRangePoint): string;
|
|
16
|
+
|
|
17
|
+
// 날짜/숫자 변환
|
|
18
|
+
static convertTimeTickToNumber(tick: number): number;
|
|
19
|
+
static convertNumberToTimeTick(value: number): number;
|
|
20
|
+
|
|
21
|
+
// 숫자 형식 처리
|
|
22
|
+
static convertNumFmtCodeToName(numFmtCode: string): ExcelNumberFormat;
|
|
23
|
+
static convertNumFmtIdToName(numFmtId: number): ExcelNumberFormat;
|
|
24
|
+
static convertNumFmtNameToId(numFmtName: ExcelNumberFormat): number;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Members
|
|
29
|
+
|
|
30
|
+
| Member | Kind | Type | Description |
|
|
31
|
+
|--------|------|------|-------------|
|
|
32
|
+
| `stringifyAddr` | static | `(point: ExcelAddressPoint) => string` | 셀 좌표를 "A1" 형식 문자열로 변환 |
|
|
33
|
+
| `stringifyRowAddr` | static | `(r: number) => string` | 행 인덱스(0 기반)를 행 주소 문자열로 변환 |
|
|
34
|
+
| `stringifyColAddr` | static | `(c: number) => string` | 열 인덱스(0 기반)를 열 주소 문자열로 변환. 범위: 0~16383 |
|
|
35
|
+
| `parseRowAddr` | static | `(addr: string) => number` | 셀 주소에서 0 기반 행 인덱스 추출 |
|
|
36
|
+
| `parseColAddr` | static | `(addr: string) => number` | 셀 주소에서 0 기반 열 인덱스 추출 |
|
|
37
|
+
| `parseCellAddr` | static | `(addr: string) => ExcelAddressPoint` | 셀 주소를 좌표로 변환 |
|
|
38
|
+
| `parseRangeAddr` | static | `(rangeAddr: string) => ExcelAddressRangePoint` | 범위 주소를 좌표로 변환 |
|
|
39
|
+
| `stringifyRangeAddr` | static | `(point: ExcelAddressRangePoint) => string` | 범위 좌표를 주소 문자열로 변환. 시작=끝이면 단일 셀 주소 반환 |
|
|
40
|
+
| `convertTimeTickToNumber` | static | `(tick: number) => number` | JavaScript 타임스탬프(ms)를 Excel 날짜 숫자로 변환 |
|
|
41
|
+
| `convertNumberToTimeTick` | static | `(value: number) => number` | Excel 날짜 숫자를 JavaScript 타임스탬프(ms)로 변환 |
|
|
42
|
+
| `convertNumFmtCodeToName` | static | `(numFmtCode: string) => ExcelNumberFormat` | 숫자 형식 코드를 형식 이름으로 변환 |
|
|
43
|
+
| `convertNumFmtIdToName` | static | `(numFmtId: number) => ExcelNumberFormat` | Excel 내장 숫자 형식 ID를 형식 이름으로 변환 |
|
|
44
|
+
| `convertNumFmtNameToId` | static | `(numFmtName: ExcelNumberFormat) => number` | 숫자 형식 이름을 형식 ID로 변환 |
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { ExcelUtils } from "@simplysm/excel";
|
|
50
|
+
|
|
51
|
+
// 주소 변환
|
|
52
|
+
ExcelUtils.stringifyAddr({ r: 0, c: 0 }); // "A1"
|
|
53
|
+
ExcelUtils.stringifyAddr({ r: 2, c: 3 }); // "D3"
|
|
54
|
+
ExcelUtils.parseCellAddr("B3"); // { r: 2, c: 1 }
|
|
55
|
+
ExcelUtils.parseRangeAddr("A1:C3"); // { s: { r: 0, c: 0 }, e: { r: 2, c: 2 } }
|
|
56
|
+
ExcelUtils.stringifyRangeAddr({ s: { r: 0, c: 0 }, e: { r: 2, c: 2 } }); // "A1:C3"
|
|
57
|
+
|
|
58
|
+
ExcelUtils.stringifyRowAddr(0); // "1"
|
|
59
|
+
ExcelUtils.stringifyColAddr(0); // "A"
|
|
60
|
+
ExcelUtils.stringifyColAddr(26); // "AA"
|
|
61
|
+
ExcelUtils.parseRowAddr("A3"); // 2
|
|
62
|
+
ExcelUtils.parseColAddr("B3"); // 1
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## `convertNumFmtCodeToName` 변환 규칙
|
|
66
|
+
|
|
67
|
+
| 형식 코드 패턴 | 반환값 |
|
|
68
|
+
|----------------|--------|
|
|
69
|
+
| `"General"` | `"number"` |
|
|
70
|
+
| `yy`, `dd`, `mm`(날짜 문맥) 포함 + 시간(`h`, `ss`) 포함 | `"DateTime"` |
|
|
71
|
+
| `yy`, `dd`, `mm`(날짜 문맥) 포함 | `"DateOnly"` |
|
|
72
|
+
| `h`, `ss` 포함 | `"Time"` |
|
|
73
|
+
| 숫자 패턴 (`0`, `#`, `.` 등) | `"number"` |
|
|
74
|
+
|
|
75
|
+
## `convertNumFmtIdToName` 내장 형식 ID 범위
|
|
76
|
+
|
|
77
|
+
| ID 범위 | 형식 |
|
|
78
|
+
|---------|------|
|
|
79
|
+
| 0~13, 37~40, 48 | `"number"` (숫자/일반/통화/퍼센트) |
|
|
80
|
+
| 14~17, 27~31, 34~36, 50~58 | `"DateOnly"` (날짜, 로컬라이즈 포함) |
|
|
81
|
+
| 22 | `"DateTime"` (날짜+시간) |
|
|
82
|
+
| 18~21, 32~33, 45~47 | `"Time"` (시간) |
|
|
83
|
+
| 49 | `"string"` (텍스트) |
|
|
84
|
+
|
|
85
|
+
## `convertNumFmtNameToId` 매핑
|
|
86
|
+
|
|
87
|
+
| 형식 이름 | ID |
|
|
88
|
+
|-----------|-----|
|
|
89
|
+
| `"number"` | 0 |
|
|
90
|
+
| `"DateOnly"` | 14 |
|
|
91
|
+
| `"DateTime"` | 22 |
|
|
92
|
+
| `"Time"` | 18 |
|
|
93
|
+
| `"string"` | 49 |
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# ExcelWrapper
|
|
2
|
+
|
|
3
|
+
Zod 스키마 기반 타입 안전한 Excel 읽기/쓰기 래퍼. 스키마에서 타입 정보를 추론하여 타입 안전한 읽기/쓰기를 제공한다.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
export class ExcelWrapper<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
7
|
+
constructor(schema: TSchema);
|
|
8
|
+
|
|
9
|
+
async read(
|
|
10
|
+
file: Bytes | Blob,
|
|
11
|
+
wsNameOrIndex?: string | number,
|
|
12
|
+
options?: { excludes?: (keyof z.infer<TSchema>)[] },
|
|
13
|
+
): Promise<z.infer<TSchema>[]>;
|
|
14
|
+
|
|
15
|
+
async write(
|
|
16
|
+
wsName: string,
|
|
17
|
+
records: Partial<z.infer<TSchema>>[],
|
|
18
|
+
options?: { excludes?: (keyof z.infer<TSchema>)[] },
|
|
19
|
+
): Promise<ExcelWorkbook>;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Members
|
|
24
|
+
|
|
25
|
+
| Member | Kind | Type | Description |
|
|
26
|
+
|--------|------|------|-------------|
|
|
27
|
+
| `constructor` | method | `(schema: TSchema) => ExcelWrapper<TSchema>` | Zod 스키마를 받아 인스턴스 생성. `.describe()`로 Excel 헤더 이름을 지정한다 |
|
|
28
|
+
| `read` | method | `(file, wsNameOrIndex?, options?) => Promise<z.infer<TSchema>[]>` | Excel 파일을 레코드 배열로 읽기. 스키마 유효성 검사 수행 |
|
|
29
|
+
| `write` | method | `(wsName, records, options?) => Promise<ExcelWorkbook>` | 레코드 배열을 Excel 워크북으로 변환. 반환된 워크북의 `close()`는 호출자 책임 |
|
|
30
|
+
|
|
31
|
+
## Parameters
|
|
32
|
+
|
|
33
|
+
### `read(file, wsNameOrIndex?, options?)`
|
|
34
|
+
|
|
35
|
+
| Parameter | Type | Description |
|
|
36
|
+
|-----------|------|-------------|
|
|
37
|
+
| `file` | `Bytes \| Blob` | Excel 파일 데이터 |
|
|
38
|
+
| `wsNameOrIndex` | `string \| number` | 워크시트 이름 또는 0 기반 인덱스 (기본값: `0`) |
|
|
39
|
+
| `options.excludes` | `(keyof z.infer<TSchema>)[] \| undefined` | 읽기에서 제외할 필드 키 배열 |
|
|
40
|
+
|
|
41
|
+
**타입 변환 규칙:**
|
|
42
|
+
|
|
43
|
+
| 스키마 타입 | 변환 동작 |
|
|
44
|
+
|------------|-----------|
|
|
45
|
+
| `z.string()` | 문자열로 변환 (`String(rawValue)`) |
|
|
46
|
+
| `z.number()` | 숫자로 파싱 (`num.parseFloat`) |
|
|
47
|
+
| `z.boolean()` | `"1"`, `"true"` → `true`, `"0"`, `"false"` → `false` |
|
|
48
|
+
| `z.optional()` / `z.nullable()` | 빈 셀을 `undefined`로 반환 |
|
|
49
|
+
| `z.default(value)` | 빈 셀에 기본값 적용 |
|
|
50
|
+
| `DateOnly` / `DateTime` / `Time` | `instanceof`로 직접 전달 |
|
|
51
|
+
|
|
52
|
+
### `write(wsName, records, options?)`
|
|
53
|
+
|
|
54
|
+
| Parameter | Type | Description |
|
|
55
|
+
|-----------|------|-------------|
|
|
56
|
+
| `wsName` | `string` | 워크시트 이름 |
|
|
57
|
+
| `records` | `Partial<z.infer<TSchema>>[]` | 레코드 배열 |
|
|
58
|
+
| `options.excludes` | `(keyof z.infer<TSchema>)[] \| undefined` | 쓰기에서 제외할 필드 키 배열 |
|
|
59
|
+
|
|
60
|
+
**쓰기 동작:**
|
|
61
|
+
|
|
62
|
+
- 첫 번째 행에 헤더 자동 생성 (스키마의 `.describe()` 값 사용)
|
|
63
|
+
- 모든 셀에 테두리 스타일 자동 적용
|
|
64
|
+
- 필수 비boolean 필드의 헤더에 노란색 배경(`00FFFF00`) 강조
|
|
65
|
+
- 확대/축소 85%, 첫 번째 행 틀 고정 자동 설정
|
|
66
|
+
- 내부에서 에러 발생 시 워크북이 자동으로 `close()`됨
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { ExcelWrapper } from "@simplysm/excel";
|
|
72
|
+
import { z } from "zod";
|
|
73
|
+
|
|
74
|
+
const schema = z.object({
|
|
75
|
+
name: z.string().describe("이름"),
|
|
76
|
+
age: z.number().describe("나이"),
|
|
77
|
+
email: z.string().optional().describe("이메일"),
|
|
78
|
+
active: z.boolean().default(false).describe("활성"),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const wrapper = new ExcelWrapper(schema);
|
|
82
|
+
|
|
83
|
+
// 쓰기 (시트명, 레코드 배열)
|
|
84
|
+
const wb = await wrapper.write("사람", [
|
|
85
|
+
{ name: "김철수", age: 30, email: "kim@example.com" },
|
|
86
|
+
{ name: "이영희", age: 28 },
|
|
87
|
+
]);
|
|
88
|
+
try {
|
|
89
|
+
const bytes = await wb.toBytes();
|
|
90
|
+
} finally {
|
|
91
|
+
await wb.close();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 읽기 (시트명 또는 인덱스, 기본값: 0)
|
|
95
|
+
const records = await wrapper.read(bytes, "사람");
|
|
96
|
+
// z.infer<typeof schema>[] 타입으로 반환
|
|
97
|
+
|
|
98
|
+
// excludes 옵션으로 특정 필드 제외
|
|
99
|
+
const filtered = await wrapper.read(bytes, 0, { excludes: ["email"] });
|
|
100
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/excel",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.51",
|
|
4
4
|
"description": "심플리즘 패키지 - 엑셀 (neutral)",
|
|
5
5
|
"author": "심플리즘",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"mime": "^4.1.0",
|
|
26
26
|
"zod": "^4.3.6",
|
|
27
|
-
"@simplysm/core-common": "14.0.
|
|
27
|
+
"@simplysm/core-common": "14.0.51"
|
|
28
28
|
}
|
|
29
29
|
}
|