@simplysm/excel 13.0.100 → 14.0.1

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.
Files changed (95) hide show
  1. package/dist/excel-cell.d.ts +28 -28
  2. package/dist/excel-cell.d.ts.map +1 -1
  3. package/dist/excel-cell.js +273 -264
  4. package/dist/excel-cell.js.map +1 -6
  5. package/dist/excel-col.d.ts +4 -4
  6. package/dist/excel-col.d.ts.map +1 -1
  7. package/dist/excel-col.js +33 -35
  8. package/dist/excel-col.js.map +1 -6
  9. package/dist/excel-row.d.ts +3 -3
  10. package/dist/excel-row.d.ts.map +1 -1
  11. package/dist/excel-row.js +28 -30
  12. package/dist/excel-row.js.map +1 -6
  13. package/dist/excel-workbook.d.ts +23 -23
  14. package/dist/excel-workbook.d.ts.map +1 -1
  15. package/dist/excel-workbook.js +151 -125
  16. package/dist/excel-workbook.js.map +1 -6
  17. package/dist/excel-worksheet.d.ts +32 -32
  18. package/dist/excel-worksheet.d.ts.map +1 -1
  19. package/dist/excel-worksheet.js +281 -253
  20. package/dist/excel-worksheet.js.map +1 -6
  21. package/dist/excel-wrapper.d.ts +7 -7
  22. package/dist/excel-wrapper.d.ts.map +1 -1
  23. package/dist/excel-wrapper.js +190 -226
  24. package/dist/excel-wrapper.js.map +1 -6
  25. package/dist/index.js +4 -1
  26. package/dist/index.js.map +1 -6
  27. package/dist/types.d.ts +13 -13
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/types.js +3 -1
  30. package/dist/types.js.map +1 -6
  31. package/dist/utils/excel-utils.d.ts +23 -23
  32. package/dist/utils/excel-utils.d.ts.map +1 -1
  33. package/dist/utils/excel-utils.js +183 -151
  34. package/dist/utils/excel-utils.js.map +1 -6
  35. package/dist/utils/zip-cache.d.ts +6 -6
  36. package/dist/utils/zip-cache.js +78 -60
  37. package/dist/utils/zip-cache.js.map +1 -6
  38. package/dist/xml/excel-xml-content-type.d.ts +2 -2
  39. package/dist/xml/excel-xml-content-type.js +55 -53
  40. package/dist/xml/excel-xml-content-type.js.map +1 -6
  41. package/dist/xml/excel-xml-drawing.d.ts +2 -2
  42. package/dist/xml/excel-xml-drawing.js +74 -73
  43. package/dist/xml/excel-xml-drawing.js.map +1 -6
  44. package/dist/xml/excel-xml-relationship.d.ts +2 -2
  45. package/dist/xml/excel-xml-relationship.js +67 -67
  46. package/dist/xml/excel-xml-relationship.js.map +1 -6
  47. package/dist/xml/excel-xml-shared-string.d.ts +2 -2
  48. package/dist/xml/excel-xml-shared-string.js +57 -55
  49. package/dist/xml/excel-xml-shared-string.js.map +1 -6
  50. package/dist/xml/excel-xml-style.d.ts +2 -2
  51. package/dist/xml/excel-xml-style.js +311 -295
  52. package/dist/xml/excel-xml-style.js.map +1 -6
  53. package/dist/xml/excel-xml-unknown.d.ts +2 -2
  54. package/dist/xml/excel-xml-unknown.js +11 -10
  55. package/dist/xml/excel-xml-unknown.js.map +1 -6
  56. package/dist/xml/excel-xml-workbook.d.ts +2 -2
  57. package/dist/xml/excel-xml-workbook.js +87 -90
  58. package/dist/xml/excel-xml-workbook.js.map +1 -6
  59. package/dist/xml/excel-xml-worksheet.d.ts +6 -6
  60. package/dist/xml/excel-xml-worksheet.js +450 -393
  61. package/dist/xml/excel-xml-worksheet.js.map +1 -6
  62. package/package.json +5 -7
  63. package/src/excel-cell.ts +36 -36
  64. package/src/excel-col.ts +4 -4
  65. package/src/excel-row.ts +3 -3
  66. package/src/excel-workbook.ts +38 -38
  67. package/src/excel-worksheet.ts +69 -51
  68. package/src/excel-wrapper.ts +55 -50
  69. package/src/index.ts +3 -3
  70. package/src/types.ts +17 -17
  71. package/src/utils/excel-utils.ts +47 -41
  72. package/src/utils/zip-cache.ts +6 -6
  73. package/src/xml/excel-xml-content-type.ts +3 -3
  74. package/src/xml/excel-xml-drawing.ts +2 -2
  75. package/src/xml/excel-xml-relationship.ts +3 -3
  76. package/src/xml/excel-xml-shared-string.ts +2 -2
  77. package/src/xml/excel-xml-style.ts +11 -11
  78. package/src/xml/excel-xml-unknown.ts +2 -2
  79. package/src/xml/excel-xml-workbook.ts +5 -5
  80. package/src/xml/excel-xml-worksheet.ts +43 -43
  81. package/README.md +0 -119
  82. package/docs/core-classes.md +0 -541
  83. package/docs/types.md +0 -297
  84. package/docs/utilities.md +0 -128
  85. package/docs/wrapper.md +0 -100
  86. package/tests/excel-cell.spec.ts +0 -393
  87. package/tests/excel-col.spec.ts +0 -81
  88. package/tests/excel-row.spec.ts +0 -61
  89. package/tests/excel-workbook.spec.ts +0 -205
  90. package/tests/excel-worksheet.spec.ts +0 -469
  91. package/tests/excel-wrapper.spec.ts +0 -273
  92. package/tests/fixtures/logo.png +0 -0
  93. package/tests/fixtures//354/264/210/352/270/260/355/231/224.xlsx +0 -0
  94. package/tests/image-insert.spec.ts +0 -190
  95. package/tests/utils/excel-utils.spec.ts +0 -198
@@ -1,6 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/xml/excel-xml-shared-string.ts"],
4
- "mappings": "AAMA,OAAO;AAMA,MAAM,qBAAyC;AAAA,EACpD;AAAA,EAEiB;AAAA,EAEjB,YAAY,MAAiC;AAC3C,QAAI,SAAS,QAAW;AACtB,WAAK,OAAO;AAAA,QACV,KAAK;AAAA,UACH,GAAG;AAAA,YACD,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF,OAAO;AACL,WAAK,OAAO;AAAA,IACd;AAEA,SAAK,oBAAoB,KAAK,KAAK,IAAI,KACnC,KAAK,KAAK,IAAI,GACX,IAAI,CAAC,KAAK,QAAQ,EAAE,IAAI,IAAI,EAAE,EAC9B,OAAO,CAAC,SAAS,CAAC,KAAK,yBAAyB,KAAK,GAAG,CAAC,EACzD;AAAA,MACC,CAAC,SAAS,KAAK,oBAAoB,KAAK,GAAG;AAAA,MAC3C,CAAC,SAAS,KAAK;AAAA,IACjB,IACF,oBAAI,IAAsB;AAAA,EAChC;AAAA,EAEA,cAAc,KAAiC;AAzCjD;AA0CI,YAAO,UAAK,kBAAkB,IAAI,GAAG,MAA9B,mBAAkC;AAAA,EAC3C;AAAA,EAEA,cAAc,IAAgC;AA7ChD;AA8CI,UAAM,MAAK,UAAK,KAAK,IAAI,OAAd,mBAAmB;AAC9B,WAAO,MAAM,OAAO,KAAK,oBAAoB,EAAE,IAAI;AAAA,EACrD;AAAA,EAEA,IAAI,KAAqB;AACvB,SAAK,KAAK,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,CAAC;AACxC,UAAM,YAAY,KAAK,KAAK,IAAI,GAAG,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;AACpD,UAAM,MAAM,KAAK,kBAAkB,YAAY,KAAK,CAAC,CAAC;AACtD,QAAI,KAAK,YAAY,CAAC;AACtB,WAAO,YAAY;AAAA,EACrB;AAAA,EAEA,UAAgB;AAAA,EAAC;AAAA,EAET,oBAAoB,IAAwC;AAClE,QAAI,OAAO,IAAI;AACb,aAAO,KAAK,mBAAmB,GAAG,CAAC;AAAA,IACrC,OAAO;AACL,aAAO,GAAG,EAAE,IAAI,CAAC,SAAS,KAAK,mBAAmB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE;AAAA,IACpE;AAAA,EACF;AAAA,EAEQ,mBAAmB,GAAyC;AAClE,UAAM,YAAY,EAAE,CAAC;AACrB,QAAI,OAAO,cAAc,UAAU;AACjC,aAAO;AAAA,IACT;AACA,WAAO,UAAU,KAAK;AAAA,EACxB;AAAA,EAEQ,yBAAyB,IAAyC;AACxE,WAAO,OAAO,KAAK,EAAE,EAAE,KAAK,CAAC,SAAS,SAAS,GAAG;AAAA,EACpD;AACF;",
5
- "names": []
6
- }
1
+ {"version":3,"file":"excel-xml-shared-string.js","sourceRoot":"","sources":["..\\..\\src\\xml\\excel-xml-shared-string.ts"],"names":[],"mappings":"AAMA,OAAO,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAC/B,IAAI,CAA2B;IAEd,iBAAiB,CAAwB;IAE1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+9,8 @@ export interface ExcelStyle {
9
9
  horizontalAlign?: ExcelHorizontalAlign;
10
10
  }
11
11
  /**
12
- * Class managing xl/styles.xml.
13
- * Handles styles such as number formats, background colors, borders, and alignment.
12
+ * xl/styles.xml을 관리하는 클래스.
13
+ * 숫자 형식, 배경색, 테두리, 정렬 등의 스타일을 처리한다.
14
14
  */
15
15
  export declare class ExcelXmlStyle implements ExcelXml {
16
16
  data: ExcelXmlStyleData;
@@ -1,319 +1,335 @@
1
1
  import "@simplysm/core-common";
2
2
  import { num, obj } from "@simplysm/core-common";
3
- class ExcelXmlStyle {
4
- data;
5
- constructor(data) {
6
- if (data === void 0) {
7
- this.data = {
8
- styleSheet: {
9
- $: {
10
- xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
11
- },
12
- fonts: [
13
- {
14
- $: { count: "1" },
15
- font: [{}]
3
+ /**
4
+ * xl/styles.xml을 관리하는 클래스.
5
+ * 숫자 형식, 배경색, 테두리, 정렬 등의 스타일을 처리한다.
6
+ */
7
+ export class ExcelXmlStyle {
8
+ data;
9
+ constructor(data) {
10
+ if (data === undefined) {
11
+ this.data = {
12
+ styleSheet: {
13
+ $: {
14
+ xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
15
+ },
16
+ fonts: [
17
+ {
18
+ $: { count: "1" },
19
+ font: [{}],
20
+ },
21
+ ],
22
+ fills: [
23
+ {
24
+ $: { count: "2" },
25
+ fill: [
26
+ { patternFill: [{ $: { patternType: "none" } }] },
27
+ { patternFill: [{ $: { patternType: "gray125" } }] },
28
+ ],
29
+ },
30
+ ],
31
+ borders: [
32
+ {
33
+ $: { count: "1" },
34
+ border: [{}],
35
+ },
36
+ ],
37
+ cellXfs: [
38
+ {
39
+ $: { count: "1" },
40
+ xf: [{ $: { numFmtId: "0" } }],
41
+ },
42
+ ],
43
+ },
44
+ };
45
+ }
46
+ else {
47
+ this.data = data;
48
+ }
49
+ }
50
+ add(style) {
51
+ const newXf = { $: {} };
52
+ if (style.numFmtId !== undefined) {
53
+ newXf.$.numFmtId = style.numFmtId;
54
+ }
55
+ if (style.numFmtCode !== undefined) {
56
+ newXf.$.numFmtId = this._setNumFmtCode(style.numFmtCode);
57
+ newXf.$.applyNumberFormat = "1";
58
+ }
59
+ if (style.background !== undefined) {
60
+ const newFill = {
61
+ patternFill: [
62
+ {
63
+ $: { patternType: "solid" },
64
+ fgColor: [{ $: { rgb: style.background.toUpperCase() } }],
65
+ },
66
+ ],
67
+ };
68
+ newXf.$.applyFill = "1";
69
+ newXf.$.fillId = this._getSameOrCreateFill(newFill);
70
+ }
71
+ if (style.border !== undefined) {
72
+ const newBorder = this._createBorderFromPositions(style.border);
73
+ newXf.$.applyBorder = "1";
74
+ newXf.$.borderId = this._getSameOrCreateBorder(newBorder);
75
+ }
76
+ this._applyAlignment(newXf, style);
77
+ return this._getSameOrCreateXf(newXf);
78
+ }
79
+ addWithClone(id, style) {
80
+ const idNum = num.parseInt(id);
81
+ if (idNum == null) {
82
+ throw new Error(`잘못된 스타일 ID: ${id}`);
83
+ }
84
+ const xfArray = this.data.styleSheet.cellXfs[0].xf;
85
+ if (idNum < 0 || idNum >= xfArray.length) {
86
+ throw new Error(`존재하지 않는 스타일 ID: ${id} (범위: 0-${xfArray.length - 1})`);
87
+ }
88
+ const prevXf = xfArray[idNum];
89
+ const cloneXf = obj.clone(prevXf);
90
+ if (style.numFmtId !== undefined) {
91
+ cloneXf.$.numFmtId = style.numFmtId;
92
+ }
93
+ if (style.numFmtCode !== undefined) {
94
+ cloneXf.$.numFmtId = this._setNumFmtCode(style.numFmtCode);
95
+ cloneXf.$.applyNumberFormat = "1";
96
+ }
97
+ if (style.background !== undefined) {
98
+ const fillIdNum = cloneXf.$.fillId !== undefined ? num.parseInt(cloneXf.$.fillId) : undefined;
99
+ const prevFill = fillIdNum !== undefined ? this.data.styleSheet.fills[0].fill[fillIdNum] : undefined;
100
+ if (prevFill != null) {
101
+ const cloneFill = obj.clone(prevFill);
102
+ cloneFill.patternFill[0].$.patternType = "solid";
103
+ if (cloneFill.patternFill[0].fgColor == null) {
104
+ cloneFill.patternFill[0].fgColor = [{ $: { rgb: style.background } }];
105
+ }
106
+ else {
107
+ cloneFill.patternFill[0].fgColor[0].$.rgb = style.background;
108
+ }
109
+ cloneXf.$.applyFill = "1";
110
+ cloneXf.$.fillId = this._getSameOrCreateFill(cloneFill);
16
111
  }
17
- ],
18
- fills: [
19
- {
20
- $: { count: "2" },
21
- fill: [
22
- { patternFill: [{ $: { patternType: "none" } }] },
23
- { patternFill: [{ $: { patternType: "gray125" } }] }
24
- ]
112
+ else {
113
+ const newFill = {
114
+ patternFill: [
115
+ {
116
+ $: { patternType: "solid" },
117
+ fgColor: [{ $: { rgb: style.background.toUpperCase() } }],
118
+ },
119
+ ],
120
+ };
121
+ cloneXf.$.applyFill = "1";
122
+ cloneXf.$.fillId = this._getSameOrCreateFill(newFill);
25
123
  }
26
- ],
27
- borders: [
28
- {
29
- $: { count: "1" },
30
- border: [{}]
124
+ }
125
+ if (style.border !== undefined) {
126
+ const borderIdNum = cloneXf.$.borderId !== undefined ? num.parseInt(cloneXf.$.borderId) : undefined;
127
+ const prevBorder = borderIdNum !== undefined ? this.data.styleSheet.borders[0].border[borderIdNum] : undefined;
128
+ if (prevBorder != null) {
129
+ const cloneBorder = obj.clone(prevBorder);
130
+ this._applyBorderPosition(cloneBorder, "left", style.border.includes("left"));
131
+ this._applyBorderPosition(cloneBorder, "right", style.border.includes("right"));
132
+ this._applyBorderPosition(cloneBorder, "top", style.border.includes("top"));
133
+ this._applyBorderPosition(cloneBorder, "bottom", style.border.includes("bottom"));
134
+ cloneXf.$.applyBorder = "1";
135
+ cloneXf.$.borderId = this._getSameOrCreateBorder(cloneBorder);
31
136
  }
32
- ],
33
- cellXfs: [
34
- {
35
- $: { count: "1" },
36
- xf: [{ $: { numFmtId: "0" } }]
137
+ else {
138
+ const newBorder = this._createBorderFromPositions(style.border);
139
+ cloneXf.$.applyBorder = "1";
140
+ cloneXf.$.borderId = this._getSameOrCreateBorder(newBorder);
37
141
  }
38
- ]
39
142
  }
40
- };
41
- } else {
42
- this.data = data;
43
- }
44
- }
45
- add(style) {
46
- const newXf = { $: {} };
47
- if (style.numFmtId !== void 0) {
48
- newXf.$.numFmtId = style.numFmtId;
49
- }
50
- if (style.numFmtCode !== void 0) {
51
- newXf.$.numFmtId = this._setNumFmtCode(style.numFmtCode);
52
- newXf.$.applyNumberFormat = "1";
53
- }
54
- if (style.background !== void 0) {
55
- const newFill = {
56
- patternFill: [
57
- {
58
- $: { patternType: "solid" },
59
- fgColor: [{ $: { rgb: style.background.toUpperCase() } }]
60
- }
61
- ]
62
- };
63
- newXf.$.applyFill = "1";
64
- newXf.$.fillId = this._getSameOrCreateFill(newFill);
143
+ this._applyAlignment(cloneXf, style);
144
+ return this._getSameOrCreateXf(cloneXf);
65
145
  }
66
- if (style.border !== void 0) {
67
- const newBorder = this._createBorderFromPositions(style.border);
68
- newXf.$.applyBorder = "1";
69
- newXf.$.borderId = this._getSameOrCreateBorder(newBorder);
70
- }
71
- this._applyAlignment(newXf, style);
72
- return this._getSameOrCreateXf(newXf);
73
- }
74
- addWithClone(id, style) {
75
- const idNum = num.parseInt(id);
76
- if (idNum == null) {
77
- throw new Error(`Invalid style ID: ${id}`);
78
- }
79
- const xfArray = this.data.styleSheet.cellXfs[0].xf;
80
- if (idNum < 0 || idNum >= xfArray.length) {
81
- throw new Error(`Non-existent style ID: ${id} (Range: 0-${xfArray.length - 1})`);
146
+ get(id) {
147
+ const idNum = num.parseInt(id);
148
+ if (idNum == null) {
149
+ throw new Error(`잘못된 스타일 ID: ${id}`);
150
+ }
151
+ const xf = this.data.styleSheet.cellXfs[0].xf[idNum];
152
+ const result = {};
153
+ if (xf !== undefined) {
154
+ result.numFmtId = xf.$.numFmtId;
155
+ if (xf.$.fillId !== undefined) {
156
+ const fillIdNum = num.parseInt(xf.$.fillId);
157
+ if (fillIdNum != null) {
158
+ const fill = this.data.styleSheet.fills[0].fill[fillIdNum];
159
+ if (fill == null) {
160
+ throw new Error(`존재하지 않는 fill ID: ${xf.$.fillId} (범위: 0-${this.data.styleSheet.fills[0].fill.length - 1})`);
161
+ }
162
+ result.background = fill.patternFill[0].fgColor?.[0].$.rgb;
163
+ }
164
+ }
165
+ if (xf.$.borderId !== undefined) {
166
+ const borderIdNum = num.parseInt(xf.$.borderId);
167
+ if (borderIdNum == null) {
168
+ throw new Error(`잘못된 border ID: ${xf.$.borderId}`);
169
+ }
170
+ const border = this.data.styleSheet.borders[0].border[borderIdNum];
171
+ if (border == null) {
172
+ throw new Error(`존재하지 않는 border ID: ${xf.$.borderId} (범위: 0-${this.data.styleSheet.borders[0].border.length - 1})`);
173
+ }
174
+ if (border.top != null ||
175
+ border.left != null ||
176
+ border.right != null ||
177
+ border.bottom != null) {
178
+ result.border = [];
179
+ if (border.left != null) {
180
+ result.border.push("left");
181
+ }
182
+ if (border.right != null) {
183
+ result.border.push("right");
184
+ }
185
+ if (border.top != null) {
186
+ result.border.push("top");
187
+ }
188
+ if (border.bottom != null) {
189
+ result.border.push("bottom");
190
+ }
191
+ }
192
+ }
193
+ result.verticalAlign = xf.alignment?.[0].$.vertical;
194
+ result.horizontalAlign = xf.alignment?.[0].$.horizontal;
195
+ }
196
+ return result;
82
197
  }
83
- const prevXf = xfArray[idNum];
84
- const cloneXf = obj.clone(prevXf);
85
- if (style.numFmtId !== void 0) {
86
- cloneXf.$.numFmtId = style.numFmtId;
198
+ getNumFmtCode(numFmtId) {
199
+ return (this.data.styleSheet.numFmts?.[0].numFmt ?? []).single((item) => item.$.numFmtId === numFmtId)?.$.formatCode;
87
200
  }
88
- if (style.numFmtCode !== void 0) {
89
- cloneXf.$.numFmtId = this._setNumFmtCode(style.numFmtCode);
90
- cloneXf.$.applyNumberFormat = "1";
201
+ cleanup() {
202
+ const result = {};
203
+ // 정렬 순서 (numFmts를 먼저)
204
+ if (this.data.styleSheet.numFmts != null) {
205
+ result.numFmts = this.data.styleSheet.numFmts;
206
+ }
207
+ const styleSheetRec = this.data.styleSheet;
208
+ const resultRec = result;
209
+ for (const key of Object.keys(styleSheetRec)) {
210
+ if (key === "numFmts")
211
+ continue;
212
+ resultRec[key] = styleSheetRec[key];
213
+ }
214
+ this.data.styleSheet = result;
91
215
  }
92
- if (style.background !== void 0) {
93
- const fillIdNum = cloneXf.$.fillId !== void 0 ? num.parseInt(cloneXf.$.fillId) : void 0;
94
- const prevFill = fillIdNum !== void 0 ? this.data.styleSheet.fills[0].fill[fillIdNum] : void 0;
95
- if (prevFill != null) {
96
- const cloneFill = obj.clone(prevFill);
97
- cloneFill.patternFill[0].$.patternType = "solid";
98
- if (cloneFill.patternFill[0].fgColor == null) {
99
- cloneFill.patternFill[0].fgColor = [{ $: { rgb: style.background } }];
100
- } else {
101
- cloneFill.patternFill[0].fgColor[0].$.rgb = style.background;
216
+ //#region Private Methods
217
+ _setNumFmtCode(numFmtCode) {
218
+ // 코드가 이미 존재하면 건너뛰기
219
+ const existsNumFmtId = (this.data.styleSheet.numFmts?.[0].numFmt ?? []).single((item) => item.$.formatCode === numFmtCode)?.$.numFmtId;
220
+ if (existsNumFmtId != null) {
221
+ return existsNumFmtId;
102
222
  }
103
- cloneXf.$.applyFill = "1";
104
- cloneXf.$.fillId = this._getSameOrCreateFill(cloneFill);
105
- } else {
106
- const newFill = {
107
- patternFill: [
223
+ this.data.styleSheet.numFmts = this.data.styleSheet.numFmts ?? [
108
224
  {
109
- $: { patternType: "solid" },
110
- fgColor: [{ $: { rgb: style.background.toUpperCase() } }]
111
- }
112
- ]
113
- };
114
- cloneXf.$.applyFill = "1";
115
- cloneXf.$.fillId = this._getSameOrCreateFill(newFill);
116
- }
225
+ $: { count: "0" },
226
+ numFmt: [],
227
+ },
228
+ ];
229
+ this.data.styleSheet.numFmts[0].numFmt = this.data.styleSheet.numFmts[0].numFmt ?? [];
230
+ // Excel 사용자 정의 숫자 형식은 ID 180+부터 시작 (0-163: 내장, 164-179: 예약)
231
+ const numFmts = this.data.styleSheet.numFmts[0].numFmt;
232
+ const maxItem = numFmts.length > 0
233
+ ? numFmts.orderByDesc((item) => num.parseInt(item.$.numFmtId) ?? 180).first()
234
+ : undefined;
235
+ const maxId = maxItem ? (num.parseInt(maxItem.$.numFmtId) ?? 180) : 180;
236
+ const nextNumFmtId = (maxId + 1).toString();
237
+ this.data.styleSheet.numFmts[0].numFmt.push({
238
+ $: {
239
+ numFmtId: nextNumFmtId,
240
+ formatCode: numFmtCode,
241
+ },
242
+ });
243
+ this.data.styleSheet.numFmts[0].$.count = ((num.parseInt(this.data.styleSheet.numFmts[0].$.count) ?? 0) + 1).toString();
244
+ return nextNumFmtId;
117
245
  }
118
- if (style.border !== void 0) {
119
- const borderIdNum = cloneXf.$.borderId !== void 0 ? num.parseInt(cloneXf.$.borderId) : void 0;
120
- const prevBorder = borderIdNum !== void 0 ? this.data.styleSheet.borders[0].border[borderIdNum] : void 0;
121
- if (prevBorder != null) {
122
- const cloneBorder = obj.clone(prevBorder);
123
- this._applyBorderPosition(cloneBorder, "left", style.border.includes("left"));
124
- this._applyBorderPosition(cloneBorder, "right", style.border.includes("right"));
125
- this._applyBorderPosition(cloneBorder, "top", style.border.includes("top"));
126
- this._applyBorderPosition(cloneBorder, "bottom", style.border.includes("bottom"));
127
- cloneXf.$.applyBorder = "1";
128
- cloneXf.$.borderId = this._getSameOrCreateBorder(cloneBorder);
129
- } else {
130
- const newBorder = this._createBorderFromPositions(style.border);
131
- cloneXf.$.applyBorder = "1";
132
- cloneXf.$.borderId = this._getSameOrCreateBorder(newBorder);
133
- }
246
+ _applyAlignment(xf, style) {
247
+ if (style.verticalAlign !== undefined) {
248
+ xf.$.applyAlignment = "1";
249
+ if (xf.alignment == null) {
250
+ xf.alignment = [{ $: { vertical: style.verticalAlign } }];
251
+ }
252
+ else {
253
+ xf.alignment[0].$.vertical = style.verticalAlign;
254
+ }
255
+ }
256
+ if (style.horizontalAlign !== undefined) {
257
+ xf.$.applyAlignment = "1";
258
+ if (xf.alignment == null) {
259
+ xf.alignment = [{ $: { horizontal: style.horizontalAlign } }];
260
+ }
261
+ else {
262
+ xf.alignment[0].$.horizontal = style.horizontalAlign;
263
+ }
264
+ }
134
265
  }
135
- this._applyAlignment(cloneXf, style);
136
- return this._getSameOrCreateXf(cloneXf);
137
- }
138
- get(id) {
139
- var _a, _b, _c;
140
- const idNum = num.parseInt(id);
141
- if (idNum == null) {
142
- throw new Error(`Invalid style ID: ${id}`);
266
+ _createBorderFromPositions(positions) {
267
+ return {
268
+ ...(positions.includes("left")
269
+ ? { left: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] }
270
+ : {}),
271
+ ...(positions.includes("right")
272
+ ? { right: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] }
273
+ : {}),
274
+ ...(positions.includes("top")
275
+ ? { top: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] }
276
+ : {}),
277
+ ...(positions.includes("bottom")
278
+ ? { bottom: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] }
279
+ : {}),
280
+ };
143
281
  }
144
- const xf = this.data.styleSheet.cellXfs[0].xf[idNum];
145
- const result = {};
146
- if (xf !== void 0) {
147
- result.numFmtId = xf.$.numFmtId;
148
- if (xf.$.fillId !== void 0) {
149
- const fillIdNum = num.parseInt(xf.$.fillId);
150
- if (fillIdNum != null) {
151
- const fill = this.data.styleSheet.fills[0].fill[fillIdNum];
152
- if (fill == null) {
153
- throw new Error(
154
- `Non-existent fill ID: ${xf.$.fillId} (Range: 0-${this.data.styleSheet.fills[0].fill.length - 1})`
155
- );
156
- }
157
- result.background = (_a = fill.patternFill[0].fgColor) == null ? void 0 : _a[0].$.rgb;
282
+ _applyBorderPosition(border, position, enabled) {
283
+ if (enabled) {
284
+ const existing = border[position];
285
+ if (existing == null) {
286
+ border[position] = [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }];
287
+ }
288
+ else if (existing[0].color == null) {
289
+ existing[0].color = [{ $: { rgb: "00000000" } }];
290
+ }
291
+ else {
292
+ existing[0].color[0].$.rgb = "00000000";
293
+ }
158
294
  }
159
- }
160
- if (xf.$.borderId !== void 0) {
161
- const borderIdNum = num.parseInt(xf.$.borderId);
162
- if (borderIdNum == null) {
163
- throw new Error(`Invalid border ID: ${xf.$.borderId}`);
295
+ else {
296
+ delete border[position];
164
297
  }
165
- const border = this.data.styleSheet.borders[0].border[borderIdNum];
166
- if (border == null) {
167
- throw new Error(
168
- `Non-existent border ID: ${xf.$.borderId} (Range: 0-${this.data.styleSheet.borders[0].border.length - 1})`
169
- );
298
+ }
299
+ _getSameOrCreateXf(xfItem) {
300
+ const prevSameXf = this.data.styleSheet.cellXfs[0].xf.single((item) => obj.equal(item, xfItem));
301
+ if (prevSameXf != null) {
302
+ return this.data.styleSheet.cellXfs[0].xf.indexOf(prevSameXf).toString();
170
303
  }
171
- if (border.top != null || border.left != null || border.right != null || border.bottom != null) {
172
- result.border = [];
173
- if (border.left != null) {
174
- result.border.push("left");
175
- }
176
- if (border.right != null) {
177
- result.border.push("right");
178
- }
179
- if (border.top != null) {
180
- result.border.push("top");
181
- }
182
- if (border.bottom != null) {
183
- result.border.push("bottom");
184
- }
304
+ else {
305
+ this.data.styleSheet.cellXfs[0].xf.push(xfItem);
306
+ this.data.styleSheet.cellXfs[0].$.count =
307
+ this.data.styleSheet.cellXfs[0].xf.length.toString();
308
+ return (this.data.styleSheet.cellXfs[0].xf.length - 1).toString();
185
309
  }
186
- }
187
- result.verticalAlign = (_b = xf.alignment) == null ? void 0 : _b[0].$.vertical;
188
- result.horizontalAlign = (_c = xf.alignment) == null ? void 0 : _c[0].$.horizontal;
189
- }
190
- return result;
191
- }
192
- getNumFmtCode(numFmtId) {
193
- var _a, _b;
194
- return (_b = (((_a = this.data.styleSheet.numFmts) == null ? void 0 : _a[0].numFmt) ?? []).single(
195
- (item) => item.$.numFmtId === numFmtId
196
- )) == null ? void 0 : _b.$.formatCode;
197
- }
198
- cleanup() {
199
- const result = {};
200
- if (this.data.styleSheet.numFmts != null) {
201
- result.numFmts = this.data.styleSheet.numFmts;
202
- }
203
- const styleSheetRec = this.data.styleSheet;
204
- const resultRec = result;
205
- for (const key of Object.keys(styleSheetRec)) {
206
- if (key === "numFmts") continue;
207
- resultRec[key] = styleSheetRec[key];
208
- }
209
- this.data.styleSheet = result;
210
- }
211
- //#region Private Methods
212
- _setNumFmtCode(numFmtCode) {
213
- var _a, _b;
214
- const existsNumFmtId = (_b = (((_a = this.data.styleSheet.numFmts) == null ? void 0 : _a[0].numFmt) ?? []).single(
215
- (item) => item.$.formatCode === numFmtCode
216
- )) == null ? void 0 : _b.$.numFmtId;
217
- if (existsNumFmtId != null) {
218
- return existsNumFmtId;
219
- }
220
- this.data.styleSheet.numFmts = this.data.styleSheet.numFmts ?? [
221
- {
222
- $: { count: "0" },
223
- numFmt: []
224
- }
225
- ];
226
- this.data.styleSheet.numFmts[0].numFmt = this.data.styleSheet.numFmts[0].numFmt ?? [];
227
- const numFmts = this.data.styleSheet.numFmts[0].numFmt;
228
- const maxItem = numFmts.length > 0 ? numFmts.orderByDesc((item) => num.parseInt(item.$.numFmtId) ?? 180).first() : void 0;
229
- const maxId = maxItem ? num.parseInt(maxItem.$.numFmtId) ?? 180 : 180;
230
- const nextNumFmtId = (maxId + 1).toString();
231
- this.data.styleSheet.numFmts[0].numFmt.push({
232
- $: {
233
- numFmtId: nextNumFmtId,
234
- formatCode: numFmtCode
235
- }
236
- });
237
- this.data.styleSheet.numFmts[0].$.count = ((num.parseInt(this.data.styleSheet.numFmts[0].$.count) ?? 0) + 1).toString();
238
- return nextNumFmtId;
239
- }
240
- _applyAlignment(xf, style) {
241
- if (style.verticalAlign !== void 0) {
242
- xf.$.applyAlignment = "1";
243
- if (xf.alignment == null) {
244
- xf.alignment = [{ $: { vertical: style.verticalAlign } }];
245
- } else {
246
- xf.alignment[0].$.vertical = style.verticalAlign;
247
- }
248
- }
249
- if (style.horizontalAlign !== void 0) {
250
- xf.$.applyAlignment = "1";
251
- if (xf.alignment == null) {
252
- xf.alignment = [{ $: { horizontal: style.horizontalAlign } }];
253
- } else {
254
- xf.alignment[0].$.horizontal = style.horizontalAlign;
255
- }
256
310
  }
257
- }
258
- _createBorderFromPositions(positions) {
259
- return {
260
- ...positions.includes("left") ? { left: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] } : {},
261
- ...positions.includes("right") ? { right: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] } : {},
262
- ...positions.includes("top") ? { top: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] } : {},
263
- ...positions.includes("bottom") ? { bottom: [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }] } : {}
264
- };
265
- }
266
- _applyBorderPosition(border, position, enabled) {
267
- if (enabled) {
268
- const existing = border[position];
269
- if (existing == null) {
270
- border[position] = [{ $: { style: "thin" }, color: [{ $: { rgb: "00000000" } }] }];
271
- } else if (existing[0].color == null) {
272
- existing[0].color = [{ $: { rgb: "00000000" } }];
273
- } else {
274
- existing[0].color[0].$.rgb = "00000000";
275
- }
276
- } else {
277
- delete border[position];
278
- }
279
- }
280
- _getSameOrCreateXf(xfItem) {
281
- const prevSameXf = this.data.styleSheet.cellXfs[0].xf.single((item) => obj.equal(item, xfItem));
282
- if (prevSameXf != null) {
283
- return this.data.styleSheet.cellXfs[0].xf.indexOf(prevSameXf).toString();
284
- } else {
285
- this.data.styleSheet.cellXfs[0].xf.push(xfItem);
286
- this.data.styleSheet.cellXfs[0].$.count = this.data.styleSheet.cellXfs[0].xf.length.toString();
287
- return (this.data.styleSheet.cellXfs[0].xf.length - 1).toString();
288
- }
289
- }
290
- _getSameOrCreateFill(fillItem) {
291
- const prevSameFill = this.data.styleSheet.fills[0].fill.single(
292
- (item) => obj.equal(item, fillItem)
293
- );
294
- if (prevSameFill != null) {
295
- return this.data.styleSheet.fills[0].fill.indexOf(prevSameFill).toString();
296
- } else {
297
- this.data.styleSheet.fills[0].fill.push(fillItem);
298
- this.data.styleSheet.fills[0].$.count = this.data.styleSheet.fills[0].fill.length.toString();
299
- return (this.data.styleSheet.fills[0].fill.length - 1).toString();
311
+ _getSameOrCreateFill(fillItem) {
312
+ const prevSameFill = this.data.styleSheet.fills[0].fill.single((item) => obj.equal(item, fillItem));
313
+ if (prevSameFill != null) {
314
+ return this.data.styleSheet.fills[0].fill.indexOf(prevSameFill).toString();
315
+ }
316
+ else {
317
+ this.data.styleSheet.fills[0].fill.push(fillItem);
318
+ this.data.styleSheet.fills[0].$.count = this.data.styleSheet.fills[0].fill.length.toString();
319
+ return (this.data.styleSheet.fills[0].fill.length - 1).toString();
320
+ }
300
321
  }
301
- }
302
- _getSameOrCreateBorder(borderItem) {
303
- const prevSameBorder = this.data.styleSheet.borders[0].border.single(
304
- (item) => obj.equal(item, borderItem)
305
- );
306
- if (prevSameBorder != null) {
307
- return this.data.styleSheet.borders[0].border.indexOf(prevSameBorder).toString();
308
- } else {
309
- this.data.styleSheet.borders[0].border.push(borderItem);
310
- this.data.styleSheet.borders[0].$.count = this.data.styleSheet.borders[0].border.length.toString();
311
- return (this.data.styleSheet.borders[0].border.length - 1).toString();
322
+ _getSameOrCreateBorder(borderItem) {
323
+ const prevSameBorder = this.data.styleSheet.borders[0].border.single((item) => obj.equal(item, borderItem));
324
+ if (prevSameBorder != null) {
325
+ return this.data.styleSheet.borders[0].border.indexOf(prevSameBorder).toString();
326
+ }
327
+ else {
328
+ this.data.styleSheet.borders[0].border.push(borderItem);
329
+ this.data.styleSheet.borders[0].$.count =
330
+ this.data.styleSheet.borders[0].border.length.toString();
331
+ return (this.data.styleSheet.borders[0].border.length - 1).toString();
332
+ }
312
333
  }
313
- }
314
- //#endregion
315
334
  }
316
- export {
317
- ExcelXmlStyle
318
- };
319
- //# sourceMappingURL=excel-xml-style.js.map
335
+ //# sourceMappingURL=excel-xml-style.js.map