@corbe30/fortune-excel 1.0.3
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/.github/workflows/main.yml +30 -0
- package/.github/workflows/publish.yml +30 -0
- package/.storybook/main.ts +18 -0
- package/.storybook/preview.ts +15 -0
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/HandleZip.d.ts +8 -0
- package/dist/HandleZip.js +37 -0
- package/dist/ICommon.d.ts +34 -0
- package/dist/ICommon.js +1 -0
- package/dist/ToExcel/ExcelBorder.d.ts +3 -0
- package/dist/ToExcel/ExcelBorder.js +1412 -0
- package/dist/ToExcel/ExcelConvert.d.ts +16 -0
- package/dist/ToExcel/ExcelConvert.js +92 -0
- package/dist/ToExcel/ExcelFile.d.ts +1 -0
- package/dist/ToExcel/ExcelFile.js +30 -0
- package/dist/ToExcel/ExcelImage.d.ts +2 -0
- package/dist/ToExcel/ExcelImage.js +64 -0
- package/dist/ToExcel/ExcelStyle.d.ts +3 -0
- package/dist/ToExcel/ExcelStyle.js +53 -0
- package/dist/ToFortuneSheet/FortuneBase.d.ts +133 -0
- package/dist/ToFortuneSheet/FortuneBase.js +28 -0
- package/dist/ToFortuneSheet/FortuneCell.d.ts +25 -0
- package/dist/ToFortuneSheet/FortuneCell.js +782 -0
- package/dist/ToFortuneSheet/FortuneFile.d.ts +50 -0
- package/dist/ToFortuneSheet/FortuneFile.js +432 -0
- package/dist/ToFortuneSheet/FortuneImage.d.ts +20 -0
- package/dist/ToFortuneSheet/FortuneImage.js +51 -0
- package/dist/ToFortuneSheet/FortuneSheet.d.ts +36 -0
- package/dist/ToFortuneSheet/FortuneSheet.js +581 -0
- package/dist/ToFortuneSheet/IFortune.d.ts +301 -0
- package/dist/ToFortuneSheet/IFortune.js +1 -0
- package/dist/ToFortuneSheet/ReadXml.d.ts +61 -0
- package/dist/ToFortuneSheet/ReadXml.js +337 -0
- package/dist/common/constant.d.ts +25 -0
- package/dist/common/constant.js +277 -0
- package/dist/common/emf.d.ts +3 -0
- package/dist/common/emf.js +1294 -0
- package/dist/common/method.d.ts +132 -0
- package/dist/common/method.js +1075 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +24 -0
- package/package.json +47 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { IuploadfileList } from "../ICommon.js";
|
|
2
|
+
import { FortuneFileBase } from "./FortuneBase.js";
|
|
3
|
+
export declare class FortuneFile {
|
|
4
|
+
private files;
|
|
5
|
+
private sheetNameList;
|
|
6
|
+
private readXml;
|
|
7
|
+
private fileName;
|
|
8
|
+
private styles;
|
|
9
|
+
private sharedStrings;
|
|
10
|
+
private calcChain;
|
|
11
|
+
private imageList;
|
|
12
|
+
private sheets?;
|
|
13
|
+
private info?;
|
|
14
|
+
constructor(files: IuploadfileList, fileName: string);
|
|
15
|
+
/**
|
|
16
|
+
* @return All sheet name of workbook
|
|
17
|
+
*/
|
|
18
|
+
private getSheetNameList;
|
|
19
|
+
/**
|
|
20
|
+
* @param sheetName WorkSheet'name
|
|
21
|
+
* @return sheet file name and path in zip
|
|
22
|
+
*/
|
|
23
|
+
private getSheetFileBysheetId;
|
|
24
|
+
/**
|
|
25
|
+
* @return workBook information
|
|
26
|
+
*/
|
|
27
|
+
getWorkBookInfo(): void;
|
|
28
|
+
/**
|
|
29
|
+
* @return All sheet , include whole information
|
|
30
|
+
*/
|
|
31
|
+
getSheetsFull(isInitialCell?: boolean): void;
|
|
32
|
+
private columnWidthSet;
|
|
33
|
+
private rowHeightSet;
|
|
34
|
+
private extendArray;
|
|
35
|
+
private imagePositionCaculation;
|
|
36
|
+
/**
|
|
37
|
+
* @return drawing file string
|
|
38
|
+
*/
|
|
39
|
+
private getDrawingFile;
|
|
40
|
+
private getDrawingRelsFile;
|
|
41
|
+
/**
|
|
42
|
+
* @return All sheet base information widthout cell and config
|
|
43
|
+
*/
|
|
44
|
+
getSheetsWithoutCell(): void;
|
|
45
|
+
/**
|
|
46
|
+
* @return FortuneSheet file json
|
|
47
|
+
*/
|
|
48
|
+
Parse(): void;
|
|
49
|
+
serialize(): FortuneFileBase;
|
|
50
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { FortuneSheet } from "./FortuneSheet.js";
|
|
13
|
+
import { workBookFile, coreFile, appFile, stylesFile, sharedStringsFile, numFmtDefault, theme1File, calcChainFile, workbookRels, numFmtDefaultMap, } from "../common/constant.js";
|
|
14
|
+
import { ReadXml } from "./ReadXml.js";
|
|
15
|
+
import { getXmlAttibute } from "../common/method.js";
|
|
16
|
+
import { FortuneFileBase, FortuneFileInfo, } from "./FortuneBase.js";
|
|
17
|
+
import { ImageList } from "./FortuneImage.js";
|
|
18
|
+
export class FortuneFile {
|
|
19
|
+
constructor(files, fileName) {
|
|
20
|
+
this.columnWidthSet = [];
|
|
21
|
+
this.rowHeightSet = [];
|
|
22
|
+
this.files = files;
|
|
23
|
+
this.fileName = fileName;
|
|
24
|
+
this.readXml = new ReadXml(files);
|
|
25
|
+
this.getSheetNameList();
|
|
26
|
+
this.sharedStrings = this.readXml.getElementsByTagName("sst/si", sharedStringsFile);
|
|
27
|
+
this.calcChain = this.readXml.getElementsByTagName("calcChain/c", calcChainFile);
|
|
28
|
+
this.styles = {};
|
|
29
|
+
this.styles["cellXfs"] = this.readXml.getElementsByTagName("cellXfs/xf", stylesFile);
|
|
30
|
+
this.styles["cellStyleXfs"] = this.readXml.getElementsByTagName("cellStyleXfs/xf", stylesFile);
|
|
31
|
+
this.styles["cellStyles"] = this.readXml.getElementsByTagName("cellStyles/cellStyle", stylesFile);
|
|
32
|
+
this.styles["fonts"] = this.readXml.getElementsByTagName("fonts/font", stylesFile);
|
|
33
|
+
this.styles["fills"] = this.readXml.getElementsByTagName("fills/fill", stylesFile);
|
|
34
|
+
this.styles["borders"] = this.readXml.getElementsByTagName("borders/border", stylesFile);
|
|
35
|
+
this.styles["clrScheme"] = this.readXml.getElementsByTagName("a:clrScheme/a:dk1|a:lt1|a:dk2|a:lt2|a:accent1|a:accent2|a:accent3|a:accent4|a:accent5|a:accent6|a:hlink|a:folHlink", theme1File);
|
|
36
|
+
this.styles["indexedColors"] = this.readXml.getElementsByTagName("colors/indexedColors/rgbColor", stylesFile);
|
|
37
|
+
this.styles["mruColors"] = this.readXml.getElementsByTagName("colors/mruColors/color", stylesFile);
|
|
38
|
+
this.imageList = new ImageList(files);
|
|
39
|
+
let numfmts = this.readXml.getElementsByTagName("numFmt/numFmt", stylesFile);
|
|
40
|
+
let numFmtDefaultC = JSON.parse(JSON.stringify(numFmtDefault));
|
|
41
|
+
for (let i = 0; i < numfmts.length; i++) {
|
|
42
|
+
let attrList = numfmts[i].attributeList;
|
|
43
|
+
let numfmtid = getXmlAttibute(attrList, "numFmtId", "49");
|
|
44
|
+
let formatcode = getXmlAttibute(attrList, "formatCode", "@");
|
|
45
|
+
// console.log(numfmtid, formatcode);
|
|
46
|
+
if (!(numfmtid in numFmtDefault)) {
|
|
47
|
+
numFmtDefaultC[numfmtid] = numFmtDefaultMap[formatcode] || formatcode;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// console.log(JSON.stringify(numFmtDefaultC), numfmts);
|
|
51
|
+
this.styles["numfmts"] = numFmtDefaultC;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @return All sheet name of workbook
|
|
55
|
+
*/
|
|
56
|
+
getSheetNameList() {
|
|
57
|
+
let workbookRelList = this.readXml.getElementsByTagName("Relationships/Relationship", workbookRels);
|
|
58
|
+
if (workbookRelList == null) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let regex = new RegExp("worksheets/[^/]*?.xml");
|
|
62
|
+
let sheetNames = {};
|
|
63
|
+
for (let i = 0; i < workbookRelList.length; i++) {
|
|
64
|
+
let rel = workbookRelList[i], attrList = rel.attributeList;
|
|
65
|
+
let id = attrList["Id"], target = attrList["Target"];
|
|
66
|
+
if (regex.test(target)) {
|
|
67
|
+
if (target.indexOf("/xl") === 0) {
|
|
68
|
+
sheetNames[id] = target.substr(1);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
sheetNames[id] = "xl/" + target;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
this.sheetNameList = sheetNames;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @param sheetName WorkSheet'name
|
|
79
|
+
* @return sheet file name and path in zip
|
|
80
|
+
*/
|
|
81
|
+
getSheetFileBysheetId(sheetId) {
|
|
82
|
+
// for(let i=0;i<this.sheetNameList.length;i++){
|
|
83
|
+
// let sheetFileName = this.sheetNameList[i];
|
|
84
|
+
// if(sheetFileName.indexOf("sheet"+sheetId)>-1){
|
|
85
|
+
// return sheetFileName;
|
|
86
|
+
// }
|
|
87
|
+
// }
|
|
88
|
+
return this.sheetNameList[sheetId];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @return workBook information
|
|
92
|
+
*/
|
|
93
|
+
getWorkBookInfo() {
|
|
94
|
+
let Company = this.readXml.getElementsByTagName("Company", appFile);
|
|
95
|
+
let AppVersion = this.readXml.getElementsByTagName("AppVersion", appFile);
|
|
96
|
+
let creator = this.readXml.getElementsByTagName("dc:creator", coreFile);
|
|
97
|
+
let lastModifiedBy = this.readXml.getElementsByTagName("cp:lastModifiedBy", coreFile);
|
|
98
|
+
let created = this.readXml.getElementsByTagName("dcterms:created", coreFile);
|
|
99
|
+
let modified = this.readXml.getElementsByTagName("dcterms:modified", coreFile);
|
|
100
|
+
this.info = new FortuneFileInfo();
|
|
101
|
+
this.info.name = this.fileName;
|
|
102
|
+
this.info.creator = creator.length > 0 ? creator[0].value : "";
|
|
103
|
+
this.info.lastmodifiedby =
|
|
104
|
+
lastModifiedBy.length > 0 ? lastModifiedBy[0].value : "";
|
|
105
|
+
this.info.createdTime = created.length > 0 ? created[0].value : "";
|
|
106
|
+
this.info.modifiedTime = modified.length > 0 ? modified[0].value : "";
|
|
107
|
+
this.info.company = Company.length > 0 ? Company[0].value : "";
|
|
108
|
+
this.info.appversion = AppVersion.length > 0 ? AppVersion[0].value : "";
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @return All sheet , include whole information
|
|
112
|
+
*/
|
|
113
|
+
getSheetsFull(isInitialCell = true) {
|
|
114
|
+
let sheets = this.readXml.getElementsByTagName("sheets/sheet", workBookFile);
|
|
115
|
+
let sheetList = {};
|
|
116
|
+
for (let key in sheets) {
|
|
117
|
+
let sheet = sheets[key];
|
|
118
|
+
sheetList[sheet.attributeList.name] = sheet.attributeList["sheetId"];
|
|
119
|
+
}
|
|
120
|
+
this.sheets = [];
|
|
121
|
+
let order = 0;
|
|
122
|
+
for (let key in sheets) {
|
|
123
|
+
let sheet = sheets[key];
|
|
124
|
+
let sheetName = sheet.attributeList.name;
|
|
125
|
+
let sheetId = sheet.attributeList["sheetId"];
|
|
126
|
+
let rid = sheet.attributeList["r:id"];
|
|
127
|
+
let sheetFile = this.getSheetFileBysheetId(rid);
|
|
128
|
+
let hide = sheet.attributeList.state === "hidden" ? 1 : 0;
|
|
129
|
+
let drawing = this.readXml.getElementsByTagName("worksheet/drawing", sheetFile), drawingFile, drawingRelsFile;
|
|
130
|
+
if (drawing != null && drawing.length > 0) {
|
|
131
|
+
let attrList = drawing[0].attributeList;
|
|
132
|
+
let rid = getXmlAttibute(attrList, "r:id", null);
|
|
133
|
+
if (rid != null) {
|
|
134
|
+
drawingFile = this.getDrawingFile(rid, sheetFile);
|
|
135
|
+
drawingRelsFile = this.getDrawingRelsFile(drawingFile);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (sheetFile != null) {
|
|
139
|
+
let sheet = new FortuneSheet(sheetName, sheetId, order, isInitialCell, {
|
|
140
|
+
sheetFile: sheetFile,
|
|
141
|
+
readXml: this.readXml,
|
|
142
|
+
sheetList: sheetList,
|
|
143
|
+
styles: this.styles,
|
|
144
|
+
sharedStrings: this.sharedStrings,
|
|
145
|
+
calcChain: this.calcChain,
|
|
146
|
+
imageList: this.imageList,
|
|
147
|
+
drawingFile: drawingFile,
|
|
148
|
+
drawingRelsFile: drawingRelsFile,
|
|
149
|
+
hide: hide,
|
|
150
|
+
});
|
|
151
|
+
this.columnWidthSet = [];
|
|
152
|
+
this.rowHeightSet = [];
|
|
153
|
+
this.imagePositionCaculation(sheet);
|
|
154
|
+
this.sheets.push(sheet);
|
|
155
|
+
order++;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
extendArray(index, sets, def, hidden, lens) {
|
|
160
|
+
if (index < sets.length) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let startIndex = sets.length, endIndex = index;
|
|
164
|
+
let allGap = 0;
|
|
165
|
+
if (startIndex > 0) {
|
|
166
|
+
allGap = sets[startIndex - 1];
|
|
167
|
+
}
|
|
168
|
+
// else{
|
|
169
|
+
// sets.push(0);
|
|
170
|
+
// }
|
|
171
|
+
for (let i = startIndex; i <= endIndex; i++) {
|
|
172
|
+
let gap = def, istring = i.toString();
|
|
173
|
+
if (istring in hidden) {
|
|
174
|
+
gap = 0;
|
|
175
|
+
}
|
|
176
|
+
else if (istring in lens) {
|
|
177
|
+
gap = lens[istring];
|
|
178
|
+
}
|
|
179
|
+
allGap += Math.round(gap + 1);
|
|
180
|
+
sets.push(allGap);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
imagePositionCaculation(sheet) {
|
|
184
|
+
let images = sheet.images, defaultColWidth = sheet.defaultColWidth, defaultRowHeight = sheet.defaultRowHeight;
|
|
185
|
+
let colhidden = {};
|
|
186
|
+
if (sheet.config.colhidden) {
|
|
187
|
+
colhidden = sheet.config.colhidden;
|
|
188
|
+
}
|
|
189
|
+
let columnlen = {};
|
|
190
|
+
if (sheet.config.columnlen) {
|
|
191
|
+
columnlen = sheet.config.columnlen;
|
|
192
|
+
}
|
|
193
|
+
let rowhidden = {};
|
|
194
|
+
if (sheet.config.rowhidden) {
|
|
195
|
+
rowhidden = sheet.config.rowhidden;
|
|
196
|
+
}
|
|
197
|
+
let rowlen = {};
|
|
198
|
+
if (sheet.config.rowlen) {
|
|
199
|
+
rowlen = sheet.config.rowlen;
|
|
200
|
+
}
|
|
201
|
+
for (let key in images) {
|
|
202
|
+
let imageObject = images[key]; //Image, fortuneImage
|
|
203
|
+
let fromCol = imageObject.fromCol;
|
|
204
|
+
let fromColOff = imageObject.fromColOff;
|
|
205
|
+
let fromRow = imageObject.fromRow;
|
|
206
|
+
let fromRowOff = imageObject.fromRowOff;
|
|
207
|
+
let toCol = imageObject.toCol;
|
|
208
|
+
let toColOff = imageObject.toColOff;
|
|
209
|
+
let toRow = imageObject.toRow;
|
|
210
|
+
let toRowOff = imageObject.toRowOff;
|
|
211
|
+
let x_n = 0, y_n = 0;
|
|
212
|
+
let cx_n = 0, cy_n = 0;
|
|
213
|
+
if (fromCol >= this.columnWidthSet.length) {
|
|
214
|
+
this.extendArray(fromCol, this.columnWidthSet, defaultColWidth, colhidden, columnlen);
|
|
215
|
+
}
|
|
216
|
+
if (fromCol == 0) {
|
|
217
|
+
x_n = 0;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
x_n = this.columnWidthSet[fromCol - 1];
|
|
221
|
+
}
|
|
222
|
+
x_n = x_n + fromColOff;
|
|
223
|
+
if (fromRow >= this.rowHeightSet.length) {
|
|
224
|
+
this.extendArray(fromRow, this.rowHeightSet, defaultRowHeight, rowhidden, rowlen);
|
|
225
|
+
}
|
|
226
|
+
if (fromRow == 0) {
|
|
227
|
+
y_n = 0;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
y_n = this.rowHeightSet[fromRow - 1];
|
|
231
|
+
}
|
|
232
|
+
y_n = y_n + fromRowOff;
|
|
233
|
+
if (toCol >= this.columnWidthSet.length) {
|
|
234
|
+
this.extendArray(toCol, this.columnWidthSet, defaultColWidth, colhidden, columnlen);
|
|
235
|
+
}
|
|
236
|
+
if (toCol == 0) {
|
|
237
|
+
cx_n = 0;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
cx_n = this.columnWidthSet[toCol - 1];
|
|
241
|
+
}
|
|
242
|
+
cx_n = cx_n + toColOff - x_n;
|
|
243
|
+
if (toRow >= this.rowHeightSet.length) {
|
|
244
|
+
this.extendArray(toRow, this.rowHeightSet, defaultRowHeight, rowhidden, rowlen);
|
|
245
|
+
}
|
|
246
|
+
if (toRow == 0) {
|
|
247
|
+
cy_n = 0;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
cy_n = this.rowHeightSet[toRow - 1];
|
|
251
|
+
}
|
|
252
|
+
cy_n = cy_n + toRowOff - y_n;
|
|
253
|
+
console.log(defaultColWidth, colhidden, columnlen);
|
|
254
|
+
console.log(fromCol, this.columnWidthSet[fromCol], fromColOff);
|
|
255
|
+
console.log(toCol, this.columnWidthSet[toCol], toColOff, JSON.stringify(this.columnWidthSet));
|
|
256
|
+
imageObject.originWidth = cx_n;
|
|
257
|
+
imageObject.originHeight = cy_n;
|
|
258
|
+
imageObject.crop.height = cy_n;
|
|
259
|
+
imageObject.crop.width = cx_n;
|
|
260
|
+
imageObject.default.height = cy_n;
|
|
261
|
+
imageObject.default.left = x_n;
|
|
262
|
+
imageObject.default.top = y_n;
|
|
263
|
+
imageObject.default.width = cx_n;
|
|
264
|
+
}
|
|
265
|
+
//console.log(this.columnWidthSet, this.rowHeightSet);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* @return drawing file string
|
|
269
|
+
*/
|
|
270
|
+
getDrawingFile(rid, sheetFile) {
|
|
271
|
+
let sheetRelsPath = "xl/worksheets/_rels/";
|
|
272
|
+
let sheetFileArr = sheetFile.split("/");
|
|
273
|
+
let sheetRelsName = sheetFileArr[sheetFileArr.length - 1];
|
|
274
|
+
let sheetRelsFile = sheetRelsPath + sheetRelsName + ".rels";
|
|
275
|
+
let drawing = this.readXml.getElementsByTagName("Relationships/Relationship", sheetRelsFile);
|
|
276
|
+
if (drawing.length > 0) {
|
|
277
|
+
for (let i = 0; i < drawing.length; i++) {
|
|
278
|
+
let relationship = drawing[i];
|
|
279
|
+
let attrList = relationship.attributeList;
|
|
280
|
+
let relationshipId = getXmlAttibute(attrList, "Id", null);
|
|
281
|
+
if (relationshipId == rid) {
|
|
282
|
+
let target = getXmlAttibute(attrList, "Target", null);
|
|
283
|
+
if (target != null) {
|
|
284
|
+
return target.replace(/\.\.\//g, "");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
getDrawingRelsFile(drawingFile) {
|
|
292
|
+
let drawingRelsPath = "xl/drawings/_rels/";
|
|
293
|
+
let drawingFileArr = drawingFile.split("/");
|
|
294
|
+
let drawingRelsName = drawingFileArr[drawingFileArr.length - 1];
|
|
295
|
+
let drawingRelsFile = drawingRelsPath + drawingRelsName + ".rels";
|
|
296
|
+
return drawingRelsFile;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* @return All sheet base information widthout cell and config
|
|
300
|
+
*/
|
|
301
|
+
getSheetsWithoutCell() {
|
|
302
|
+
this.getSheetsFull(false);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* @return FortuneSheet file json
|
|
306
|
+
*/
|
|
307
|
+
Parse() {
|
|
308
|
+
this.getWorkBookInfo();
|
|
309
|
+
this.getSheetsFull();
|
|
310
|
+
}
|
|
311
|
+
serialize() {
|
|
312
|
+
var _a;
|
|
313
|
+
const FortuneOutPutFile = new FortuneFileBase();
|
|
314
|
+
FortuneOutPutFile.info = this.info;
|
|
315
|
+
FortuneOutPutFile.sheets = [];
|
|
316
|
+
for (const sheet of this.sheets) {
|
|
317
|
+
const sheetout = {};
|
|
318
|
+
//let attrName = ["name","color","config","index","status","order","row","column","luckysheet_select_save","scrollLeft","scrollTop","zoomRatio","showGridLines","defaultColWidth","defaultRowHeight","celldata","chart","isPivotTable","pivotTable","luckysheet_conditionformat_save","freezen","calcChain"];
|
|
319
|
+
if (sheet.name != null) {
|
|
320
|
+
sheetout.name = sheet.name;
|
|
321
|
+
}
|
|
322
|
+
if (sheet.color != null) {
|
|
323
|
+
sheetout.color = sheet.color;
|
|
324
|
+
}
|
|
325
|
+
if (sheet.config != null) {
|
|
326
|
+
sheetout.config = sheet.config;
|
|
327
|
+
// if(sheetout.config._borderInfo!=null){
|
|
328
|
+
// delete sheetout.config._borderInfo;
|
|
329
|
+
// }
|
|
330
|
+
}
|
|
331
|
+
if (sheet.id != null) {
|
|
332
|
+
sheetout.id = sheet.id;
|
|
333
|
+
}
|
|
334
|
+
if (sheet.status != null) {
|
|
335
|
+
sheetout.status = sheet.status;
|
|
336
|
+
}
|
|
337
|
+
if (sheet.order != null) {
|
|
338
|
+
sheetout.order = sheet.order;
|
|
339
|
+
}
|
|
340
|
+
if (sheet.row != null) {
|
|
341
|
+
sheetout.row = sheet.row;
|
|
342
|
+
}
|
|
343
|
+
if (sheet.column != null) {
|
|
344
|
+
sheetout.column = sheet.column;
|
|
345
|
+
}
|
|
346
|
+
if (sheet.luckysheet_select_save != null) {
|
|
347
|
+
sheetout.luckysheet_select_save = sheet.luckysheet_select_save;
|
|
348
|
+
}
|
|
349
|
+
if (sheet.scrollLeft != null) {
|
|
350
|
+
sheetout.scrollLeft = sheet.scrollLeft;
|
|
351
|
+
}
|
|
352
|
+
if (sheet.scrollTop != null) {
|
|
353
|
+
sheetout.scrollTop = sheet.scrollTop;
|
|
354
|
+
}
|
|
355
|
+
if (sheet.zoomRatio != null) {
|
|
356
|
+
sheetout.zoomRatio = sheet.zoomRatio;
|
|
357
|
+
}
|
|
358
|
+
if (sheet.showGridLines != null) {
|
|
359
|
+
sheetout.showGridLines = sheet.showGridLines;
|
|
360
|
+
}
|
|
361
|
+
if (sheet.defaultColWidth != null) {
|
|
362
|
+
sheetout.defaultColWidth = sheet.defaultColWidth;
|
|
363
|
+
}
|
|
364
|
+
if (sheet.defaultRowHeight != null) {
|
|
365
|
+
sheetout.defaultRowHeight = sheet.defaultRowHeight;
|
|
366
|
+
}
|
|
367
|
+
// https://github.com/ruilisi/fortune-sheet/issues/299
|
|
368
|
+
const merges = new Map();
|
|
369
|
+
if ((_a = sheet.config) === null || _a === void 0 ? void 0 : _a.merge) {
|
|
370
|
+
for (const { r, c, rs, cs } of Object.values(sheet.config.merge)) {
|
|
371
|
+
merges.set(r + "_" + c, { r, c, rs, cs });
|
|
372
|
+
for (let i = r + 1; i < r + rs; i++)
|
|
373
|
+
for (let j = c + 1; j < c + cs; j++)
|
|
374
|
+
merges.set(i + "_" + j, { r, c });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (sheet.celldata != null) {
|
|
378
|
+
// Plain objects matter here
|
|
379
|
+
sheetout.celldata = [];
|
|
380
|
+
for (let { r, c, v } of sheet.celldata) {
|
|
381
|
+
if (typeof v === "object") {
|
|
382
|
+
const xv = __rest(v, []);
|
|
383
|
+
v = xv;
|
|
384
|
+
if (v.ct) {
|
|
385
|
+
const ct = __rest(v.ct, []);
|
|
386
|
+
v.ct = ct;
|
|
387
|
+
}
|
|
388
|
+
if (merges.has(r + "_" + c)) {
|
|
389
|
+
v.mc = merges.get(r + "_" + c);
|
|
390
|
+
if (v.mc.r !== r || v.mc.c !== c)
|
|
391
|
+
v = { mc: v.mc };
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
sheetout.celldata.push({ r, c, v });
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (sheet.chart != null) {
|
|
398
|
+
sheetout.chart = sheet.chart;
|
|
399
|
+
}
|
|
400
|
+
if (sheet.isPivotTable != null) {
|
|
401
|
+
sheetout.isPivotTable = sheet.isPivotTable;
|
|
402
|
+
}
|
|
403
|
+
if (sheet.pivotTable != null) {
|
|
404
|
+
sheetout.pivotTable = sheet.pivotTable;
|
|
405
|
+
}
|
|
406
|
+
if (sheet.luckysheet_conditionformat_save != null) {
|
|
407
|
+
sheetout.luckysheet_conditionformat_save =
|
|
408
|
+
sheet.luckysheet_conditionformat_save;
|
|
409
|
+
}
|
|
410
|
+
if (sheet.freezen != null) {
|
|
411
|
+
sheetout.freezen = sheet.freezen;
|
|
412
|
+
}
|
|
413
|
+
if (sheet.calcChain != null) {
|
|
414
|
+
sheetout.calcChain = sheet.calcChain;
|
|
415
|
+
}
|
|
416
|
+
if (sheet.images != null) {
|
|
417
|
+
sheetout.images = sheet.images;
|
|
418
|
+
}
|
|
419
|
+
if (sheet.dataVerification != null) {
|
|
420
|
+
sheetout.dataVerification = sheet.dataVerification;
|
|
421
|
+
}
|
|
422
|
+
if (sheet.hyperlink != null) {
|
|
423
|
+
sheetout.hyperlink = sheet.hyperlink;
|
|
424
|
+
}
|
|
425
|
+
if (sheet.hide != null) {
|
|
426
|
+
sheetout.hide = sheet.hide;
|
|
427
|
+
}
|
|
428
|
+
FortuneOutPutFile.sheets.push(sheetout);
|
|
429
|
+
}
|
|
430
|
+
return FortuneOutPutFile;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IuploadfileList } from "../ICommon.js";
|
|
2
|
+
import { FortuneImageBase } from "./FortuneBase.js";
|
|
3
|
+
export declare class ImageList {
|
|
4
|
+
private images;
|
|
5
|
+
constructor(files: IuploadfileList);
|
|
6
|
+
getImageByName(pathName: string): Image;
|
|
7
|
+
}
|
|
8
|
+
declare class Image extends FortuneImageBase {
|
|
9
|
+
fromCol: number;
|
|
10
|
+
fromColOff: number;
|
|
11
|
+
fromRow: number;
|
|
12
|
+
fromRowOff: number;
|
|
13
|
+
toCol: number;
|
|
14
|
+
toColOff: number;
|
|
15
|
+
toRow: number;
|
|
16
|
+
toRowOff: number;
|
|
17
|
+
constructor(pathName: string, base64: string);
|
|
18
|
+
setDefault(): void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FortuneImageBase } from "./FortuneBase.js";
|
|
2
|
+
import { FromEMF, ToContext2D } from "../common/emf.js";
|
|
3
|
+
export class ImageList {
|
|
4
|
+
constructor(files) {
|
|
5
|
+
if (files == null) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
this.images = {};
|
|
9
|
+
for (let fileKey in files) {
|
|
10
|
+
// let reg = new RegExp("xl/media/image1.png", "g");
|
|
11
|
+
if (fileKey.indexOf("xl/media/") > -1) {
|
|
12
|
+
let fileNameArr = fileKey.split(".");
|
|
13
|
+
let suffix = fileNameArr[fileNameArr.length - 1].toLowerCase();
|
|
14
|
+
if (suffix in
|
|
15
|
+
{ png: 1, jpeg: 1, jpg: 1, gif: 1, bmp: 1, tif: 1, webp: 1, emf: 1 }) {
|
|
16
|
+
if (suffix == "emf") {
|
|
17
|
+
var pNum = 0; // number of the page, that you want to render
|
|
18
|
+
var scale = 1; // the scale of the document
|
|
19
|
+
var wrt = new ToContext2D(pNum, scale);
|
|
20
|
+
var inp, out, stt;
|
|
21
|
+
FromEMF.K = [];
|
|
22
|
+
inp = FromEMF.C;
|
|
23
|
+
out = FromEMF.K;
|
|
24
|
+
stt = 4;
|
|
25
|
+
for (var p in inp)
|
|
26
|
+
out[inp[p]] = p.slice(stt);
|
|
27
|
+
FromEMF.Parse(files[fileKey], wrt);
|
|
28
|
+
this.images[fileKey] = wrt.canvas.toDataURL("image/png");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.images[fileKey] = files[fileKey];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getImageByName(pathName) {
|
|
38
|
+
if (pathName in this.images) {
|
|
39
|
+
let base64 = this.images[pathName];
|
|
40
|
+
return new Image(pathName, base64);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class Image extends FortuneImageBase {
|
|
46
|
+
constructor(pathName, base64) {
|
|
47
|
+
super();
|
|
48
|
+
this.src = base64;
|
|
49
|
+
}
|
|
50
|
+
setDefault() { }
|
|
51
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FortuneSheetBase } from "./FortuneBase.js";
|
|
2
|
+
export declare class FortuneSheet extends FortuneSheetBase {
|
|
3
|
+
private readXml;
|
|
4
|
+
private sheetFile;
|
|
5
|
+
private isInitialCell;
|
|
6
|
+
private styles;
|
|
7
|
+
private sharedStrings;
|
|
8
|
+
private mergeCells;
|
|
9
|
+
private calcChainEles;
|
|
10
|
+
private sheetList;
|
|
11
|
+
private imageList;
|
|
12
|
+
private formulaRefList;
|
|
13
|
+
constructor(sheetName: string, sheetId: string, sheetOrder: number, isInitialCell: boolean, allFileOption: any);
|
|
14
|
+
private getXdrValue;
|
|
15
|
+
private getBase64ByRid;
|
|
16
|
+
/**
|
|
17
|
+
* @desc This will convert cols/col to fortunesheet config of column'width
|
|
18
|
+
*/
|
|
19
|
+
private generateConfigColumnLenAndHidden;
|
|
20
|
+
/**
|
|
21
|
+
* @desc This will convert cols/col to fortunesheet config of column'width
|
|
22
|
+
*/
|
|
23
|
+
private generateConfigRowLenAndHiddenAddCell;
|
|
24
|
+
/**
|
|
25
|
+
* fortunesheet config of dataValidations
|
|
26
|
+
*
|
|
27
|
+
* @returns {IfortunesheetDataVerification} - dataValidations config
|
|
28
|
+
*/
|
|
29
|
+
private generateConfigDataValidations;
|
|
30
|
+
/**
|
|
31
|
+
* fortunesheet config of hyperlink
|
|
32
|
+
*
|
|
33
|
+
* @returns {IfortunesheetHyperlink} - hyperlink config
|
|
34
|
+
*/
|
|
35
|
+
private generateConfigHyperlinks;
|
|
36
|
+
}
|