@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,581 @@
|
|
|
1
|
+
import { FortuneSheetCelldata } from "./FortuneCell.js";
|
|
2
|
+
import { getXmlAttibute, getColumnWidthPixel, fromulaRef, getRowHeightPixel, getcellrange, generateRandomIndex, getPxByEMUs, getMultiSequenceToNum, getTransR1C1ToSequence, getPeelOffX14, getMultiFormulaValue, } from "../common/method.js";
|
|
3
|
+
import { COMMON_TYPE2, DATA_VERIFICATION_MAP, DATA_VERIFICATION_TYPE2_MAP, worksheetFilePath, } from "../common/constant.js";
|
|
4
|
+
import { getColor } from "./ReadXml.js";
|
|
5
|
+
import { FortuneSheetBase, FortuneConfig, FortunesheetCalcChain, FortuneSheetConfigMerge, } from "./FortuneBase.js";
|
|
6
|
+
import dayjs from "dayjs";
|
|
7
|
+
export class FortuneSheet extends FortuneSheetBase {
|
|
8
|
+
constructor(sheetName, sheetId, sheetOrder, isInitialCell = false, allFileOption) {
|
|
9
|
+
//Private
|
|
10
|
+
super();
|
|
11
|
+
this.isInitialCell = isInitialCell;
|
|
12
|
+
this.readXml = allFileOption.readXml;
|
|
13
|
+
this.sheetFile = allFileOption.sheetFile;
|
|
14
|
+
this.styles = allFileOption.styles;
|
|
15
|
+
this.sharedStrings = allFileOption.sharedStrings;
|
|
16
|
+
this.calcChainEles = allFileOption.calcChain;
|
|
17
|
+
this.sheetList = allFileOption.sheetList;
|
|
18
|
+
this.imageList = allFileOption.imageList;
|
|
19
|
+
this.hide = allFileOption.hide;
|
|
20
|
+
//Output
|
|
21
|
+
this.name = sheetName;
|
|
22
|
+
this.id = sheetId;
|
|
23
|
+
this.order = sheetOrder.toString();
|
|
24
|
+
this.config = new FortuneConfig();
|
|
25
|
+
this.celldata = [];
|
|
26
|
+
this.mergeCells = this.readXml.getElementsByTagName("mergeCells/mergeCell", this.sheetFile);
|
|
27
|
+
let clrScheme = this.styles["clrScheme"];
|
|
28
|
+
let sheetView = this.readXml.getElementsByTagName("sheetViews/sheetView", this.sheetFile);
|
|
29
|
+
let showGridLines = "1", tabSelected = "0", zoomScale = "100", activeCell = "A1";
|
|
30
|
+
if (sheetView.length > 0) {
|
|
31
|
+
let attrList = sheetView[0].attributeList;
|
|
32
|
+
showGridLines = getXmlAttibute(attrList, "showGridLines", "1");
|
|
33
|
+
tabSelected = getXmlAttibute(attrList, "tabSelected", "0");
|
|
34
|
+
zoomScale = getXmlAttibute(attrList, "zoomScale", "100");
|
|
35
|
+
// let colorId = getXmlAttibute(attrList, "colorId", "0");
|
|
36
|
+
let selections = sheetView[0].getInnerElements("selection");
|
|
37
|
+
if (selections != null && selections.length > 0) {
|
|
38
|
+
activeCell = getXmlAttibute(selections[0].attributeList, "activeCell", "A1");
|
|
39
|
+
let range = getcellrange(activeCell, this.sheetList, sheetId);
|
|
40
|
+
this.luckysheet_select_save = [];
|
|
41
|
+
this.luckysheet_select_save.push(range);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.showGridLines = showGridLines;
|
|
45
|
+
this.status = tabSelected;
|
|
46
|
+
this.zoomRatio = parseInt(zoomScale) / 100;
|
|
47
|
+
let tabColors = this.readXml.getElementsByTagName("sheetPr/tabColor", this.sheetFile);
|
|
48
|
+
if (tabColors != null && tabColors.length > 0) {
|
|
49
|
+
let tabColor = tabColors[0], attrList = tabColor.attributeList;
|
|
50
|
+
// if(attrList.rgb!=null){
|
|
51
|
+
let tc = getColor(tabColor, this.styles, "b");
|
|
52
|
+
this.color = tc;
|
|
53
|
+
// }
|
|
54
|
+
}
|
|
55
|
+
let sheetFormatPr = this.readXml.getElementsByTagName("sheetFormatPr", this.sheetFile);
|
|
56
|
+
let defaultColWidth, defaultRowHeight;
|
|
57
|
+
if (sheetFormatPr.length > 0) {
|
|
58
|
+
let attrList = sheetFormatPr[0].attributeList;
|
|
59
|
+
defaultColWidth = getXmlAttibute(attrList, "defaultColWidth", "9.21");
|
|
60
|
+
defaultRowHeight = getXmlAttibute(attrList, "defaultRowHeight", "19");
|
|
61
|
+
}
|
|
62
|
+
this.defaultColWidth = getColumnWidthPixel(parseFloat(defaultColWidth));
|
|
63
|
+
this.defaultRowHeight = getRowHeightPixel(parseFloat(defaultRowHeight));
|
|
64
|
+
this.generateConfigColumnLenAndHidden();
|
|
65
|
+
let cellOtherInfo = this.generateConfigRowLenAndHiddenAddCell();
|
|
66
|
+
if (this.calcChain == null) {
|
|
67
|
+
this.calcChain = [];
|
|
68
|
+
}
|
|
69
|
+
let formulaListExist = {};
|
|
70
|
+
for (let c = 0; c < this.calcChainEles.length; c++) {
|
|
71
|
+
let calcChainEle = this.calcChainEles[c], attrList = calcChainEle.attributeList;
|
|
72
|
+
if (attrList.i != sheetId) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
let r = attrList.r, i = attrList.i, l = attrList.l, s = attrList.s, a = attrList.a, t = attrList.t;
|
|
76
|
+
let range = getcellrange(r);
|
|
77
|
+
let chain = new FortunesheetCalcChain();
|
|
78
|
+
chain.r = range.row[0];
|
|
79
|
+
chain.c = range.column[0];
|
|
80
|
+
chain.id = this.id;
|
|
81
|
+
this.calcChain.push(chain);
|
|
82
|
+
formulaListExist["r" + r + "c" + c] = null;
|
|
83
|
+
}
|
|
84
|
+
if (this.formulaRefList != null) {
|
|
85
|
+
for (let key in this.formulaRefList) {
|
|
86
|
+
let funclist = this.formulaRefList[key];
|
|
87
|
+
let mainFunc = funclist["mainRef"], mainCellValue = mainFunc.cellValue;
|
|
88
|
+
let formulaTxt = mainFunc.fv;
|
|
89
|
+
let mainR = mainCellValue.r, mainC = mainCellValue.c;
|
|
90
|
+
// let refRange = getcellrange(ref);
|
|
91
|
+
for (let name in funclist) {
|
|
92
|
+
if (name == "mainRef") {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
let funcValue = funclist[name], cellValue = funcValue.cellValue;
|
|
96
|
+
if (cellValue == null) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
let r = cellValue.r, c = cellValue.c;
|
|
100
|
+
let func = formulaTxt;
|
|
101
|
+
let offsetRow = r - mainR, offsetCol = c - mainC;
|
|
102
|
+
if (offsetRow > 0) {
|
|
103
|
+
func = "=" + fromulaRef.functionCopy(func, "down", offsetRow);
|
|
104
|
+
}
|
|
105
|
+
else if (offsetRow < 0) {
|
|
106
|
+
func =
|
|
107
|
+
"=" + fromulaRef.functionCopy(func, "up", Math.abs(offsetRow));
|
|
108
|
+
}
|
|
109
|
+
if (offsetCol > 0) {
|
|
110
|
+
func = "=" + fromulaRef.functionCopy(func, "right", offsetCol);
|
|
111
|
+
}
|
|
112
|
+
else if (offsetCol < 0) {
|
|
113
|
+
func =
|
|
114
|
+
"=" + fromulaRef.functionCopy(func, "left", Math.abs(offsetCol));
|
|
115
|
+
}
|
|
116
|
+
// console.log(offsetRow, offsetCol, func);
|
|
117
|
+
cellValue.v.f = func;
|
|
118
|
+
//添加共享公式链
|
|
119
|
+
let chain = new FortunesheetCalcChain();
|
|
120
|
+
chain.r = cellValue.r;
|
|
121
|
+
chain.c = cellValue.c;
|
|
122
|
+
chain.id = this.id;
|
|
123
|
+
this.calcChain.push(chain);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//There may be formulas that do not appear in calcChain
|
|
128
|
+
for (let key in cellOtherInfo.formulaList) {
|
|
129
|
+
if (!(key in formulaListExist)) {
|
|
130
|
+
let formulaListItem = cellOtherInfo.formulaList[key];
|
|
131
|
+
let chain = new FortunesheetCalcChain();
|
|
132
|
+
chain.r = formulaListItem.r;
|
|
133
|
+
chain.c = formulaListItem.c;
|
|
134
|
+
chain.id = this.id;
|
|
135
|
+
this.calcChain.push(chain);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// dataVerification config
|
|
139
|
+
this.dataVerification = this.generateConfigDataValidations();
|
|
140
|
+
// hyperlink config
|
|
141
|
+
this.hyperlink = this.generateConfigHyperlinks();
|
|
142
|
+
// sheet hide
|
|
143
|
+
this.hide = this.hide;
|
|
144
|
+
if (this.mergeCells != null) {
|
|
145
|
+
for (let i = 0; i < this.mergeCells.length; i++) {
|
|
146
|
+
let merge = this.mergeCells[i], attrList = merge.attributeList;
|
|
147
|
+
let ref = attrList.ref;
|
|
148
|
+
if (ref == null) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
let range = getcellrange(ref, this.sheetList, sheetId);
|
|
152
|
+
let mergeValue = new FortuneSheetConfigMerge();
|
|
153
|
+
mergeValue.r = range.row[0];
|
|
154
|
+
mergeValue.c = range.column[0];
|
|
155
|
+
mergeValue.rs = range.row[1] - range.row[0] + 1;
|
|
156
|
+
mergeValue.cs = range.column[1] - range.column[0] + 1;
|
|
157
|
+
if (this.config.merge == null) {
|
|
158
|
+
this.config.merge = {};
|
|
159
|
+
}
|
|
160
|
+
this.config.merge[range.row[0] + "_" + range.column[0]] = mergeValue;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let drawingFile = allFileOption.drawingFile, drawingRelsFile = allFileOption.drawingRelsFile;
|
|
164
|
+
if (drawingFile != null && drawingRelsFile != null) {
|
|
165
|
+
let twoCellAnchors = this.readXml.getElementsByTagName("xdr:twoCellAnchor", drawingFile);
|
|
166
|
+
if (twoCellAnchors != null && twoCellAnchors.length > 0) {
|
|
167
|
+
for (let i = 0; i < twoCellAnchors.length; i++) {
|
|
168
|
+
let twoCellAnchor = twoCellAnchors[i];
|
|
169
|
+
let editAs = getXmlAttibute(twoCellAnchor.attributeList, "editAs", "twoCell");
|
|
170
|
+
let xdrFroms = twoCellAnchor.getInnerElements("xdr:from"), xdrTos = twoCellAnchor.getInnerElements("xdr:to");
|
|
171
|
+
let xdr_blipfills = twoCellAnchor.getInnerElements("a:blip");
|
|
172
|
+
if (xdrFroms != null &&
|
|
173
|
+
xdr_blipfills != null &&
|
|
174
|
+
xdrFroms.length > 0 &&
|
|
175
|
+
xdr_blipfills.length > 0) {
|
|
176
|
+
let xdrFrom = xdrFroms[0], xdrTo = xdrTos[0], xdr_blipfill = xdr_blipfills[0];
|
|
177
|
+
let rembed = getXmlAttibute(xdr_blipfill.attributeList, "r:embed", null);
|
|
178
|
+
let imageObject = this.getBase64ByRid(rembed, drawingRelsFile);
|
|
179
|
+
// let aoff = xdr_xfrm.getInnerElements("a:off"), aext = xdr_xfrm.getInnerElements("a:ext");
|
|
180
|
+
// if(aoff!=null && aext!=null && aoff.length>0 && aext.length>0){
|
|
181
|
+
// let aoffAttribute = aoff[0].attributeList, aextAttribute = aext[0].attributeList;
|
|
182
|
+
// let x = getXmlAttibute(aoffAttribute, "x", null);
|
|
183
|
+
// let y = getXmlAttibute(aoffAttribute, "y", null);
|
|
184
|
+
// let cx = getXmlAttibute(aextAttribute, "cx", null);
|
|
185
|
+
// let cy = getXmlAttibute(aextAttribute, "cy", null);
|
|
186
|
+
// if(x!=null && y!=null && cx!=null && cy!=null && imageObject !=null){
|
|
187
|
+
// let x_n = getPxByEMUs(parseInt(x), "c"),y_n = getPxByEMUs(parseInt(y));
|
|
188
|
+
// let cx_n = getPxByEMUs(parseInt(cx), "c"),cy_n = getPxByEMUs(parseInt(cy));
|
|
189
|
+
let x_n = 0, y_n = 0;
|
|
190
|
+
let cx_n = 0, cy_n = 0;
|
|
191
|
+
imageObject.fromCol = this.getXdrValue(xdrFrom.getInnerElements("xdr:col"));
|
|
192
|
+
imageObject.fromColOff = getPxByEMUs(this.getXdrValue(xdrFrom.getInnerElements("xdr:colOff")));
|
|
193
|
+
imageObject.fromRow = this.getXdrValue(xdrFrom.getInnerElements("xdr:row"));
|
|
194
|
+
imageObject.fromRowOff = getPxByEMUs(this.getXdrValue(xdrFrom.getInnerElements("xdr:rowOff")));
|
|
195
|
+
imageObject.toCol = this.getXdrValue(xdrTo.getInnerElements("xdr:col"));
|
|
196
|
+
imageObject.toColOff = getPxByEMUs(this.getXdrValue(xdrTo.getInnerElements("xdr:colOff")));
|
|
197
|
+
imageObject.toRow = this.getXdrValue(xdrTo.getInnerElements("xdr:row"));
|
|
198
|
+
imageObject.toRowOff = getPxByEMUs(this.getXdrValue(xdrTo.getInnerElements("xdr:rowOff")));
|
|
199
|
+
imageObject.originWidth = cx_n;
|
|
200
|
+
imageObject.originHeight = cy_n;
|
|
201
|
+
if (editAs == "absolute") {
|
|
202
|
+
imageObject.type = "3";
|
|
203
|
+
}
|
|
204
|
+
else if (editAs == "oneCell") {
|
|
205
|
+
imageObject.type = "2";
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
imageObject.type = "1";
|
|
209
|
+
}
|
|
210
|
+
imageObject.isFixedPos = false;
|
|
211
|
+
imageObject.fixedLeft = 0;
|
|
212
|
+
imageObject.fixedTop = 0;
|
|
213
|
+
let imageBorder = {
|
|
214
|
+
color: "#000",
|
|
215
|
+
radius: 0,
|
|
216
|
+
style: "solid",
|
|
217
|
+
width: 0,
|
|
218
|
+
};
|
|
219
|
+
imageObject.border = imageBorder;
|
|
220
|
+
let imageCrop = {
|
|
221
|
+
height: cy_n,
|
|
222
|
+
offsetLeft: 0,
|
|
223
|
+
offsetTop: 0,
|
|
224
|
+
width: cx_n,
|
|
225
|
+
};
|
|
226
|
+
imageObject.crop = imageCrop;
|
|
227
|
+
let imageDefault = {
|
|
228
|
+
height: cy_n,
|
|
229
|
+
left: x_n,
|
|
230
|
+
top: y_n,
|
|
231
|
+
width: cx_n,
|
|
232
|
+
};
|
|
233
|
+
imageObject.default = imageDefault;
|
|
234
|
+
if (this.images == null) {
|
|
235
|
+
this.images = {};
|
|
236
|
+
}
|
|
237
|
+
this.images[generateRandomIndex("image")] = imageObject;
|
|
238
|
+
// }
|
|
239
|
+
// }
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
getXdrValue(ele) {
|
|
246
|
+
if (ele == null || ele.length == 0) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
return parseInt(ele[0].value);
|
|
250
|
+
}
|
|
251
|
+
getBase64ByRid(rid, drawingRelsFile) {
|
|
252
|
+
let Relationships = this.readXml.getElementsByTagName("Relationships/Relationship", drawingRelsFile);
|
|
253
|
+
if (Relationships != null && Relationships.length > 0) {
|
|
254
|
+
for (let i = 0; i < Relationships.length; i++) {
|
|
255
|
+
let Relationship = Relationships[i];
|
|
256
|
+
let attrList = Relationship.attributeList;
|
|
257
|
+
let Id = getXmlAttibute(attrList, "Id", null);
|
|
258
|
+
let src = getXmlAttibute(attrList, "Target", null);
|
|
259
|
+
if (Id == rid) {
|
|
260
|
+
src = src.replace(/\.\.\//g, "");
|
|
261
|
+
src = "xl/" + src;
|
|
262
|
+
let imgage = this.imageList.getImageByName(src);
|
|
263
|
+
return imgage;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @desc This will convert cols/col to fortunesheet config of column'width
|
|
271
|
+
*/
|
|
272
|
+
generateConfigColumnLenAndHidden() {
|
|
273
|
+
let cols = this.readXml.getElementsByTagName("cols/col", this.sheetFile);
|
|
274
|
+
for (let i = 0; i < cols.length; i++) {
|
|
275
|
+
let col = cols[i], attrList = col.attributeList;
|
|
276
|
+
let min = getXmlAttibute(attrList, "min", null);
|
|
277
|
+
let max = getXmlAttibute(attrList, "max", null);
|
|
278
|
+
let width = getXmlAttibute(attrList, "width", null);
|
|
279
|
+
let hidden = getXmlAttibute(attrList, "hidden", null);
|
|
280
|
+
let customWidth = getXmlAttibute(attrList, "customWidth", null);
|
|
281
|
+
if (min == null || max == null) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
let minNum = parseInt(min) - 1, maxNum = parseInt(max) - 1, widthNum = parseFloat(width);
|
|
285
|
+
for (let m = minNum; m <= maxNum; m++) {
|
|
286
|
+
if (width != null) {
|
|
287
|
+
if (this.config.columnlen == null) {
|
|
288
|
+
this.config.columnlen = {};
|
|
289
|
+
}
|
|
290
|
+
this.config.columnlen[m] = getColumnWidthPixel(widthNum);
|
|
291
|
+
}
|
|
292
|
+
if (hidden == "1") {
|
|
293
|
+
if (this.config.colhidden == null) {
|
|
294
|
+
this.config.colhidden = {};
|
|
295
|
+
}
|
|
296
|
+
this.config.colhidden[m] = 0;
|
|
297
|
+
if (this.config.columnlen) {
|
|
298
|
+
delete this.config.columnlen[m];
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (customWidth != null) {
|
|
302
|
+
if (this.config.customWidth == null) {
|
|
303
|
+
this.config.customWidth = {};
|
|
304
|
+
}
|
|
305
|
+
this.config.customWidth[m] = 1;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* @desc This will convert cols/col to fortunesheet config of column'width
|
|
312
|
+
*/
|
|
313
|
+
generateConfigRowLenAndHiddenAddCell() {
|
|
314
|
+
let rows = this.readXml.getElementsByTagName("sheetData/row", this.sheetFile);
|
|
315
|
+
let cellOtherInfo = {};
|
|
316
|
+
let formulaList = {};
|
|
317
|
+
cellOtherInfo.formulaList = formulaList;
|
|
318
|
+
for (let i = 0; i < rows.length; i++) {
|
|
319
|
+
let row = rows[i], attrList = row.attributeList;
|
|
320
|
+
let rowNo = getXmlAttibute(attrList, "r", null);
|
|
321
|
+
let height = getXmlAttibute(attrList, "ht", null);
|
|
322
|
+
let hidden = getXmlAttibute(attrList, "hidden", null);
|
|
323
|
+
let customHeight = getXmlAttibute(attrList, "customHeight", null);
|
|
324
|
+
if (rowNo == null) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
let rowNoNum = parseInt(rowNo) - 1;
|
|
328
|
+
if (height != null) {
|
|
329
|
+
let heightNum = parseFloat(height);
|
|
330
|
+
if (this.config.rowlen == null) {
|
|
331
|
+
this.config.rowlen = {};
|
|
332
|
+
}
|
|
333
|
+
this.config.rowlen[rowNoNum] = getRowHeightPixel(heightNum);
|
|
334
|
+
}
|
|
335
|
+
if (hidden == "1") {
|
|
336
|
+
if (this.config.rowhidden == null) {
|
|
337
|
+
this.config.rowhidden = {};
|
|
338
|
+
}
|
|
339
|
+
this.config.rowhidden[rowNoNum] = 0;
|
|
340
|
+
if (this.config.rowlen) {
|
|
341
|
+
delete this.config.rowlen[rowNoNum];
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (customHeight != null) {
|
|
345
|
+
if (this.config.customHeight == null) {
|
|
346
|
+
this.config.customHeight = {};
|
|
347
|
+
}
|
|
348
|
+
this.config.customHeight[rowNoNum] = 1;
|
|
349
|
+
}
|
|
350
|
+
if (this.isInitialCell) {
|
|
351
|
+
let cells = row.getInnerElements("c");
|
|
352
|
+
for (let key in cells) {
|
|
353
|
+
let cell = cells[key];
|
|
354
|
+
let cellValue = new FortuneSheetCelldata(cell, this.styles, this.sharedStrings, this.mergeCells, this.sheetFile, this.readXml);
|
|
355
|
+
if (cellValue._borderObject != null) {
|
|
356
|
+
if (this.config.borderInfo == null) {
|
|
357
|
+
this.config.borderInfo = [];
|
|
358
|
+
}
|
|
359
|
+
this.config.borderInfo.push(cellValue._borderObject);
|
|
360
|
+
delete cellValue._borderObject;
|
|
361
|
+
}
|
|
362
|
+
// let borderId = cellValue._borderId;
|
|
363
|
+
// if(borderId!=null){
|
|
364
|
+
// let borders = this.styles["borders"] as Element[];
|
|
365
|
+
// if(this.config._borderInfo==null){
|
|
366
|
+
// this.config._borderInfo = {};
|
|
367
|
+
// }
|
|
368
|
+
// if( borderId in this.config._borderInfo){
|
|
369
|
+
// this.config._borderInfo[borderId].cells.push(cellValue.r + "_" + cellValue.c);
|
|
370
|
+
// }
|
|
371
|
+
// else{
|
|
372
|
+
// let border = borders[borderId];
|
|
373
|
+
// let borderObject = new FortuneSheetborderInfoCellForImp();
|
|
374
|
+
// borderObject.rangeType = "cellGroup";
|
|
375
|
+
// borderObject.cells = [];
|
|
376
|
+
// let borderCellValue = new FortuneSheetborderInfoCellValue();
|
|
377
|
+
// let lefts = border.getInnerElements("left");
|
|
378
|
+
// let rights = border.getInnerElements("right");
|
|
379
|
+
// let tops = border.getInnerElements("top");
|
|
380
|
+
// let bottoms = border.getInnerElements("bottom");
|
|
381
|
+
// let diagonals = border.getInnerElements("diagonal");
|
|
382
|
+
// let left = this.getBorderInfo(lefts);
|
|
383
|
+
// let right = this.getBorderInfo(rights);
|
|
384
|
+
// let top = this.getBorderInfo(tops);
|
|
385
|
+
// let bottom = this.getBorderInfo(bottoms);
|
|
386
|
+
// let diagonal = this.getBorderInfo(diagonals);
|
|
387
|
+
// let isAdd = false;
|
|
388
|
+
// if(left!=null && left.color!=null){
|
|
389
|
+
// borderCellValue.l = left;
|
|
390
|
+
// isAdd = true;
|
|
391
|
+
// }
|
|
392
|
+
// if(right!=null && right.color!=null){
|
|
393
|
+
// borderCellValue.r = right;
|
|
394
|
+
// isAdd = true;
|
|
395
|
+
// }
|
|
396
|
+
// if(top!=null && top.color!=null){
|
|
397
|
+
// borderCellValue.t = top;
|
|
398
|
+
// isAdd = true;
|
|
399
|
+
// }
|
|
400
|
+
// if(bottom!=null && bottom.color!=null){
|
|
401
|
+
// borderCellValue.b = bottom;
|
|
402
|
+
// isAdd = true;
|
|
403
|
+
// }
|
|
404
|
+
// if(isAdd){
|
|
405
|
+
// borderObject.value = borderCellValue;
|
|
406
|
+
// this.config._borderInfo[borderId] = borderObject;
|
|
407
|
+
// }
|
|
408
|
+
// }
|
|
409
|
+
// }
|
|
410
|
+
if (cellValue._formulaType == "shared") {
|
|
411
|
+
if (this.formulaRefList == null) {
|
|
412
|
+
this.formulaRefList = {};
|
|
413
|
+
}
|
|
414
|
+
if (this.formulaRefList[cellValue._formulaSi] == null) {
|
|
415
|
+
this.formulaRefList[cellValue._formulaSi] = {};
|
|
416
|
+
}
|
|
417
|
+
let fv;
|
|
418
|
+
if (cellValue.v != null) {
|
|
419
|
+
fv = cellValue.v.f;
|
|
420
|
+
}
|
|
421
|
+
let refValue = {
|
|
422
|
+
t: cellValue._formulaType,
|
|
423
|
+
ref: cellValue._fomulaRef,
|
|
424
|
+
si: cellValue._formulaSi,
|
|
425
|
+
fv: fv,
|
|
426
|
+
cellValue: cellValue,
|
|
427
|
+
};
|
|
428
|
+
if (cellValue._fomulaRef != null) {
|
|
429
|
+
this.formulaRefList[cellValue._formulaSi]["mainRef"] = refValue;
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
this.formulaRefList[cellValue._formulaSi][cellValue.r + "_" + cellValue.c] = refValue;
|
|
433
|
+
}
|
|
434
|
+
// console.log(refValue, this.formulaRefList);
|
|
435
|
+
}
|
|
436
|
+
//There may be formulas that do not appear in calcChain
|
|
437
|
+
if (cellValue.v != null &&
|
|
438
|
+
cellValue.v.f != null) {
|
|
439
|
+
let formulaCell = {
|
|
440
|
+
r: cellValue.r,
|
|
441
|
+
c: cellValue.c,
|
|
442
|
+
};
|
|
443
|
+
cellOtherInfo.formulaList["r" + cellValue.r + "c" + cellValue.c] =
|
|
444
|
+
formulaCell;
|
|
445
|
+
}
|
|
446
|
+
this.celldata.push(cellValue);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return cellOtherInfo;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* fortunesheet config of dataValidations
|
|
454
|
+
*
|
|
455
|
+
* @returns {IfortunesheetDataVerification} - dataValidations config
|
|
456
|
+
*/
|
|
457
|
+
generateConfigDataValidations() {
|
|
458
|
+
let rows = this.readXml.getElementsByTagName("dataValidations/dataValidation", this.sheetFile);
|
|
459
|
+
let extLst = this.readXml.getElementsByTagName("extLst/ext/x14:dataValidations/x14:dataValidation", this.sheetFile) || [];
|
|
460
|
+
rows = rows.concat(extLst);
|
|
461
|
+
let dataVerification = {};
|
|
462
|
+
for (let i = 0; i < rows.length; i++) {
|
|
463
|
+
let row = rows[i];
|
|
464
|
+
let attrList = row.attributeList;
|
|
465
|
+
let formulaValue = row.value;
|
|
466
|
+
let type = getXmlAttibute(attrList, "type", null);
|
|
467
|
+
if (!type) {
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
let operator = "", sqref = "", sqrefIndexArr = [], valueArr = [];
|
|
471
|
+
let _prohibitInput = getXmlAttibute(attrList, "allowBlank", null) !== "1" ? false : true;
|
|
472
|
+
// x14 processing
|
|
473
|
+
const formulaReg = new RegExp(/<x14:formula1>|<xm:sqref>/g);
|
|
474
|
+
if (formulaReg.test(formulaValue) && (extLst === null || extLst === void 0 ? void 0 : extLst.length) >= 0) {
|
|
475
|
+
operator = getXmlAttibute(attrList, "operator", null);
|
|
476
|
+
const peelOffData = getPeelOffX14(formulaValue);
|
|
477
|
+
sqref = peelOffData === null || peelOffData === void 0 ? void 0 : peelOffData.sqref;
|
|
478
|
+
sqrefIndexArr = getMultiSequenceToNum(sqref);
|
|
479
|
+
valueArr = getMultiFormulaValue(peelOffData === null || peelOffData === void 0 ? void 0 : peelOffData.formula);
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
operator = getXmlAttibute(attrList, "operator", null);
|
|
483
|
+
sqref = getXmlAttibute(attrList, "sqref", null);
|
|
484
|
+
sqrefIndexArr = getMultiSequenceToNum(sqref);
|
|
485
|
+
valueArr = getMultiFormulaValue(formulaValue);
|
|
486
|
+
}
|
|
487
|
+
let _type = DATA_VERIFICATION_MAP[type];
|
|
488
|
+
let _type2 = null;
|
|
489
|
+
let _value1 = (valueArr === null || valueArr === void 0 ? void 0 : valueArr.length) >= 1 ? valueArr[0] : "";
|
|
490
|
+
let _value2 = (valueArr === null || valueArr === void 0 ? void 0 : valueArr.length) === 2 ? valueArr[1] : "";
|
|
491
|
+
let _hint = getXmlAttibute(attrList, "prompt", null);
|
|
492
|
+
let _hintShow = _hint ? true : false;
|
|
493
|
+
const matchType = COMMON_TYPE2.includes(_type) ? "common" : _type;
|
|
494
|
+
_type2 = operator
|
|
495
|
+
? DATA_VERIFICATION_TYPE2_MAP[matchType][operator]
|
|
496
|
+
: "bw";
|
|
497
|
+
// mobile phone number processing
|
|
498
|
+
if (_type === "text_content" &&
|
|
499
|
+
((_value1 === null || _value1 === void 0 ? void 0 : _value1.includes("LEN")) || (_value1 === null || _value1 === void 0 ? void 0 : _value1.includes("len"))) &&
|
|
500
|
+
(_value1 === null || _value1 === void 0 ? void 0 : _value1.includes("=11"))) {
|
|
501
|
+
_type = "validity";
|
|
502
|
+
_type2 = "phone";
|
|
503
|
+
}
|
|
504
|
+
// date processing
|
|
505
|
+
if (_type === "date") {
|
|
506
|
+
const D1900 = new Date(1899, 11, 30, 0, 0, 0);
|
|
507
|
+
_value1 = dayjs(D1900)
|
|
508
|
+
.clone()
|
|
509
|
+
.add(Number(_value1), "day")
|
|
510
|
+
.format("YYYY-MM-DD");
|
|
511
|
+
_value2 = dayjs(D1900)
|
|
512
|
+
.clone()
|
|
513
|
+
.add(Number(_value2), "day")
|
|
514
|
+
.format("YYYY-MM-DD");
|
|
515
|
+
}
|
|
516
|
+
// checkbox and dropdown processing
|
|
517
|
+
if (_type === "checkbox" || _type === "dropdown") {
|
|
518
|
+
_type2 = null;
|
|
519
|
+
}
|
|
520
|
+
// dynamically add dataVerifications
|
|
521
|
+
for (const ref of sqrefIndexArr) {
|
|
522
|
+
dataVerification[ref] = {
|
|
523
|
+
type: _type,
|
|
524
|
+
type2: _type2,
|
|
525
|
+
value1: _value1,
|
|
526
|
+
value2: _value2,
|
|
527
|
+
checked: false,
|
|
528
|
+
remote: false,
|
|
529
|
+
prohibitInput: _prohibitInput,
|
|
530
|
+
hintShow: _hintShow,
|
|
531
|
+
hintText: _hint,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return dataVerification;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* fortunesheet config of hyperlink
|
|
539
|
+
*
|
|
540
|
+
* @returns {IfortunesheetHyperlink} - hyperlink config
|
|
541
|
+
*/
|
|
542
|
+
generateConfigHyperlinks() {
|
|
543
|
+
var _a;
|
|
544
|
+
let rows = this.readXml.getElementsByTagName("hyperlinks/hyperlink", this.sheetFile);
|
|
545
|
+
let hyperlink = {};
|
|
546
|
+
for (let i = 0; i < rows.length; i++) {
|
|
547
|
+
let row = rows[i];
|
|
548
|
+
let attrList = row.attributeList;
|
|
549
|
+
let ref = getXmlAttibute(attrList, "ref", null), refArr = getMultiSequenceToNum(ref), _display = getXmlAttibute(attrList, "display", null), _address = getXmlAttibute(attrList, "location", null), _tooltip = getXmlAttibute(attrList, "tooltip", null);
|
|
550
|
+
let _type = _address
|
|
551
|
+
? "internal"
|
|
552
|
+
: "external";
|
|
553
|
+
// external hyperlink
|
|
554
|
+
if (!_address) {
|
|
555
|
+
let rid = attrList["r:id"];
|
|
556
|
+
let sheetFile = this.sheetFile;
|
|
557
|
+
let relationshipList = this.readXml.getElementsByTagName("Relationships/Relationship", `xl/worksheets/_rels/${sheetFile.replace(worksheetFilePath, "")}.rels`);
|
|
558
|
+
const findRid = relationshipList === null || relationshipList === void 0 ? void 0 : relationshipList.find((e) => e.attributeList["Id"] === rid);
|
|
559
|
+
if (findRid) {
|
|
560
|
+
_address = findRid.attributeList["Target"];
|
|
561
|
+
_type = (_a = findRid.attributeList["TargetMode"]) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
// match R1C1
|
|
565
|
+
const addressReg = new RegExp(/^.*!R([\d$])+C([\d$])*$/g);
|
|
566
|
+
if (addressReg.test(_address)) {
|
|
567
|
+
_address = getTransR1C1ToSequence(_address);
|
|
568
|
+
}
|
|
569
|
+
// dynamically add hyperlinks
|
|
570
|
+
for (const ref of refArr) {
|
|
571
|
+
hyperlink[ref] = {
|
|
572
|
+
linkAddress: _address,
|
|
573
|
+
linkTooltip: _tooltip || "",
|
|
574
|
+
linkType: _type,
|
|
575
|
+
display: _display || "",
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return hyperlink;
|
|
580
|
+
}
|
|
581
|
+
}
|