@ricsam/formula-engine 0.0.16 → 0.0.17
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/cjs/core/autofill-utils.cjs +73 -35
- package/dist/cjs/core/autofill-utils.cjs.map +3 -3
- package/dist/cjs/core/cell-mover.cjs +178 -0
- package/dist/cjs/core/cell-mover.cjs.map +10 -0
- package/dist/cjs/core/engine.cjs +105 -13
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/copy-manager.cjs +337 -82
- package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/reference-manager.cjs +124 -0
- package/dist/cjs/core/managers/reference-manager.cjs.map +10 -0
- package/dist/cjs/core/managers/style-manager.cjs +115 -147
- package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/workbook-manager.cjs +87 -3
- package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
- package/dist/cjs/core/types.cjs.map +2 -2
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/autofill-utils.mjs +73 -35
- package/dist/mjs/core/autofill-utils.mjs.map +3 -3
- package/dist/mjs/core/cell-mover.mjs +148 -0
- package/dist/mjs/core/cell-mover.mjs.map +10 -0
- package/dist/mjs/core/engine.mjs +105 -13
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/copy-manager.mjs +339 -82
- package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/reference-manager.mjs +93 -0
- package/dist/mjs/core/managers/reference-manager.mjs.map +10 -0
- package/dist/mjs/core/managers/style-manager.mjs +115 -147
- package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/workbook-manager.mjs +87 -3
- package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
- package/dist/mjs/core/types.mjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/autofill-utils.d.ts +4 -0
- package/dist/types/core/cell-mover.d.ts +63 -0
- package/dist/types/core/engine.d.ts +123 -9
- package/dist/types/core/managers/copy-manager.d.ts +47 -2
- package/dist/types/core/managers/reference-manager.d.ts +54 -0
- package/dist/types/core/managers/style-manager.d.ts +6 -6
- package/dist/types/core/managers/workbook-manager.d.ts +39 -1
- package/dist/types/core/types.d.ts +52 -11
- package/package.json +1 -1
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { parseFormula } from "../../parser/parser.mjs";
|
|
3
3
|
import { astToString } from "../../parser/formatter.mjs";
|
|
4
4
|
import { transformAST } from "../ast-traverser.mjs";
|
|
5
|
+
import { getCellReference, isCellInRange } from "../utils.mjs";
|
|
5
6
|
import { intersectRanges } from "../utils/range-utils.mjs";
|
|
7
|
+
import {
|
|
8
|
+
updateReferencesForMovedCells
|
|
9
|
+
} from "../cell-mover.mjs";
|
|
6
10
|
|
|
7
11
|
class CopyManager {
|
|
8
12
|
workbookManager;
|
|
@@ -13,30 +17,115 @@ class CopyManager {
|
|
|
13
17
|
this.evaluationManager = evaluationManager;
|
|
14
18
|
this.styleManager = styleManager;
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
normalizeInclude(include) {
|
|
21
|
+
if (!include || include === "all") {
|
|
22
|
+
return ["content", "style", "metadata"];
|
|
23
|
+
}
|
|
24
|
+
return include;
|
|
25
|
+
}
|
|
26
|
+
shouldInclude(options, part) {
|
|
27
|
+
const normalized = this.normalizeInclude(options.include);
|
|
28
|
+
return normalized.includes(part);
|
|
29
|
+
}
|
|
30
|
+
pasteCells(source, target, options) {
|
|
17
31
|
if (source.length === 0) {
|
|
18
32
|
return;
|
|
19
33
|
}
|
|
34
|
+
if (options.cut === true) {
|
|
35
|
+
return this.cutCells(source, target, options);
|
|
36
|
+
} else {
|
|
37
|
+
return this.copyOnlyCells(source, target, options);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
cutCells(source, target, options) {
|
|
41
|
+
const topLeft = this.findTopLeft(source);
|
|
42
|
+
const rowOffset = target.rowIndex - topLeft.rowIndex;
|
|
43
|
+
const colOffset = target.colIndex - topLeft.colIndex;
|
|
44
|
+
const snapshot = this.snapshotCellsWithStyles(source);
|
|
45
|
+
this.clearSourceCells(source);
|
|
46
|
+
if (this.shouldInclude(options, "style")) {
|
|
47
|
+
for (const cell of source) {
|
|
48
|
+
const cellRange = {
|
|
49
|
+
workbookName: cell.workbookName,
|
|
50
|
+
sheetName: cell.sheetName,
|
|
51
|
+
range: {
|
|
52
|
+
start: { col: cell.colIndex, row: cell.rowIndex },
|
|
53
|
+
end: {
|
|
54
|
+
col: { type: "number", value: cell.colIndex },
|
|
55
|
+
row: { type: "number", value: cell.rowIndex }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
this.styleManager.clearCellStylesInRange(cellRange);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const movedCellsSet = new Set(source.map((c) => `${c.workbookName}:${c.sheetName}:${c.colIndex}:${c.rowIndex}`));
|
|
63
|
+
const movedCellsInfo = {
|
|
64
|
+
cellsSet: movedCellsSet,
|
|
65
|
+
workbookName: topLeft.workbookName,
|
|
66
|
+
sheetName: topLeft.sheetName,
|
|
67
|
+
rowOffset,
|
|
68
|
+
colOffset
|
|
69
|
+
};
|
|
70
|
+
this.workbookManager.updateFormulasExcluding(movedCellsSet, (formula) => updateReferencesForMovedCells(formula, movedCellsInfo));
|
|
71
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
72
|
+
const snap = snapshot[i];
|
|
73
|
+
const sourceCell = source[i];
|
|
74
|
+
const targetCell = {
|
|
75
|
+
workbookName: target.workbookName,
|
|
76
|
+
sheetName: target.sheetName,
|
|
77
|
+
colIndex: sourceCell.colIndex + colOffset,
|
|
78
|
+
rowIndex: sourceCell.rowIndex + rowOffset
|
|
79
|
+
};
|
|
80
|
+
if (this.shouldInclude(options, "content") && snap.content) {
|
|
81
|
+
let targetContent = snap.content;
|
|
82
|
+
if (typeof snap.content === "string" && snap.content.startsWith("=")) {
|
|
83
|
+
targetContent = this.adjustFormulaReferences(snap.content, {
|
|
84
|
+
colIndex: snap.address.colIndex,
|
|
85
|
+
rowIndex: snap.address.rowIndex
|
|
86
|
+
}, {
|
|
87
|
+
colIndex: targetCell.colIndex,
|
|
88
|
+
rowIndex: targetCell.rowIndex
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
console.log("targetContent", targetContent);
|
|
92
|
+
this.workbookManager.setCellContent(targetCell, targetContent);
|
|
93
|
+
}
|
|
94
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
95
|
+
if (snap.metadata) {
|
|
96
|
+
this.workbookManager.setCellMetadata(targetCell, {
|
|
97
|
+
...snap.metadata
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (this.shouldInclude(options, "style")) {
|
|
104
|
+
this.applyStylesFromSnapshot(snap, targetCell);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
copyOnlyCells(source, target, options) {
|
|
20
109
|
const topLeft = this.findTopLeft(source);
|
|
21
110
|
const rowOffset = target.rowIndex - topLeft.rowIndex;
|
|
22
111
|
const colOffset = target.colIndex - topLeft.colIndex;
|
|
23
|
-
|
|
24
|
-
|
|
112
|
+
const snapshot = this.snapshotCells(source);
|
|
113
|
+
if (this.shouldInclude(options, "content")) {
|
|
114
|
+
for (let i = 0;i < source.length; i++) {
|
|
115
|
+
const sourceCell = source[i];
|
|
116
|
+
const cellSnapshot = snapshot[i];
|
|
25
117
|
const targetCell = {
|
|
26
118
|
workbookName: target.workbookName,
|
|
27
119
|
sheetName: target.sheetName,
|
|
28
120
|
colIndex: sourceCell.colIndex + colOffset,
|
|
29
121
|
rowIndex: sourceCell.rowIndex + rowOffset
|
|
30
122
|
};
|
|
31
|
-
this.
|
|
123
|
+
this.copyCellContentFromSnapshot(cellSnapshot, targetCell, topLeft, options);
|
|
32
124
|
}
|
|
33
125
|
}
|
|
34
|
-
if (
|
|
126
|
+
if (this.shouldInclude(options, "style")) {
|
|
35
127
|
this.copyFormatting(source, topLeft, target, rowOffset, colOffset);
|
|
36
128
|
}
|
|
37
|
-
if (options.cut) {
|
|
38
|
-
this.clearSourceCells(source);
|
|
39
|
-
}
|
|
40
129
|
}
|
|
41
130
|
findTopLeft(cells) {
|
|
42
131
|
let minRow = Infinity;
|
|
@@ -51,6 +140,141 @@ class CopyManager {
|
|
|
51
140
|
}
|
|
52
141
|
return topLeftCell;
|
|
53
142
|
}
|
|
143
|
+
snapshotCells(cells) {
|
|
144
|
+
return cells.map((cell) => {
|
|
145
|
+
const sheet = this.workbookManager.getSheet({
|
|
146
|
+
workbookName: cell.workbookName,
|
|
147
|
+
sheetName: cell.sheetName
|
|
148
|
+
});
|
|
149
|
+
const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
|
|
150
|
+
const content = sheet?.content.get(key);
|
|
151
|
+
const metadata = this.workbookManager.getCellMetadata(cell);
|
|
152
|
+
return {
|
|
153
|
+
address: cell,
|
|
154
|
+
content,
|
|
155
|
+
metadata
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
snapshotCellsWithStyles(cells) {
|
|
160
|
+
const allCellStyles = this.styleManager.getAllCellStyles();
|
|
161
|
+
const allConditionalStyles = this.styleManager.getAllConditionalStyles();
|
|
162
|
+
return cells.map((cell) => {
|
|
163
|
+
const sheet = this.workbookManager.getSheet({
|
|
164
|
+
workbookName: cell.workbookName,
|
|
165
|
+
sheetName: cell.sheetName
|
|
166
|
+
});
|
|
167
|
+
const key = getCellReference(cell);
|
|
168
|
+
const content = sheet?.content.get(key);
|
|
169
|
+
const metadata = this.workbookManager.getCellMetadata(cell);
|
|
170
|
+
const matchingCellStyles = allCellStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && isCellInRange(cell, area.range)));
|
|
171
|
+
const matchingConditionalStyles = allConditionalStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && isCellInRange(cell, area.range)));
|
|
172
|
+
return {
|
|
173
|
+
address: cell,
|
|
174
|
+
content,
|
|
175
|
+
metadata,
|
|
176
|
+
matchingCellStyles,
|
|
177
|
+
matchingConditionalStyles
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
applyStylesFromSnapshot(snapshot, targetCell) {
|
|
182
|
+
if (snapshot.matchingCellStyles) {
|
|
183
|
+
for (const style of snapshot.matchingCellStyles) {
|
|
184
|
+
const newStyle = {
|
|
185
|
+
areas: [
|
|
186
|
+
{
|
|
187
|
+
workbookName: targetCell.workbookName,
|
|
188
|
+
sheetName: targetCell.sheetName,
|
|
189
|
+
range: {
|
|
190
|
+
start: { col: targetCell.colIndex, row: targetCell.rowIndex },
|
|
191
|
+
end: {
|
|
192
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
193
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
style: style.style
|
|
199
|
+
};
|
|
200
|
+
this.styleManager.addCellStyle(newStyle);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (snapshot.matchingConditionalStyles) {
|
|
204
|
+
for (const style of snapshot.matchingConditionalStyles) {
|
|
205
|
+
const newStyle = {
|
|
206
|
+
areas: [
|
|
207
|
+
{
|
|
208
|
+
workbookName: targetCell.workbookName,
|
|
209
|
+
sheetName: targetCell.sheetName,
|
|
210
|
+
range: {
|
|
211
|
+
start: { col: targetCell.colIndex, row: targetCell.rowIndex },
|
|
212
|
+
end: {
|
|
213
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
214
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
condition: style.condition
|
|
220
|
+
};
|
|
221
|
+
this.styleManager.addConditionalStyle(newStyle);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
copyCellContentFromSnapshot(snapshot, targetCell, sourceTopLeft, options) {
|
|
226
|
+
if (!snapshot.content) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let targetContent;
|
|
230
|
+
const copyType = options.type ?? "formula";
|
|
231
|
+
if (copyType === "value") {
|
|
232
|
+
const evalResult = this.evaluationManager.getCellEvaluationResult(snapshot.address);
|
|
233
|
+
if (!evalResult || evalResult.type !== "value") {
|
|
234
|
+
targetContent = snapshot.content;
|
|
235
|
+
} else {
|
|
236
|
+
const result = evalResult.result;
|
|
237
|
+
if (result.type === "number") {
|
|
238
|
+
targetContent = result.value;
|
|
239
|
+
} else if (result.type === "string") {
|
|
240
|
+
targetContent = result.value;
|
|
241
|
+
} else if (result.type === "boolean") {
|
|
242
|
+
targetContent = result.value;
|
|
243
|
+
} else {
|
|
244
|
+
targetContent = snapshot.content;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
if (typeof snapshot.content === "string" && snapshot.content.startsWith("=")) {
|
|
249
|
+
targetContent = this.adjustFormulaReferences(snapshot.content, {
|
|
250
|
+
colIndex: snapshot.address.colIndex,
|
|
251
|
+
rowIndex: snapshot.address.rowIndex
|
|
252
|
+
}, {
|
|
253
|
+
colIndex: targetCell.colIndex,
|
|
254
|
+
rowIndex: targetCell.rowIndex
|
|
255
|
+
});
|
|
256
|
+
} else {
|
|
257
|
+
targetContent = snapshot.content;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const targetSheet = this.workbookManager.getSheet({
|
|
261
|
+
workbookName: targetCell.workbookName,
|
|
262
|
+
sheetName: targetCell.sheetName
|
|
263
|
+
});
|
|
264
|
+
if (targetSheet) {
|
|
265
|
+
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
266
|
+
targetSheet.content.set(targetKey, targetContent);
|
|
267
|
+
}
|
|
268
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
269
|
+
if (snapshot.metadata) {
|
|
270
|
+
this.workbookManager.setCellMetadata(targetCell, {
|
|
271
|
+
...snapshot.metadata
|
|
272
|
+
});
|
|
273
|
+
} else {
|
|
274
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
54
278
|
copyCellContent(sourceCell, targetCell, sourceTopLeft, options) {
|
|
55
279
|
const sheet = this.workbookManager.getSheet({
|
|
56
280
|
workbookName: sourceCell.workbookName,
|
|
@@ -65,7 +289,8 @@ class CopyManager {
|
|
|
65
289
|
return;
|
|
66
290
|
}
|
|
67
291
|
let targetContent;
|
|
68
|
-
|
|
292
|
+
const copyType = options.type ?? "formula";
|
|
293
|
+
if (copyType === "value") {
|
|
69
294
|
const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
|
|
70
295
|
if (!evalResult || evalResult.type !== "value") {
|
|
71
296
|
targetContent = cellContent;
|
|
@@ -102,6 +327,14 @@ class CopyManager {
|
|
|
102
327
|
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
103
328
|
targetSheet.content.set(targetKey, targetContent);
|
|
104
329
|
}
|
|
330
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
331
|
+
const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
|
|
332
|
+
if (sourceMetadata) {
|
|
333
|
+
this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
|
|
334
|
+
} else {
|
|
335
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
105
338
|
}
|
|
106
339
|
adjustFormulaReferences(formula, sourceAddress, targetAddress) {
|
|
107
340
|
try {
|
|
@@ -159,34 +392,42 @@ class CopyManager {
|
|
|
159
392
|
const allConditionalStyles = this.styleManager.getAllConditionalStyles();
|
|
160
393
|
const allCellStyles = this.styleManager.getAllCellStyles();
|
|
161
394
|
for (const style of allConditionalStyles) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
395
|
+
for (const area of style.areas) {
|
|
396
|
+
if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
|
|
397
|
+
const intersection = intersectRanges(area.range, sourceRange);
|
|
398
|
+
if (intersection) {
|
|
399
|
+
const newStyle = {
|
|
400
|
+
areas: [
|
|
401
|
+
{
|
|
402
|
+
workbookName: target.workbookName,
|
|
403
|
+
sheetName: target.sheetName,
|
|
404
|
+
range: this.adjustRange(intersection, rowOffset, colOffset)
|
|
405
|
+
}
|
|
406
|
+
],
|
|
407
|
+
condition: style.condition
|
|
408
|
+
};
|
|
409
|
+
this.styleManager.addConditionalStyle(newStyle);
|
|
410
|
+
}
|
|
174
411
|
}
|
|
175
412
|
}
|
|
176
413
|
}
|
|
177
414
|
for (const style of allCellStyles) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
415
|
+
for (const area of style.areas) {
|
|
416
|
+
if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
|
|
417
|
+
const intersection = intersectRanges(area.range, sourceRange);
|
|
418
|
+
if (intersection) {
|
|
419
|
+
const newStyle = {
|
|
420
|
+
areas: [
|
|
421
|
+
{
|
|
422
|
+
workbookName: target.workbookName,
|
|
423
|
+
sheetName: target.sheetName,
|
|
424
|
+
range: this.adjustRange(intersection, rowOffset, colOffset)
|
|
425
|
+
}
|
|
426
|
+
],
|
|
427
|
+
style: style.style
|
|
428
|
+
};
|
|
429
|
+
this.styleManager.addCellStyle(newStyle);
|
|
430
|
+
}
|
|
190
431
|
}
|
|
191
432
|
}
|
|
192
433
|
}
|
|
@@ -224,22 +465,15 @@ class CopyManager {
|
|
|
224
465
|
}
|
|
225
466
|
clearSourceCells(cells) {
|
|
226
467
|
for (const cell of cells) {
|
|
227
|
-
|
|
228
|
-
workbookName: cell.workbookName,
|
|
229
|
-
sheetName: cell.sheetName
|
|
230
|
-
});
|
|
231
|
-
if (sheet) {
|
|
232
|
-
const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
|
|
233
|
-
sheet.content.delete(key);
|
|
234
|
-
}
|
|
468
|
+
this.workbookManager.setCellContent(cell, "");
|
|
235
469
|
}
|
|
236
470
|
}
|
|
237
471
|
fillAreas(seedRange, targetRanges, options) {
|
|
238
472
|
for (const targetRange of targetRanges) {
|
|
239
473
|
this.fillRangeWithSeed(seedRange, targetRange, {
|
|
240
|
-
copyContent: options
|
|
241
|
-
copyStyles:
|
|
242
|
-
contentType: options.type,
|
|
474
|
+
copyContent: this.shouldInclude(options, "content"),
|
|
475
|
+
copyStyles: this.shouldInclude(options, "style"),
|
|
476
|
+
contentType: options.type ?? "formula",
|
|
243
477
|
adjustFormulas: true
|
|
244
478
|
});
|
|
245
479
|
}
|
|
@@ -275,7 +509,7 @@ class CopyManager {
|
|
|
275
509
|
this.copyCellContentWithOffset(seedCell, targetCell, rowDelta, colDelta, {
|
|
276
510
|
type: options.contentType,
|
|
277
511
|
cut: false,
|
|
278
|
-
|
|
512
|
+
include: ["content"]
|
|
279
513
|
});
|
|
280
514
|
}
|
|
281
515
|
if (options.copyStyles) {
|
|
@@ -313,7 +547,7 @@ class CopyManager {
|
|
|
313
547
|
this.copyCellContentWithOffset(sourceCell, targetCell, 0, colDelta, {
|
|
314
548
|
type: options.contentType,
|
|
315
549
|
cut: false,
|
|
316
|
-
|
|
550
|
+
include: ["content"]
|
|
317
551
|
});
|
|
318
552
|
}
|
|
319
553
|
if (options.copyStyles) {
|
|
@@ -386,7 +620,8 @@ class CopyManager {
|
|
|
386
620
|
return;
|
|
387
621
|
}
|
|
388
622
|
let targetContent;
|
|
389
|
-
|
|
623
|
+
const copyType = options.type ?? "formula";
|
|
624
|
+
if (copyType === "value") {
|
|
390
625
|
const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
|
|
391
626
|
if (!evalResult || evalResult.type !== "value") {
|
|
392
627
|
targetContent = cellContent;
|
|
@@ -417,6 +652,14 @@ class CopyManager {
|
|
|
417
652
|
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
418
653
|
targetSheet.content.set(targetKey, targetContent);
|
|
419
654
|
}
|
|
655
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
656
|
+
const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
|
|
657
|
+
if (sourceMetadata) {
|
|
658
|
+
this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
|
|
659
|
+
} else {
|
|
660
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
420
663
|
}
|
|
421
664
|
adjustFormulaWithOffset(formula, rowDelta, colDelta) {
|
|
422
665
|
try {
|
|
@@ -484,46 +727,60 @@ class CopyManager {
|
|
|
484
727
|
}
|
|
485
728
|
};
|
|
486
729
|
for (const style of allConditionalStyles) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
730
|
+
for (const area of style.areas) {
|
|
731
|
+
if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
|
|
732
|
+
const intersection = intersectRanges(area.range, sourceCellRange);
|
|
733
|
+
if (intersection) {
|
|
734
|
+
const newStyle = {
|
|
735
|
+
areas: [
|
|
736
|
+
{
|
|
737
|
+
workbookName: targetCell.workbookName,
|
|
738
|
+
sheetName: targetCell.sheetName,
|
|
739
|
+
range: {
|
|
740
|
+
start: {
|
|
741
|
+
col: targetCell.colIndex,
|
|
742
|
+
row: targetCell.rowIndex
|
|
743
|
+
},
|
|
744
|
+
end: {
|
|
745
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
746
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
747
|
+
}
|
|
748
|
+
}
|
|
499
749
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
750
|
+
],
|
|
751
|
+
condition: style.condition
|
|
752
|
+
};
|
|
753
|
+
this.styleManager.addConditionalStyle(newStyle);
|
|
754
|
+
}
|
|
505
755
|
}
|
|
506
756
|
}
|
|
507
757
|
}
|
|
508
758
|
for (const style of allCellStyles) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
759
|
+
for (const area of style.areas) {
|
|
760
|
+
if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
|
|
761
|
+
const intersection = intersectRanges(area.range, sourceCellRange);
|
|
762
|
+
if (intersection) {
|
|
763
|
+
const newStyle = {
|
|
764
|
+
areas: [
|
|
765
|
+
{
|
|
766
|
+
workbookName: targetCell.workbookName,
|
|
767
|
+
sheetName: targetCell.sheetName,
|
|
768
|
+
range: {
|
|
769
|
+
start: {
|
|
770
|
+
col: targetCell.colIndex,
|
|
771
|
+
row: targetCell.rowIndex
|
|
772
|
+
},
|
|
773
|
+
end: {
|
|
774
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
775
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
776
|
+
}
|
|
777
|
+
}
|
|
521
778
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
779
|
+
],
|
|
780
|
+
style: style.style
|
|
781
|
+
};
|
|
782
|
+
this.styleManager.addCellStyle(newStyle);
|
|
783
|
+
}
|
|
527
784
|
}
|
|
528
785
|
}
|
|
529
786
|
}
|
|
@@ -533,4 +790,4 @@ export {
|
|
|
533
790
|
CopyManager
|
|
534
791
|
};
|
|
535
792
|
|
|
536
|
-
//# debugId=
|
|
793
|
+
//# debugId=A9675A1499D2CBA064756E2164756E21
|