@simplysm/excel 1.0.138 → 13.0.0-beta.2
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/.cache/typecheck-browser.tsbuildinfo +1 -0
- package/.cache/typecheck-node.tsbuildinfo +1 -0
- package/.cache/typecheck-tests-browser.tsbuildinfo +1 -0
- package/.cache/typecheck-tests-node.tsbuildinfo +1 -0
- package/README.md +491 -0
- package/dist/core-common/src/common.types.d.ts +74 -0
- package/dist/core-common/src/common.types.d.ts.map +1 -0
- package/dist/core-common/src/env.d.ts +6 -0
- package/dist/core-common/src/env.d.ts.map +1 -0
- package/dist/core-common/src/errors/argument-error.d.ts +25 -0
- package/dist/core-common/src/errors/argument-error.d.ts.map +1 -0
- package/dist/core-common/src/errors/not-implemented-error.d.ts +29 -0
- package/dist/core-common/src/errors/not-implemented-error.d.ts.map +1 -0
- package/dist/core-common/src/errors/sd-error.d.ts +27 -0
- package/dist/core-common/src/errors/sd-error.d.ts.map +1 -0
- package/dist/core-common/src/errors/timeout-error.d.ts +31 -0
- package/dist/core-common/src/errors/timeout-error.d.ts.map +1 -0
- package/dist/core-common/src/extensions/arr-ext.d.ts +15 -0
- package/dist/core-common/src/extensions/arr-ext.d.ts.map +1 -0
- package/dist/core-common/src/extensions/arr-ext.helpers.d.ts +19 -0
- package/dist/core-common/src/extensions/arr-ext.helpers.d.ts.map +1 -0
- package/dist/core-common/src/extensions/arr-ext.types.d.ts +215 -0
- package/dist/core-common/src/extensions/arr-ext.types.d.ts.map +1 -0
- package/dist/core-common/src/extensions/map-ext.d.ts +57 -0
- package/dist/core-common/src/extensions/map-ext.d.ts.map +1 -0
- package/dist/core-common/src/extensions/set-ext.d.ts +36 -0
- package/dist/core-common/src/extensions/set-ext.d.ts.map +1 -0
- package/dist/core-common/src/features/debounce-queue.d.ts +53 -0
- package/dist/core-common/src/features/debounce-queue.d.ts.map +1 -0
- package/dist/core-common/src/features/event-emitter.d.ts +66 -0
- package/dist/core-common/src/features/event-emitter.d.ts.map +1 -0
- package/dist/core-common/src/features/serial-queue.d.ts +47 -0
- package/dist/core-common/src/features/serial-queue.d.ts.map +1 -0
- package/dist/core-common/src/index.d.ts +32 -0
- package/dist/core-common/src/index.d.ts.map +1 -0
- package/dist/core-common/src/types/date-only.d.ts +152 -0
- package/dist/core-common/src/types/date-only.d.ts.map +1 -0
- package/dist/core-common/src/types/date-time.d.ts +96 -0
- package/dist/core-common/src/types/date-time.d.ts.map +1 -0
- package/dist/core-common/src/types/lazy-gc-map.d.ts +80 -0
- package/dist/core-common/src/types/lazy-gc-map.d.ts.map +1 -0
- package/dist/core-common/src/types/time.d.ts +68 -0
- package/dist/core-common/src/types/time.d.ts.map +1 -0
- package/dist/core-common/src/types/uuid.d.ts +35 -0
- package/dist/core-common/src/types/uuid.d.ts.map +1 -0
- package/dist/core-common/src/utils/bytes.d.ts +51 -0
- package/dist/core-common/src/utils/bytes.d.ts.map +1 -0
- package/dist/core-common/src/utils/date-format.d.ts +90 -0
- package/dist/core-common/src/utils/date-format.d.ts.map +1 -0
- package/dist/core-common/src/utils/json.d.ts +34 -0
- package/dist/core-common/src/utils/json.d.ts.map +1 -0
- package/dist/core-common/src/utils/num.d.ts +60 -0
- package/dist/core-common/src/utils/num.d.ts.map +1 -0
- package/dist/core-common/src/utils/obj.d.ts +258 -0
- package/dist/core-common/src/utils/obj.d.ts.map +1 -0
- package/dist/core-common/src/utils/path.d.ts +23 -0
- package/dist/core-common/src/utils/path.d.ts.map +1 -0
- package/dist/core-common/src/utils/primitive.d.ts +18 -0
- package/dist/core-common/src/utils/primitive.d.ts.map +1 -0
- package/dist/core-common/src/utils/str.d.ts +103 -0
- package/dist/core-common/src/utils/str.d.ts.map +1 -0
- package/dist/core-common/src/utils/template-strings.d.ts +84 -0
- package/dist/core-common/src/utils/template-strings.d.ts.map +1 -0
- package/dist/core-common/src/utils/transferable.d.ts +47 -0
- package/dist/core-common/src/utils/transferable.d.ts.map +1 -0
- package/dist/core-common/src/utils/wait.d.ts +19 -0
- package/dist/core-common/src/utils/wait.d.ts.map +1 -0
- package/dist/core-common/src/utils/xml.d.ts +36 -0
- package/dist/core-common/src/utils/xml.d.ts.map +1 -0
- package/dist/core-common/src/zip/sd-zip.d.ts +80 -0
- package/dist/core-common/src/zip/sd-zip.d.ts.map +1 -0
- package/dist/excel/src/excel-cell.d.ts +68 -0
- package/dist/excel/src/excel-cell.d.ts.map +1 -0
- package/dist/excel/src/excel-col.d.ts +19 -0
- package/dist/excel/src/excel-col.d.ts.map +1 -0
- package/dist/excel/src/excel-row.d.ts +17 -0
- package/dist/excel/src/excel-row.d.ts.map +1 -0
- package/dist/excel/src/excel-workbook.d.ts +66 -0
- package/dist/excel/src/excel-workbook.d.ts.map +1 -0
- package/dist/excel/src/excel-worksheet.d.ts +102 -0
- package/dist/excel/src/excel-worksheet.d.ts.map +1 -0
- package/dist/excel/src/excel-wrapper.d.ts +42 -0
- package/dist/excel/src/excel-wrapper.d.ts.map +1 -0
- package/dist/excel/src/index.d.ts +9 -0
- package/dist/excel/src/index.d.ts.map +1 -0
- package/dist/excel/src/types.d.ts +445 -0
- package/dist/excel/src/types.d.ts.map +1 -0
- package/dist/excel/src/utils/excel-utils.d.ts +50 -0
- package/dist/excel/src/utils/excel-utils.d.ts.map +1 -0
- package/dist/excel/src/utils/zip-cache.d.ts +23 -0
- package/dist/excel/src/utils/zip-cache.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-content-type.d.ts +12 -0
- package/dist/excel/src/xml/excel-xml-content-type.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-drawing.d.ts +26 -0
- package/dist/excel/src/xml/excel-xml-drawing.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-relationship.d.ts +18 -0
- package/dist/excel/src/xml/excel-xml-relationship.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-shared-string.d.ts +19 -0
- package/dist/excel/src/xml/excel-xml-shared-string.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-style.d.ts +31 -0
- package/dist/excel/src/xml/excel-xml-style.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-unknown.d.ts +11 -0
- package/dist/excel/src/xml/excel-xml-unknown.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-workbook.d.ts +22 -0
- package/dist/excel/src/xml/excel-xml-workbook.d.ts.map +1 -0
- package/dist/excel/src/xml/excel-xml-worksheet.d.ts +103 -0
- package/dist/excel/src/xml/excel-xml-worksheet.d.ts.map +1 -0
- package/dist/excel-cell.js +261 -0
- package/dist/excel-cell.js.map +7 -0
- package/dist/excel-col.js +36 -0
- package/dist/excel-col.js.map +7 -0
- package/dist/excel-row.js +31 -0
- package/dist/excel-row.js.map +7 -0
- package/dist/excel-workbook.js +137 -0
- package/dist/excel-workbook.js.map +7 -0
- package/dist/excel-worksheet.js +279 -0
- package/dist/excel-worksheet.js.map +7 -0
- package/dist/excel-wrapper.js +220 -0
- package/dist/excel-wrapper.js.map +7 -0
- package/dist/index.js +9 -15
- package/dist/index.js.map +7 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +7 -0
- package/dist/utils/excel-utils.js +162 -0
- package/dist/utils/excel-utils.js.map +7 -0
- package/dist/utils/zip-cache.js +74 -0
- package/dist/utils/zip-cache.js.map +7 -0
- package/dist/xml/excel-xml-content-type.js +57 -0
- package/dist/xml/excel-xml-content-type.js.map +7 -0
- package/dist/xml/excel-xml-drawing.js +77 -0
- package/dist/xml/excel-xml-drawing.js.map +7 -0
- package/dist/xml/excel-xml-relationship.js +72 -0
- package/dist/xml/excel-xml-relationship.js.map +7 -0
- package/dist/xml/excel-xml-shared-string.js +61 -0
- package/dist/xml/excel-xml-shared-string.js.map +7 -0
- package/dist/xml/excel-xml-style.js +313 -0
- package/dist/xml/excel-xml-style.js.map +7 -0
- package/dist/xml/excel-xml-unknown.js +11 -0
- package/dist/xml/excel-xml-unknown.js.map +7 -0
- package/dist/xml/excel-xml-workbook.js +94 -0
- package/dist/xml/excel-xml-workbook.js.map +7 -0
- package/dist/xml/excel-xml-worksheet.js +405 -0
- package/dist/xml/excel-xml-worksheet.js.map +7 -0
- package/package.json +13 -7
- package/src/excel-cell.ts +326 -0
- package/src/excel-col.ts +43 -0
- package/src/excel-row.ts +37 -0
- package/src/excel-workbook.ts +206 -0
- package/src/excel-worksheet.ts +380 -0
- package/src/excel-wrapper.ts +219 -0
- package/src/index.ts +13 -9
- package/src/types.ts +396 -0
- package/src/utils/excel-utils.ts +201 -0
- package/src/utils/zip-cache.ts +103 -0
- package/src/xml/excel-xml-content-type.ts +64 -0
- package/src/xml/excel-xml-drawing.ts +87 -0
- package/src/xml/excel-xml-relationship.ts +86 -0
- package/src/xml/excel-xml-shared-string.ts +80 -0
- package/src/xml/excel-xml-style.ts +393 -0
- package/src/xml/excel-xml-unknown.ts +11 -0
- package/src/xml/excel-xml-workbook.ts +112 -0
- package/src/xml/excel-xml-worksheet.ts +544 -0
- package/tests/excel-cell.spec.ts +407 -0
- package/tests/excel-col.spec.ts +112 -0
- package/tests/excel-row.spec.ts +71 -0
- package/tests/excel-workbook.spec.ts +166 -0
- package/tests/excel-worksheet.spec.ts +389 -0
- package/tests/excel-wrapper.spec.ts +275 -0
- package/tests/fixtures/logo.png +0 -0
- package/tests/image-insert.spec.ts +188 -0
- package/tests/utils/excel-utils.spec.ts +240 -0
- package/dist/ExcelCell.d.ts +0 -13
- package/dist/ExcelCell.js +0 -161
- package/dist/ExcelCell.js.map +0 -1
- package/dist/ExcelCellStyle.d.ts +0 -31
- package/dist/ExcelCellStyle.js +0 -312
- package/dist/ExcelCellStyle.js.map +0 -1
- package/dist/ExcelColumn.d.ts +0 -8
- package/dist/ExcelColumn.js +0 -49
- package/dist/ExcelColumn.js.map +0 -1
- package/dist/ExcelRow.d.ts +0 -7
- package/dist/ExcelRow.js +0 -21
- package/dist/ExcelRow.js.map +0 -1
- package/dist/ExcelWorkbook.d.ts +0 -24
- package/dist/ExcelWorkbook.js +0 -418
- package/dist/ExcelWorkbook.js.map +0 -1
- package/dist/ExcelWorksheet.d.ts +0 -14
- package/dist/ExcelWorksheet.js +0 -31
- package/dist/ExcelWorksheet.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/utils/ExcelUtils.d.ts +0 -14
- package/dist/utils/ExcelUtils.js +0 -66
- package/dist/utils/ExcelUtils.js.map +0 -1
- package/dist/utils/XmlConvert.d.ts +0 -4
- package/dist/utils/XmlConvert.js +0 -64
- package/dist/utils/XmlConvert.js.map +0 -1
- package/src/ExcelCell.ts +0 -163
- package/src/ExcelCellStyle.ts +0 -297
- package/src/ExcelColumn.ts +0 -46
- package/src/ExcelRow.ts +0 -17
- package/src/ExcelWorkbook.ts +0 -369
- package/src/ExcelWorksheet.ts +0 -27
- package/src/utils/ExcelUtils.ts +0 -68
- package/src/utils/XmlConvert.ts +0 -20
- package/tsconfig.build.json +0 -18
- package/tsconfig.json +0 -18
- package/tslint.json +0 -5
package/src/ExcelWorkbook.ts
DELETED
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
import {ExcelWorksheet} from "./ExcelWorksheet";
|
|
2
|
-
import * as JSZip from "jszip";
|
|
3
|
-
import {XmlConvert} from "./utils/XmlConvert";
|
|
4
|
-
|
|
5
|
-
export class ExcelWorkbook {
|
|
6
|
-
private readonly _worksheets: ExcelWorksheet[] = [];
|
|
7
|
-
private _zip!: JSZip;
|
|
8
|
-
private _relData: any;
|
|
9
|
-
private _wbData: any;
|
|
10
|
-
private _contentTypeData: any;
|
|
11
|
-
private _wbRelData: any;
|
|
12
|
-
public sstData: any;
|
|
13
|
-
public stylesData: any;
|
|
14
|
-
|
|
15
|
-
public static create(): ExcelWorkbook {
|
|
16
|
-
const wb = new ExcelWorkbook();
|
|
17
|
-
|
|
18
|
-
wb._zip = new JSZip();
|
|
19
|
-
|
|
20
|
-
// .rel
|
|
21
|
-
wb._relData = {
|
|
22
|
-
Relationships: {
|
|
23
|
-
$: {
|
|
24
|
-
xmlns: "http://schemas.openxmlformats.org/package/2006/relationships"
|
|
25
|
-
},
|
|
26
|
-
Relationship: [
|
|
27
|
-
{
|
|
28
|
-
$: {
|
|
29
|
-
Id: "rId1",
|
|
30
|
-
Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
|
|
31
|
-
Target: "xl/workbook.xml"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Workbook
|
|
39
|
-
wb._wbData = {
|
|
40
|
-
workbook: {
|
|
41
|
-
$: {
|
|
42
|
-
"xmlns": "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
|
|
43
|
-
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// ContentType
|
|
49
|
-
wb._contentTypeData = {
|
|
50
|
-
Types: {
|
|
51
|
-
$: {
|
|
52
|
-
xmlns: "http://schemas.openxmlformats.org/package/2006/content-types"
|
|
53
|
-
},
|
|
54
|
-
Default: [
|
|
55
|
-
{
|
|
56
|
-
$: {
|
|
57
|
-
Extension: "rels",
|
|
58
|
-
ContentType: "application/vnd.openxmlformats-package.relationships+xml"
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
$: {
|
|
63
|
-
Extension: "xml",
|
|
64
|
-
ContentType: "application/xml"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
Override: [
|
|
69
|
-
{
|
|
70
|
-
$: {
|
|
71
|
-
PartName: "/xl/workbook.xml",
|
|
72
|
-
ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
$: {
|
|
77
|
-
PartName: "/xl/sharedStrings.xml",
|
|
78
|
-
ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
$: {
|
|
83
|
-
PartName: "/xl/styles.xml",
|
|
84
|
-
ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// Workbook Rel
|
|
92
|
-
wb._wbRelData = {
|
|
93
|
-
Relationships: {
|
|
94
|
-
$: {
|
|
95
|
-
xmlns: "http://schemas.openxmlformats.org/package/2006/relationships"
|
|
96
|
-
},
|
|
97
|
-
Relationship: [
|
|
98
|
-
{
|
|
99
|
-
$: {
|
|
100
|
-
Id: "rId1",
|
|
101
|
-
Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
|
|
102
|
-
Target: "sharedStrings.xml"
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
$: {
|
|
107
|
-
Id: "rId2",
|
|
108
|
-
Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
|
|
109
|
-
Target: "styles.xml"
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// SharedStrings
|
|
117
|
-
wb.sstData = {
|
|
118
|
-
sst: {
|
|
119
|
-
$: {
|
|
120
|
-
xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// Styles
|
|
126
|
-
wb.stylesData = {
|
|
127
|
-
styleSheet: {
|
|
128
|
-
$: {
|
|
129
|
-
xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
|
130
|
-
},
|
|
131
|
-
fonts: [{
|
|
132
|
-
font: [{}]
|
|
133
|
-
}],
|
|
134
|
-
fills: [{
|
|
135
|
-
fill: [
|
|
136
|
-
{patternFill: [{$: {patternType: "none"}}]},
|
|
137
|
-
{patternFill: [{$: {patternType: "none"}}]}
|
|
138
|
-
]
|
|
139
|
-
}],
|
|
140
|
-
borders: [{
|
|
141
|
-
border: [{}]
|
|
142
|
-
}],
|
|
143
|
-
cellXfs: [{
|
|
144
|
-
xf: [{}]
|
|
145
|
-
}]
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
return wb;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
public static async loadAsync(buffer: Buffer): Promise<ExcelWorkbook>;
|
|
153
|
-
public static async loadAsync(file: File): Promise<ExcelWorkbook>;
|
|
154
|
-
public static async loadAsync(blob: Blob): Promise<ExcelWorkbook>;
|
|
155
|
-
public static async loadAsync(arg: Buffer | Blob | File): Promise<ExcelWorkbook> {
|
|
156
|
-
let buffer: Buffer | Blob;
|
|
157
|
-
if (arg instanceof File) {
|
|
158
|
-
buffer = await new Promise<Buffer>(resolve => {
|
|
159
|
-
const fileReader = new FileReader();
|
|
160
|
-
fileReader.onload = () => {
|
|
161
|
-
resolve(Buffer.from(fileReader.result as ArrayBuffer));
|
|
162
|
-
};
|
|
163
|
-
fileReader.readAsArrayBuffer(arg);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
buffer = arg;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const wb = new ExcelWorkbook();
|
|
171
|
-
|
|
172
|
-
const zip = await new JSZip().loadAsync(buffer);
|
|
173
|
-
wb._zip = zip;
|
|
174
|
-
|
|
175
|
-
// .rel
|
|
176
|
-
wb._relData = await XmlConvert.parseAsync(await zip.file("_rels/.rels").async("text"));
|
|
177
|
-
|
|
178
|
-
// Workbook
|
|
179
|
-
wb._wbData = await XmlConvert.parseAsync(await zip.file("xl/workbook.xml").async("text"));
|
|
180
|
-
|
|
181
|
-
// ContentType
|
|
182
|
-
wb._contentTypeData = await XmlConvert.parseAsync(await zip.file("[Content_Types].xml").async("text"));
|
|
183
|
-
|
|
184
|
-
// Workbook Rel
|
|
185
|
-
wb._wbRelData = await XmlConvert.parseAsync(await zip.file("xl/_rels/workbook.xml.rels").async("text"));
|
|
186
|
-
|
|
187
|
-
// Worksheets
|
|
188
|
-
const worksheets = wb._wbData.workbook.sheets[0].sheet.map((item: any) => ({
|
|
189
|
-
rid: item.$["r:id"],
|
|
190
|
-
name: item.$.name
|
|
191
|
-
}));
|
|
192
|
-
for (const item of worksheets) {
|
|
193
|
-
const r = wb._wbRelData.Relationships.Relationship.single((item1: any) => item1.$.Id === item.rid);
|
|
194
|
-
const sheetData = await XmlConvert.parseAsync(await zip.file(`xl/${r.$.Target}`).async("text"));
|
|
195
|
-
const id = Number(r.$.Target.match(/\/sheet(.*)\./)[1]);
|
|
196
|
-
wb._worksheets[id] = new ExcelWorksheet(wb, item.name, sheetData);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// SharedStrings
|
|
200
|
-
wb.sstData = await XmlConvert.parseAsync(await zip.file("xl/sharedStrings.xml").async("text"));
|
|
201
|
-
|
|
202
|
-
// Styles
|
|
203
|
-
wb.stylesData = await XmlConvert.parseAsync(await zip.file("xl/styles.xml").async("text"));
|
|
204
|
-
|
|
205
|
-
return wb;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
public getWorksheet(name: string): ExcelWorksheet {
|
|
209
|
-
const ws = this._worksheets.single(item => item.name === name);
|
|
210
|
-
if (!ws) {
|
|
211
|
-
throw new Error(`시트[${name}]가 존재하지 않습니다.`);
|
|
212
|
-
}
|
|
213
|
-
return ws;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
public createWorksheet(name: string): ExcelWorksheet {
|
|
217
|
-
// Workbook
|
|
218
|
-
this._wbData.workbook.sheets = this._wbData.workbook.sheets || [{}];
|
|
219
|
-
this._wbData.workbook.sheets[0].sheet = this._wbData.workbook.sheets[0].sheet || [];
|
|
220
|
-
const lastSheetId = this._wbData.workbook.sheets[0].sheet.max((item: any) => Number(item.$.sheetId)) || 0;
|
|
221
|
-
const newSheetId = lastSheetId + 1;
|
|
222
|
-
|
|
223
|
-
this._wbData.workbook.sheets[0].sheet.push({
|
|
224
|
-
$: {
|
|
225
|
-
"name": name,
|
|
226
|
-
"sheetId": newSheetId,
|
|
227
|
-
"r:id": `rId${newSheetId}`
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// ContentType
|
|
232
|
-
this._contentTypeData.Types.Override.push({
|
|
233
|
-
$: {
|
|
234
|
-
PartName: `/xl/worksheets/sheet${newSheetId}.xml`,
|
|
235
|
-
ContentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
// Workbook Rel
|
|
240
|
-
this._wbRelData.Relationships.Relationship = this._wbRelData.Relationships.Relationship || [];
|
|
241
|
-
const sheetRelationships = this._wbRelData.Relationships.Relationship.filter((item: any) => item.$.Type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet");
|
|
242
|
-
sheetRelationships.push({
|
|
243
|
-
$: {
|
|
244
|
-
Id: `rId${newSheetId}`,
|
|
245
|
-
Type: `http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet`,
|
|
246
|
-
Target: `worksheets/sheet${newSheetId}.xml`
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
const nonSheetRelationships = this._wbRelData.Relationships.Relationship.filter((item: any) => item.$.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet");
|
|
251
|
-
let cnt = newSheetId + 1;
|
|
252
|
-
for (const nonSheetRelationship of nonSheetRelationships) {
|
|
253
|
-
nonSheetRelationship.$.Id = "rId" + cnt;
|
|
254
|
-
cnt++;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
this._wbRelData.Relationships.Relationship = sheetRelationships.concat(nonSheetRelationships);
|
|
258
|
-
|
|
259
|
-
// Worksheets
|
|
260
|
-
const sheetData = {
|
|
261
|
-
worksheet: {
|
|
262
|
-
$: {
|
|
263
|
-
xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
|
264
|
-
},
|
|
265
|
-
cols: [],
|
|
266
|
-
sheetData: [{}]
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
this._worksheets[newSheetId] = new ExcelWorksheet(this, name, sheetData);
|
|
270
|
-
return this._worksheets[newSheetId];
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
public async downloadAsync(filename: string): Promise<void> {
|
|
274
|
-
// .rel
|
|
275
|
-
this._zip.file("_rels/.rels", XmlConvert.stringify(this._relData));
|
|
276
|
-
|
|
277
|
-
// Workbook
|
|
278
|
-
this._zip.file("xl/workbook.xml", XmlConvert.stringify(this._wbData));
|
|
279
|
-
|
|
280
|
-
// ContentType
|
|
281
|
-
this._zip.file("[Content_Types].xml", XmlConvert.stringify(this._contentTypeData));
|
|
282
|
-
|
|
283
|
-
// Workbook Rel
|
|
284
|
-
this._zip.file("xl/_rels/workbook.xml.rels", XmlConvert.stringify(this._wbRelData));
|
|
285
|
-
|
|
286
|
-
// Worksheets
|
|
287
|
-
for (const wsId of Object.keys(this._worksheets)) {
|
|
288
|
-
this._zip.file(`xl/worksheets/sheet${wsId}.xml`, XmlConvert.stringify(this._worksheets[wsId].sheetData));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// SharedStrings
|
|
292
|
-
this._zip.file("xl/sharedStrings.xml", XmlConvert.stringify(this.sstData));
|
|
293
|
-
|
|
294
|
-
// Styles
|
|
295
|
-
this._zip.file("xl/styles.xml", XmlConvert.stringify(this.stylesData));
|
|
296
|
-
|
|
297
|
-
const blob = await this._zip.generateAsync({type: "blob"});
|
|
298
|
-
const link = document.createElement("a");
|
|
299
|
-
link.href = window.URL.createObjectURL(blob);
|
|
300
|
-
link.download = filename;
|
|
301
|
-
link.click();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
public get json(): { [sheetName: string]: { [key: string]: any }[] } {
|
|
305
|
-
const result: { [sheetName: string]: { [key: string]: any }[] } = {};
|
|
306
|
-
|
|
307
|
-
for (const sheet of this._worksheets.filterExists()) {
|
|
308
|
-
const sheetData = [];
|
|
309
|
-
for (let r = 1; r < sheet.rowLength; r++) {
|
|
310
|
-
const data = {};
|
|
311
|
-
for (let c = 0; c < sheet.row(r).columnLength; c++) {
|
|
312
|
-
const header = sheet.cell(0, c).value;
|
|
313
|
-
if (header) {
|
|
314
|
-
data[header] = sheet.cell(r, c).value;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
sheetData.push(data);
|
|
318
|
-
}
|
|
319
|
-
result[sheet.name] = sheetData;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return result;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
public set json(data: { [sheetName: string]: { [key: string]: any }[] }) {
|
|
326
|
-
for (const sheetName of Object.keys(data)) {
|
|
327
|
-
let sheet = this._worksheets.single(item => item.name === sheetName);
|
|
328
|
-
if (!sheet) {
|
|
329
|
-
// new sheet
|
|
330
|
-
sheet = this.createWorksheet(sheetName);
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
// clear
|
|
334
|
-
for (let r = 0; r < sheet.rowLength; r++) {
|
|
335
|
-
for (let c = 0; c < sheet.row(r).columnLength; c++) {
|
|
336
|
-
sheet.cell(r, c).value = undefined;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const rowItems: any[] = data[sheetName];
|
|
342
|
-
// const headerColumnIndexMap = rowItems.mapMany(item => Object.keys(item)).distinct()
|
|
343
|
-
// .toMap(item => item, (item, index) => index);
|
|
344
|
-
const headerColumns = rowItems.mapMany(item => Object.keys(item).map((item1, i) => [item1, i] as [string, number]));
|
|
345
|
-
const headerColumnIndexMap = new Map<string, number>();
|
|
346
|
-
for (const headerColumn of headerColumns) {
|
|
347
|
-
headerColumnIndexMap.set(
|
|
348
|
-
headerColumn[0],
|
|
349
|
-
headerColumnIndexMap.has(headerColumn[0])
|
|
350
|
-
? Math.max(headerColumnIndexMap.get(headerColumn[0])!, headerColumn[1])
|
|
351
|
-
: headerColumn[1]
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
for (const colName of Array.from(headerColumnIndexMap.keys())) {
|
|
356
|
-
const c = headerColumnIndexMap.get(colName)!;
|
|
357
|
-
sheet.cell(0, c).value = colName;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
for (let r = 0; r < rowItems.length; r++) {
|
|
361
|
-
const rowItem = rowItems[r];
|
|
362
|
-
for (const colName of Object.keys(rowItem)) {
|
|
363
|
-
const c = headerColumnIndexMap.get(colName)!;
|
|
364
|
-
sheet.cell(r + 1, c).value = rowItem[colName];
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
package/src/ExcelWorksheet.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {ExcelWorkbook} from "./ExcelWorkbook";
|
|
2
|
-
import {ExcelCell} from "./ExcelCell";
|
|
3
|
-
import {ExcelColumn} from "./ExcelColumn";
|
|
4
|
-
import {ExcelRow} from "./ExcelRow";
|
|
5
|
-
|
|
6
|
-
export class ExcelWorksheet {
|
|
7
|
-
public constructor(public readonly workbook: ExcelWorkbook,
|
|
8
|
-
public readonly name: string,
|
|
9
|
-
public readonly sheetData: any) {
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public cell(row: number, col: number): ExcelCell {
|
|
13
|
-
return new ExcelCell(this, row, col);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public column(col: number): ExcelColumn {
|
|
17
|
-
return new ExcelColumn(this, col);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public row(row: number): ExcelRow {
|
|
21
|
-
return new ExcelRow(this, row);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public get rowLength(): number {
|
|
25
|
-
return this.sheetData.worksheet.sheetData[0].row.length;
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/utils/ExcelUtils.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {DateOnly, DateTime} from "@simplysm/common";
|
|
2
|
-
|
|
3
|
-
export class ExcelUtils {
|
|
4
|
-
public static getRangeAddress(fromRow: number, fromCol: number, toRow: number, toCol: number): string {
|
|
5
|
-
return `${this.getAddress(fromRow, fromCol)}:${this.getAddress(toRow, toCol)}`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
public static getAddress(row: number, col: number): string {
|
|
9
|
-
const rowStr = (row + 1).toString();
|
|
10
|
-
const colStr = this._getColAddress(col);
|
|
11
|
-
return `${colStr}${rowStr}`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public static getAddressRowCol(addr: string): { row: number; col: number } {
|
|
15
|
-
return {
|
|
16
|
-
row: Number(addr.match(/[0-9]*$/)![0]),
|
|
17
|
-
col: this._getAddressCol(addr.match(/^[a-zA-Z]*/)![0])
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public static getTimeNumber(date: DateTime | DateOnly): number {
|
|
22
|
-
const currDate = date.date;
|
|
23
|
-
currDate.setMinutes(currDate.getMinutes() - currDate.getTimezoneOffset());
|
|
24
|
-
|
|
25
|
-
const excelBaseDateNumberUtc = Date.UTC(1899, 11, 31);
|
|
26
|
-
const inputExcelDateNumberUtc = currDate.getTime() - excelBaseDateNumberUtc;
|
|
27
|
-
return inputExcelDateNumberUtc / (24 * 60 * 60 * 1000) + 1;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public static getDateOnly(excelTime: number): DateOnly {
|
|
31
|
-
const excelBaseDateNumberUtc = Date.UTC(1899, 11, 31);
|
|
32
|
-
const excelDateNumberUtc = (excelTime - 1) * 24 * 60 * 60 * 1000;
|
|
33
|
-
const dateNumberUtc = excelBaseDateNumberUtc + excelDateNumberUtc;
|
|
34
|
-
const date = new Date(dateNumberUtc);
|
|
35
|
-
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
|
|
36
|
-
return new DateOnly(date);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public static getDateTime(excelTime: number): DateTime {
|
|
40
|
-
const excelBaseDateNumberUtc = Date.UTC(1899, 11, 31);
|
|
41
|
-
const excelDateNumberUtc = (excelTime - 1) * 24 * 60 * 60 * 1000;
|
|
42
|
-
const dateNumberUtc = excelBaseDateNumberUtc + excelDateNumberUtc;
|
|
43
|
-
const date = new Date(dateNumberUtc);
|
|
44
|
-
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
|
|
45
|
-
return new DateTime(date);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private static _getColAddress(index: number): string {
|
|
49
|
-
let remained = index;
|
|
50
|
-
let result = String.fromCharCode(remained % 26 + 65);
|
|
51
|
-
remained = Math.floor(remained / 26);
|
|
52
|
-
while (remained !== 0) {
|
|
53
|
-
result = String.fromCharCode(remained % 26 + 64) + result;
|
|
54
|
-
remained = Math.floor(remained / 26);
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private static _getAddressCol(addr: string): number {
|
|
60
|
-
let result = 0;
|
|
61
|
-
const revAddr = Array.from(addr).reverse().join("");
|
|
62
|
-
for (let i = 0; i < revAddr.length; i++) {
|
|
63
|
-
const col = revAddr.charCodeAt(i) - 65;
|
|
64
|
-
result += col * Math.pow(26, i);
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/utils/XmlConvert.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as xml2js from "xml2js";
|
|
2
|
-
|
|
3
|
-
export class XmlConvert {
|
|
4
|
-
public static async parseAsync(str: string): Promise<any> {
|
|
5
|
-
return new Promise<any>((resolve, reject) => {
|
|
6
|
-
xml2js.parseString(str, (err, parsed) => {
|
|
7
|
-
if (err) {
|
|
8
|
-
reject(err);
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
resolve(parsed);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static stringify(obj: any): string {
|
|
17
|
-
const builder = new xml2js.Builder();
|
|
18
|
-
return builder.buildObject(obj);
|
|
19
|
-
}
|
|
20
|
-
}
|
package/tsconfig.build.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"lib": [
|
|
7
|
-
"es2015",
|
|
8
|
-
"dom"
|
|
9
|
-
],
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"baseUrl": ".",
|
|
12
|
-
"paths": {
|
|
13
|
-
"@simplysm/common": [
|
|
14
|
-
"../common"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"lib": [
|
|
7
|
-
"es2015",
|
|
8
|
-
"dom"
|
|
9
|
-
],
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"baseUrl": ".",
|
|
12
|
-
"paths": {
|
|
13
|
-
"@simplysm/common": [
|
|
14
|
-
"../common/src/index.ts"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|