@simplysm/excel 14.0.100 → 14.0.102
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/biff/biff-model-factory.d.ts +32 -0
- package/dist/biff/biff-model-factory.d.ts.map +1 -0
- package/dist/biff/biff-model-factory.js +88 -0
- package/dist/biff/biff-model-factory.js.map +1 -0
- package/dist/biff/biff-ptg.d.ts +14 -0
- package/dist/biff/biff-ptg.d.ts.map +1 -0
- package/dist/biff/biff-ptg.js +277 -0
- package/dist/biff/biff-ptg.js.map +1 -0
- package/dist/biff/biff-records.d.ts +163 -0
- package/dist/biff/biff-records.d.ts.map +1 -0
- package/dist/biff/biff-records.js +579 -0
- package/dist/biff/biff-records.js.map +1 -0
- package/dist/biff/biff-shared-string-model.d.ts +13 -0
- package/dist/biff/biff-shared-string-model.d.ts.map +1 -0
- package/dist/biff/biff-shared-string-model.js +41 -0
- package/dist/biff/biff-shared-string-model.js.map +1 -0
- package/dist/biff/biff-style-model.d.ts +39 -0
- package/dist/biff/biff-style-model.d.ts.map +1 -0
- package/dist/biff/biff-style-model.js +182 -0
- package/dist/biff/biff-style-model.js.map +1 -0
- package/dist/biff/biff-workbook-model.d.ts +17 -0
- package/dist/biff/biff-workbook-model.d.ts.map +1 -0
- package/dist/biff/biff-workbook-model.js +64 -0
- package/dist/biff/biff-workbook-model.js.map +1 -0
- package/dist/biff/biff-worksheet-model.d.ts +69 -0
- package/dist/biff/biff-worksheet-model.d.ts.map +1 -0
- package/dist/biff/biff-worksheet-model.js +495 -0
- package/dist/biff/biff-worksheet-model.js.map +1 -0
- package/dist/biff/biff12-codec.d.ts +149 -0
- package/dist/biff/biff12-codec.d.ts.map +1 -0
- package/dist/biff/biff12-codec.js +262 -0
- package/dist/biff/biff12-codec.js.map +1 -0
- package/dist/excel-cell.d.ts +0 -6
- package/dist/excel-cell.d.ts.map +1 -1
- package/dist/excel-cell.js +2 -24
- package/dist/excel-cell.js.map +1 -1
- package/dist/excel-col.js.map +1 -1
- package/dist/excel-row.js.map +1 -1
- package/dist/excel-workbook.d.ts +4 -21
- package/dist/excel-workbook.d.ts.map +1 -1
- package/dist/excel-workbook.js +16 -49
- package/dist/excel-workbook.js.map +1 -1
- package/dist/excel-worksheet.d.ts +0 -11
- package/dist/excel-worksheet.d.ts.map +1 -1
- package/dist/excel-worksheet.js +9 -46
- package/dist/excel-worksheet.js.map +1 -1
- package/dist/excel-wrapper.d.ts +0 -10
- package/dist/excel-wrapper.d.ts.map +1 -1
- package/dist/excel-wrapper.js +0 -10
- package/dist/excel-wrapper.js.map +1 -1
- package/dist/models/excel-format.d.ts +3 -0
- package/dist/models/excel-format.d.ts.map +1 -0
- package/dist/models/excel-format.js +2 -0
- package/dist/models/excel-format.js.map +1 -0
- package/dist/models/excel-model-factory.d.ts +33 -0
- package/dist/models/excel-model-factory.d.ts.map +1 -0
- package/dist/models/excel-model-factory.js +2 -0
- package/dist/models/excel-model-factory.js.map +1 -0
- package/dist/models/excel-model.d.ts +12 -0
- package/dist/models/excel-model.d.ts.map +1 -0
- package/dist/models/excel-model.js +2 -0
- package/dist/models/excel-model.js.map +1 -0
- package/dist/models/i-content-type-model.d.ts +7 -0
- package/dist/models/i-content-type-model.d.ts.map +1 -0
- package/dist/models/i-content-type-model.js +2 -0
- package/dist/models/i-content-type-model.js.map +1 -0
- package/dist/models/i-drawing-model.d.ts +23 -0
- package/dist/models/i-drawing-model.d.ts.map +1 -0
- package/dist/models/i-drawing-model.js +2 -0
- package/dist/models/i-drawing-model.js.map +1 -0
- package/dist/models/i-relationship-model.d.ts +16 -0
- package/dist/models/i-relationship-model.d.ts.map +1 -0
- package/dist/models/i-relationship-model.js +2 -0
- package/dist/models/i-relationship-model.js.map +1 -0
- package/dist/models/i-shared-string-model.d.ts +9 -0
- package/dist/models/i-shared-string-model.d.ts.map +1 -0
- package/dist/models/i-shared-string-model.js +2 -0
- package/dist/models/i-shared-string-model.js.map +1 -0
- package/dist/models/i-style-model.d.ts +18 -0
- package/dist/models/i-style-model.d.ts.map +1 -0
- package/dist/models/i-style-model.js +2 -0
- package/dist/models/i-style-model.js.map +1 -0
- package/dist/models/i-workbook-model.d.ts +17 -0
- package/dist/models/i-workbook-model.d.ts.map +1 -0
- package/dist/models/i-workbook-model.js +2 -0
- package/dist/models/i-workbook-model.js.map +1 -0
- package/dist/models/i-worksheet-model.d.ts +39 -0
- package/dist/models/i-worksheet-model.d.ts.map +1 -0
- package/dist/models/i-worksheet-model.js +2 -0
- package/dist/models/i-worksheet-model.js.map +1 -0
- package/dist/models/shared/excel-cf-spec.d.ts +13 -0
- package/dist/models/shared/excel-cf-spec.d.ts.map +1 -0
- package/dist/models/shared/excel-cf-spec.js +2 -0
- package/dist/models/shared/excel-cf-spec.js.map +1 -0
- package/dist/models/shared/excel-style.d.ts +24 -0
- package/dist/models/shared/excel-style.d.ts.map +1 -0
- package/dist/models/shared/excel-style.js +38 -0
- package/dist/models/shared/excel-style.js.map +1 -0
- package/dist/types.d.ts +0 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/excel-style-data.d.ts +3 -5
- package/dist/utils/excel-style-data.d.ts.map +1 -1
- package/dist/utils/excel-style-data.js +2 -16
- package/dist/utils/excel-style-data.js.map +1 -1
- package/dist/utils/zip-cache.d.ts +46 -9
- package/dist/utils/zip-cache.d.ts.map +1 -1
- package/dist/utils/zip-cache.js +138 -52
- package/dist/utils/zip-cache.js.map +1 -1
- package/dist/xml/excel-xml-content-type.d.ts +8 -4
- package/dist/xml/excel-xml-content-type.d.ts.map +1 -1
- package/dist/xml/excel-xml-content-type.js +13 -6
- package/dist/xml/excel-xml-content-type.js.map +1 -1
- package/dist/xml/excel-xml-drawing.d.ts +8 -4
- package/dist/xml/excel-xml-drawing.d.ts.map +1 -1
- package/dist/xml/excel-xml-drawing.js +14 -7
- package/dist/xml/excel-xml-drawing.js.map +1 -1
- package/dist/xml/excel-xml-relationship.d.ts +12 -4
- package/dist/xml/excel-xml-relationship.d.ts.map +1 -1
- package/dist/xml/excel-xml-relationship.js +22 -12
- package/dist/xml/excel-xml-relationship.js.map +1 -1
- package/dist/xml/excel-xml-shared-string.d.ts +8 -4
- package/dist/xml/excel-xml-shared-string.d.ts.map +1 -1
- package/dist/xml/excel-xml-shared-string.js +16 -9
- package/dist/xml/excel-xml-shared-string.js.map +1 -1
- package/dist/xml/excel-xml-style.d.ts +11 -22
- package/dist/xml/excel-xml-style.d.ts.map +1 -1
- package/dist/xml/excel-xml-style.js +66 -92
- package/dist/xml/excel-xml-style.js.map +1 -1
- package/dist/xml/excel-xml-unknown.d.ts +6 -5
- package/dist/xml/excel-xml-unknown.d.ts.map +1 -1
- package/dist/xml/excel-xml-unknown.js +7 -4
- package/dist/xml/excel-xml-unknown.js.map +1 -1
- package/dist/xml/excel-xml-workbook.d.ts +9 -4
- package/dist/xml/excel-xml-workbook.d.ts.map +1 -1
- package/dist/xml/excel-xml-workbook.js +28 -20
- package/dist/xml/excel-xml-workbook.js.map +1 -1
- package/dist/xml/excel-xml-worksheet.d.ts +12 -7
- package/dist/xml/excel-xml-worksheet.d.ts.map +1 -1
- package/dist/xml/excel-xml-worksheet.js +65 -50
- package/dist/xml/excel-xml-worksheet.js.map +1 -1
- package/dist/xml/xml-model-factory.d.ts +25 -0
- package/dist/xml/xml-model-factory.d.ts.map +1 -0
- package/dist/xml/xml-model-factory.js +66 -0
- package/dist/xml/xml-model-factory.js.map +1 -0
- package/package.json +2 -2
- package/src/biff/biff-model-factory.ts +101 -0
- package/src/biff/biff-ptg.ts +289 -0
- package/src/biff/biff-records.ts +686 -0
- package/src/biff/biff-shared-string-model.ts +52 -0
- package/src/biff/biff-style-model.ts +219 -0
- package/src/biff/biff-workbook-model.ts +83 -0
- package/src/biff/biff-worksheet-model.ts +545 -0
- package/src/biff/biff12-codec.ts +286 -0
- package/src/excel-cell.ts +12 -46
- package/src/excel-col.ts +3 -3
- package/src/excel-row.ts +3 -3
- package/src/excel-workbook.ts +26 -69
- package/src/excel-worksheet.ts +36 -107
- package/src/excel-wrapper.ts +0 -10
- package/src/models/excel-format.ts +2 -0
- package/src/models/excel-model-factory.ts +33 -0
- package/src/models/excel-model.ts +12 -0
- package/src/models/i-content-type-model.ts +7 -0
- package/src/models/i-drawing-model.ts +13 -0
- package/src/models/i-relationship-model.ts +13 -0
- package/src/models/i-shared-string-model.ts +9 -0
- package/src/models/i-style-model.ts +18 -0
- package/src/models/i-workbook-model.ts +17 -0
- package/src/models/i-worksheet-model.ts +40 -0
- package/src/models/shared/excel-cf-spec.ts +24 -0
- package/src/models/shared/excel-style.ts +65 -0
- package/src/types.ts +0 -13
- package/src/utils/excel-style-data.ts +4 -25
- package/src/utils/zip-cache.ts +189 -58
- package/src/xml/excel-xml-content-type.ts +18 -8
- package/src/xml/excel-xml-drawing.ts +19 -9
- package/src/xml/excel-xml-relationship.ts +28 -14
- package/src/xml/excel-xml-shared-string.ts +20 -11
- package/src/xml/excel-xml-style.ts +74 -116
- package/src/xml/excel-xml-unknown.ts +8 -4
- package/src/xml/excel-xml-workbook.ts +34 -22
- package/src/xml/excel-xml-worksheet.ts +73 -53
- package/src/xml/xml-model-factory.ts +83 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Bytes } from "@simplysm/core-common";
|
|
2
|
+
import type { ISharedStringModel } from "../models/i-shared-string-model";
|
|
3
|
+
import { concatBytes, REC } from "./biff12-codec";
|
|
4
|
+
import {
|
|
5
|
+
encodeBrtBeginSst,
|
|
6
|
+
encodeBrtSSTItem,
|
|
7
|
+
encodeMarker,
|
|
8
|
+
readSharedStrings,
|
|
9
|
+
} from "./biff-records";
|
|
10
|
+
|
|
11
|
+
/** sharedStrings.bin (BIFF12) 읽기/쓰기 모델. */
|
|
12
|
+
export class BiffSharedStringModel implements ISharedStringModel {
|
|
13
|
+
private readonly _strings: string[];
|
|
14
|
+
private readonly _indexMap = new Map<string, number>();
|
|
15
|
+
|
|
16
|
+
constructor(bytes?: Bytes) {
|
|
17
|
+
this._strings = bytes != null ? readSharedStrings(bytes) : [];
|
|
18
|
+
for (let i = 0; i < this._strings.length; i++) {
|
|
19
|
+
if (!this._indexMap.has(this._strings[i])) {
|
|
20
|
+
this._indexMap.set(this._strings[i], i);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getStringById(id: number): string | undefined {
|
|
26
|
+
return this._strings[id];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getIdByString(str: string): number | undefined {
|
|
30
|
+
return this._indexMap.get(str);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
add(str: string): number {
|
|
34
|
+
const existing = this._indexMap.get(str);
|
|
35
|
+
if (existing != null) return existing;
|
|
36
|
+
const idx = this._strings.length;
|
|
37
|
+
this._strings.push(str);
|
|
38
|
+
this._indexMap.set(str, idx);
|
|
39
|
+
return idx;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
serialize(): Bytes {
|
|
43
|
+
const parts: Uint8Array[] = [
|
|
44
|
+
encodeBrtBeginSst(this._strings.length, this._strings.length),
|
|
45
|
+
];
|
|
46
|
+
for (const s of this._strings) {
|
|
47
|
+
parts.push(encodeBrtSSTItem(s));
|
|
48
|
+
}
|
|
49
|
+
parts.push(encodeMarker(REC.BrtEndSst));
|
|
50
|
+
return concatBytes(parts);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { Bytes } from "@simplysm/core-common";
|
|
2
|
+
import type { IStyleModel } from "../models/i-style-model";
|
|
3
|
+
import type { ExcelStyle } from "../models/shared/excel-style";
|
|
4
|
+
import type { ExcelConditionalRuleStyle } from "../types";
|
|
5
|
+
import { concatBytes, encodeRecord, readAllRecords, readXLWideString, REC } from "./biff12-codec";
|
|
6
|
+
import { encodeBeginCount, encodeBrtDXF, encodeBrtFmt, encodeCellXF, encodeMarker } from "./biff-records";
|
|
7
|
+
|
|
8
|
+
const HEX = (n: number): string => n.toString(16).padStart(2, "0").toUpperCase();
|
|
9
|
+
|
|
10
|
+
const READONLY_WRITE = "기존 xlsb 의 스타일 수정은 아직 지원되지 않습니다 (후속 예정).";
|
|
11
|
+
const STYLE_WRITE_LIMIT =
|
|
12
|
+
"xlsb 는 numberFormat 외 셀 스타일(배경/테두리/폰트/정렬) 쓰기를 아직 지원하지 않습니다 (후속 예정).";
|
|
13
|
+
|
|
14
|
+
const hexBytes = (h: string): Uint8Array =>
|
|
15
|
+
Uint8Array.from(h.split(" ").map((x) => parseInt(x, 16)));
|
|
16
|
+
|
|
17
|
+
// boa-sample.xlsb 정답지에서 추출한 기본 슬롯 (Calibri 11 / none·gray125 fill / empty border / General xf).
|
|
18
|
+
const SLOT_FONT = hexBytes(
|
|
19
|
+
"dc 00 00 00 90 01 00 00 00 02 00 00 07 01 00 00 00 00 00 ff 02 07 00 00 00 43 00 61 00 6c 00 69 00 62 00 72 00 69 00",
|
|
20
|
+
);
|
|
21
|
+
const SLOT_FILL_NONE = hexBytes(
|
|
22
|
+
"00 00 00 00 03 40 00 00 00 00 00 ff 03 41 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
|
23
|
+
);
|
|
24
|
+
const SLOT_FILL_GRAY125 = hexBytes(
|
|
25
|
+
"11 00 00 00 03 40 00 00 00 00 00 ff 03 41 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
|
26
|
+
);
|
|
27
|
+
const SLOT_BORDER = hexBytes(
|
|
28
|
+
"00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00",
|
|
29
|
+
);
|
|
30
|
+
const SLOT_CELLSTYLEXF = hexBytes("ff ff 00 00 00 00 00 00 00 00 00 00 10 10 00 00");
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* styles.bin (BIFF12) 읽기/쓰기 모델.
|
|
34
|
+
*
|
|
35
|
+
* **읽기**: 셀 iStyleRef(cellXFs 인덱스) → numFmtId 매핑 + numFmt 코드 디코드(날짜/숫자 포맷 판정용).
|
|
36
|
+
* 원본을 읽은 경우 직렬화는 원본 바이트를 그대로 보존한다(스타일 손실 방지).
|
|
37
|
+
*
|
|
38
|
+
* **쓰기**(새 워크북, 빈 모델): numberFormat 만 지원. 기본 슬롯(font/fill/border/cellStyleXF)을
|
|
39
|
+
* 정답지 byte 로 고정하고, cellXFs 만 numFmtId 별로 추가하여 styles.bin 을 재생성한다.
|
|
40
|
+
* 배경·테두리·폰트·정렬은 후속 단계.
|
|
41
|
+
*/
|
|
42
|
+
export class BiffStyleModel implements IStyleModel {
|
|
43
|
+
private readonly _raw: Bytes | undefined;
|
|
44
|
+
private readonly _numFmts = new Map<number, string>();
|
|
45
|
+
private readonly _cellXfNumFmtIds: number[];
|
|
46
|
+
private readonly _dxfs: ExcelConditionalRuleStyle[] = [];
|
|
47
|
+
|
|
48
|
+
constructor(bytes?: Bytes) {
|
|
49
|
+
this._raw = bytes;
|
|
50
|
+
if (bytes != null) {
|
|
51
|
+
this._cellXfNumFmtIds = [];
|
|
52
|
+
this._decode(bytes);
|
|
53
|
+
} else {
|
|
54
|
+
this._cellXfNumFmtIds = [0]; // cellXF[0] = General
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private _decode(buf: Uint8Array): void {
|
|
59
|
+
let inCellXfs = false;
|
|
60
|
+
for (const rec of readAllRecords(buf)) {
|
|
61
|
+
if (rec.type === REC.BrtFmt) {
|
|
62
|
+
const id = rec.payload[0] | (rec.payload[1] << 8);
|
|
63
|
+
this._numFmts.set(id, readXLWideString(rec.payload, 2).value);
|
|
64
|
+
} else if (rec.type === REC.BrtBeginCellXFs) {
|
|
65
|
+
inCellXfs = true;
|
|
66
|
+
} else if (rec.type === REC.BrtEndCellXFs) {
|
|
67
|
+
inCellXfs = false;
|
|
68
|
+
} else if (inCellXfs && rec.type === REC.BrtXF) {
|
|
69
|
+
// BrtXF(16B): ixfeParent(u16@0) + iFmt(u16@2) + iFont(@4) + iFill(@6) + ixBorder(@8) + ...
|
|
70
|
+
this._cellXfNumFmtIds.push(rec.payload[2] | (rec.payload[3] << 8));
|
|
71
|
+
} else if (rec.type === REC.BrtDXF) {
|
|
72
|
+
this._dxfs.push(this._decodeDxf(rec.payload));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* BrtDXF([MS-XLSB] 2.4.359) payload → 조건부 서식 스타일.
|
|
79
|
+
* header(2) + XFProps(reserved 2 + cprops 2 + XFProp[]). bg color(0x02)→background,
|
|
80
|
+
* text color(0x05)→fontColor, Bold(0x19, >=700)→bold. 그 외 prop(border/numFmt 등)은 무시.
|
|
81
|
+
*/
|
|
82
|
+
private _decodeDxf(p: Uint8Array): ExcelConditionalRuleStyle {
|
|
83
|
+
const dxf: ExcelConditionalRuleStyle = {};
|
|
84
|
+
if (p.length < 6) return dxf;
|
|
85
|
+
const cprops = p[4] | (p[5] << 8);
|
|
86
|
+
// XFPropColor(8B) → "AARRGGBB" (LongRGBA = R,G,B,A @blob[4..7])
|
|
87
|
+
const argb = (blob: Uint8Array): string =>
|
|
88
|
+
`${HEX(blob[7])}${HEX(blob[4])}${HEX(blob[5])}${HEX(blob[6])}`;
|
|
89
|
+
let off = 6;
|
|
90
|
+
for (let k = 0; k < cprops && off + 4 <= p.length; k++) {
|
|
91
|
+
const type = p[off] | (p[off + 1] << 8);
|
|
92
|
+
const cb = p[off + 2] | (p[off + 3] << 8);
|
|
93
|
+
if (cb < 4) break;
|
|
94
|
+
const blob = p.subarray(off + 4, off + cb);
|
|
95
|
+
if (type === 0x02 && blob.length >= 8) dxf.background = argb(blob);
|
|
96
|
+
else if (type === 0x05 && blob.length >= 8) dxf.fontColor = argb(blob);
|
|
97
|
+
else if (type === 0x19 && blob.length >= 2 && (blob[0] | (blob[1] << 8)) >= 700) {
|
|
98
|
+
dxf.fontWeight = "bold";
|
|
99
|
+
}
|
|
100
|
+
off += cb;
|
|
101
|
+
}
|
|
102
|
+
return dxf;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get(id: string): ExcelStyle {
|
|
106
|
+
const idx = parseInt(id, 10);
|
|
107
|
+
if (idx < 0 || idx >= this._cellXfNumFmtIds.length) return {};
|
|
108
|
+
return { numFmtId: this._cellXfNumFmtIds[idx].toString() };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getNumFmtCode(numFmtId: string): string | undefined {
|
|
112
|
+
return this._numFmts.get(parseInt(numFmtId, 10));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
add(style: ExcelStyle): string {
|
|
116
|
+
if (this._raw != null) throw new Error(READONLY_WRITE);
|
|
117
|
+
if (
|
|
118
|
+
style.background != null ||
|
|
119
|
+
style.border != null ||
|
|
120
|
+
style.font != null ||
|
|
121
|
+
style.horizontalAlign != null ||
|
|
122
|
+
style.verticalAlign != null
|
|
123
|
+
) {
|
|
124
|
+
throw new Error(STYLE_WRITE_LIMIT);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let numFmtId = 0;
|
|
128
|
+
if (style.numFmtCode != null) numFmtId = this._setNumFmtCode(style.numFmtCode);
|
|
129
|
+
else if (style.numFmtId != null) numFmtId = parseInt(style.numFmtId, 10);
|
|
130
|
+
|
|
131
|
+
const existing = this._cellXfNumFmtIds.indexOf(numFmtId);
|
|
132
|
+
if (existing >= 0) return existing.toString();
|
|
133
|
+
this._cellXfNumFmtIds.push(numFmtId);
|
|
134
|
+
return (this._cellXfNumFmtIds.length - 1).toString();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
addWithClone(_id: string, style: ExcelStyle): string {
|
|
138
|
+
// 현재 numberFormat 만 지원하므로 clone 은 numFmt 교체와 동일하다.
|
|
139
|
+
return this.add(style);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
addDxf(style: ExcelConditionalRuleStyle): string {
|
|
143
|
+
if (this._raw != null) throw new Error(READONLY_WRITE);
|
|
144
|
+
const key = JSON.stringify(style);
|
|
145
|
+
const idx = this._dxfs.findIndex((d) => JSON.stringify(d) === key);
|
|
146
|
+
if (idx >= 0) return idx.toString();
|
|
147
|
+
this._dxfs.push(style);
|
|
148
|
+
return (this._dxfs.length - 1).toString();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** @internal 테스트용 — 디코드된 dxf 목록. */
|
|
152
|
+
get dxfs(): ExcelConditionalRuleStyle[] {
|
|
153
|
+
return this._dxfs;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
setDefaultStyle(): void {
|
|
157
|
+
throw new Error(STYLE_WRITE_LIMIT);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private _setNumFmtCode(code: string): number {
|
|
161
|
+
for (const [id, c] of this._numFmts) {
|
|
162
|
+
if (c === code) return id;
|
|
163
|
+
}
|
|
164
|
+
// 사용자 정의 numFmt 는 180+ 부터.
|
|
165
|
+
let next = 180;
|
|
166
|
+
while (this._numFmts.has(next)) next++;
|
|
167
|
+
this._numFmts.set(next, code);
|
|
168
|
+
return next;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
serialize(): Bytes {
|
|
172
|
+
if (this._raw != null) return this._raw;
|
|
173
|
+
|
|
174
|
+
const parts: Uint8Array[] = [encodeMarker(REC.BrtBeginStyleSheet)];
|
|
175
|
+
|
|
176
|
+
if (this._numFmts.size > 0) {
|
|
177
|
+
parts.push(encodeBeginCount(REC.BrtBeginFmts, this._numFmts.size));
|
|
178
|
+
for (const [id, code] of this._numFmts) parts.push(encodeBrtFmt(id, code));
|
|
179
|
+
parts.push(encodeMarker(REC.BrtEndFmts));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
parts.push(
|
|
183
|
+
encodeBeginCount(REC.BrtBeginFonts, 1),
|
|
184
|
+
encodeRecord(REC.BrtFont, SLOT_FONT),
|
|
185
|
+
encodeMarker(REC.BrtEndFonts),
|
|
186
|
+
);
|
|
187
|
+
parts.push(
|
|
188
|
+
encodeBeginCount(REC.BrtBeginFills, 2),
|
|
189
|
+
encodeRecord(REC.BrtFill, SLOT_FILL_NONE),
|
|
190
|
+
encodeRecord(REC.BrtFill, SLOT_FILL_GRAY125),
|
|
191
|
+
encodeMarker(REC.BrtEndFills),
|
|
192
|
+
);
|
|
193
|
+
parts.push(
|
|
194
|
+
encodeBeginCount(REC.BrtBeginBorders, 1),
|
|
195
|
+
encodeRecord(REC.BrtBorder, SLOT_BORDER),
|
|
196
|
+
encodeMarker(REC.BrtEndBorders),
|
|
197
|
+
);
|
|
198
|
+
parts.push(
|
|
199
|
+
encodeBeginCount(REC.BrtBeginCellStyleXFs, 1),
|
|
200
|
+
encodeRecord(REC.BrtXF, SLOT_CELLSTYLEXF),
|
|
201
|
+
encodeMarker(REC.BrtEndCellStyleXFs),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
parts.push(encodeBeginCount(REC.BrtBeginCellXFs, this._cellXfNumFmtIds.length));
|
|
205
|
+
for (const numFmtId of this._cellXfNumFmtIds) parts.push(encodeCellXF(numFmtId));
|
|
206
|
+
parts.push(encodeMarker(REC.BrtEndCellXFs));
|
|
207
|
+
|
|
208
|
+
if (this._dxfs.length > 0) {
|
|
209
|
+
parts.push(encodeBeginCount(REC.BrtBeginDXFs, this._dxfs.length));
|
|
210
|
+
for (const d of this._dxfs) {
|
|
211
|
+
parts.push(encodeBrtDXF(d.background, d.fontColor, d.fontWeight === "bold"));
|
|
212
|
+
}
|
|
213
|
+
parts.push(encodeMarker(REC.BrtEndDXFs));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
parts.push(encodeMarker(REC.BrtEndStyleSheet));
|
|
217
|
+
return concatBytes(parts);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Bytes } from "@simplysm/core-common";
|
|
2
|
+
import type { IWorkbookModel } from "../models/i-workbook-model";
|
|
3
|
+
import { concatBytes, REC } from "./biff12-codec";
|
|
4
|
+
import {
|
|
5
|
+
encodeBrtBookView,
|
|
6
|
+
encodeBrtBundleSh,
|
|
7
|
+
encodeBrtFileVersion,
|
|
8
|
+
encodeBrtWbProp,
|
|
9
|
+
encodeMarker,
|
|
10
|
+
parseRelId,
|
|
11
|
+
readWorkbookSheets,
|
|
12
|
+
} from "./biff-records";
|
|
13
|
+
|
|
14
|
+
const WRITE_NOT_SUPPORTED = "xlsb 쓰기는 아직 지원되지 않습니다 (Stage 3 이후 예정).";
|
|
15
|
+
|
|
16
|
+
/** workbook.bin (BIFF12) 읽기 모델. 시트 목록·관계 ID 조회. */
|
|
17
|
+
export class BiffWorkbookModel implements IWorkbookModel {
|
|
18
|
+
private readonly _sheets: { name: string; relId: string }[];
|
|
19
|
+
|
|
20
|
+
constructor(bytes?: Bytes) {
|
|
21
|
+
this._sheets = bytes != null ? readWorkbookSheets(bytes) : [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get sheetNames(): string[] {
|
|
25
|
+
return this._sheets.map((s) => s.name);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get lastWsRelId(): number | undefined {
|
|
29
|
+
let max: number | undefined;
|
|
30
|
+
for (const s of this._sheets) {
|
|
31
|
+
const n = parseRelId(s.relId);
|
|
32
|
+
if (n != null && (max == null || n > max)) max = n;
|
|
33
|
+
}
|
|
34
|
+
return max;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getWsRelIdByName(name: string): number | undefined {
|
|
38
|
+
const s = this._sheets.find((x) => x.name === name);
|
|
39
|
+
return s != null ? parseRelId(s.relId) : undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getWsRelIdByIndex(index: number): number | undefined {
|
|
43
|
+
if (index < 0 || index >= this._sheets.length) return undefined;
|
|
44
|
+
return parseRelId(this._sheets[index].relId);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getWorksheetNameById(id: number): string | undefined {
|
|
48
|
+
const s = this._sheets.find((x) => parseRelId(x.relId) === id);
|
|
49
|
+
return s?.name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
addWorksheet(name: string): this {
|
|
53
|
+
const relId = (this.lastWsRelId ?? 0) + 1;
|
|
54
|
+
this._sheets.push({ name, relId: `rId${relId}` });
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setWorksheetNameById(): void {
|
|
59
|
+
throw new Error(WRITE_NOT_SUPPORTED);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
initializeView(): void {
|
|
63
|
+
// xlsb 는 별도 bookView 초기화가 필요 없다(기본 bookView 사용). no-op.
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
serialize(): Bytes {
|
|
67
|
+
const parts: Uint8Array[] = [
|
|
68
|
+
encodeMarker(REC.BrtBeginBook),
|
|
69
|
+
encodeBrtFileVersion(),
|
|
70
|
+
encodeBrtWbProp(),
|
|
71
|
+
encodeMarker(REC.BrtBeginBookViews),
|
|
72
|
+
encodeBrtBookView(),
|
|
73
|
+
encodeMarker(REC.BrtEndBookViews),
|
|
74
|
+
encodeMarker(REC.BrtBeginBundleShs),
|
|
75
|
+
];
|
|
76
|
+
for (let i = 0; i < this._sheets.length; i++) {
|
|
77
|
+
// iTabID 는 1-base 고유 탭 id (0 은 Excel 이 무효로 보고 복구한다).
|
|
78
|
+
parts.push(encodeBrtBundleSh(this._sheets[i].relId, this._sheets[i].name, i + 1));
|
|
79
|
+
}
|
|
80
|
+
parts.push(encodeMarker(REC.BrtEndBundleShs), encodeMarker(REC.BrtEndBook));
|
|
81
|
+
return concatBytes(parts);
|
|
82
|
+
}
|
|
83
|
+
}
|