@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
|
@@ -35,7 +35,9 @@ module.exports = __toCommonJS(exports_copy_manager);
|
|
|
35
35
|
var import_parser = require("../../parser/parser.cjs");
|
|
36
36
|
var import_formatter = require("../../parser/formatter.cjs");
|
|
37
37
|
var import_ast_traverser = require("../ast-traverser.cjs");
|
|
38
|
+
var import_utils = require("../utils.cjs");
|
|
38
39
|
var import_range_utils = require("../utils/range-utils.cjs");
|
|
40
|
+
var import_cell_mover = require("../cell-mover.cjs");
|
|
39
41
|
|
|
40
42
|
class CopyManager {
|
|
41
43
|
workbookManager;
|
|
@@ -46,30 +48,115 @@ class CopyManager {
|
|
|
46
48
|
this.evaluationManager = evaluationManager;
|
|
47
49
|
this.styleManager = styleManager;
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
normalizeInclude(include) {
|
|
52
|
+
if (!include || include === "all") {
|
|
53
|
+
return ["content", "style", "metadata"];
|
|
54
|
+
}
|
|
55
|
+
return include;
|
|
56
|
+
}
|
|
57
|
+
shouldInclude(options, part) {
|
|
58
|
+
const normalized = this.normalizeInclude(options.include);
|
|
59
|
+
return normalized.includes(part);
|
|
60
|
+
}
|
|
61
|
+
pasteCells(source, target, options) {
|
|
50
62
|
if (source.length === 0) {
|
|
51
63
|
return;
|
|
52
64
|
}
|
|
65
|
+
if (options.cut === true) {
|
|
66
|
+
return this.cutCells(source, target, options);
|
|
67
|
+
} else {
|
|
68
|
+
return this.copyOnlyCells(source, target, options);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
cutCells(source, target, options) {
|
|
72
|
+
const topLeft = this.findTopLeft(source);
|
|
73
|
+
const rowOffset = target.rowIndex - topLeft.rowIndex;
|
|
74
|
+
const colOffset = target.colIndex - topLeft.colIndex;
|
|
75
|
+
const snapshot = this.snapshotCellsWithStyles(source);
|
|
76
|
+
this.clearSourceCells(source);
|
|
77
|
+
if (this.shouldInclude(options, "style")) {
|
|
78
|
+
for (const cell of source) {
|
|
79
|
+
const cellRange = {
|
|
80
|
+
workbookName: cell.workbookName,
|
|
81
|
+
sheetName: cell.sheetName,
|
|
82
|
+
range: {
|
|
83
|
+
start: { col: cell.colIndex, row: cell.rowIndex },
|
|
84
|
+
end: {
|
|
85
|
+
col: { type: "number", value: cell.colIndex },
|
|
86
|
+
row: { type: "number", value: cell.rowIndex }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.styleManager.clearCellStylesInRange(cellRange);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const movedCellsSet = new Set(source.map((c) => `${c.workbookName}:${c.sheetName}:${c.colIndex}:${c.rowIndex}`));
|
|
94
|
+
const movedCellsInfo = {
|
|
95
|
+
cellsSet: movedCellsSet,
|
|
96
|
+
workbookName: topLeft.workbookName,
|
|
97
|
+
sheetName: topLeft.sheetName,
|
|
98
|
+
rowOffset,
|
|
99
|
+
colOffset
|
|
100
|
+
};
|
|
101
|
+
this.workbookManager.updateFormulasExcluding(movedCellsSet, (formula) => import_cell_mover.updateReferencesForMovedCells(formula, movedCellsInfo));
|
|
102
|
+
for (let i = 0;i < snapshot.length; i++) {
|
|
103
|
+
const snap = snapshot[i];
|
|
104
|
+
const sourceCell = source[i];
|
|
105
|
+
const targetCell = {
|
|
106
|
+
workbookName: target.workbookName,
|
|
107
|
+
sheetName: target.sheetName,
|
|
108
|
+
colIndex: sourceCell.colIndex + colOffset,
|
|
109
|
+
rowIndex: sourceCell.rowIndex + rowOffset
|
|
110
|
+
};
|
|
111
|
+
if (this.shouldInclude(options, "content") && snap.content) {
|
|
112
|
+
let targetContent = snap.content;
|
|
113
|
+
if (typeof snap.content === "string" && snap.content.startsWith("=")) {
|
|
114
|
+
targetContent = this.adjustFormulaReferences(snap.content, {
|
|
115
|
+
colIndex: snap.address.colIndex,
|
|
116
|
+
rowIndex: snap.address.rowIndex
|
|
117
|
+
}, {
|
|
118
|
+
colIndex: targetCell.colIndex,
|
|
119
|
+
rowIndex: targetCell.rowIndex
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
console.log("targetContent", targetContent);
|
|
123
|
+
this.workbookManager.setCellContent(targetCell, targetContent);
|
|
124
|
+
}
|
|
125
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
126
|
+
if (snap.metadata) {
|
|
127
|
+
this.workbookManager.setCellMetadata(targetCell, {
|
|
128
|
+
...snap.metadata
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (this.shouldInclude(options, "style")) {
|
|
135
|
+
this.applyStylesFromSnapshot(snap, targetCell);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
copyOnlyCells(source, target, options) {
|
|
53
140
|
const topLeft = this.findTopLeft(source);
|
|
54
141
|
const rowOffset = target.rowIndex - topLeft.rowIndex;
|
|
55
142
|
const colOffset = target.colIndex - topLeft.colIndex;
|
|
56
|
-
|
|
57
|
-
|
|
143
|
+
const snapshot = this.snapshotCells(source);
|
|
144
|
+
if (this.shouldInclude(options, "content")) {
|
|
145
|
+
for (let i = 0;i < source.length; i++) {
|
|
146
|
+
const sourceCell = source[i];
|
|
147
|
+
const cellSnapshot = snapshot[i];
|
|
58
148
|
const targetCell = {
|
|
59
149
|
workbookName: target.workbookName,
|
|
60
150
|
sheetName: target.sheetName,
|
|
61
151
|
colIndex: sourceCell.colIndex + colOffset,
|
|
62
152
|
rowIndex: sourceCell.rowIndex + rowOffset
|
|
63
153
|
};
|
|
64
|
-
this.
|
|
154
|
+
this.copyCellContentFromSnapshot(cellSnapshot, targetCell, topLeft, options);
|
|
65
155
|
}
|
|
66
156
|
}
|
|
67
|
-
if (
|
|
157
|
+
if (this.shouldInclude(options, "style")) {
|
|
68
158
|
this.copyFormatting(source, topLeft, target, rowOffset, colOffset);
|
|
69
159
|
}
|
|
70
|
-
if (options.cut) {
|
|
71
|
-
this.clearSourceCells(source);
|
|
72
|
-
}
|
|
73
160
|
}
|
|
74
161
|
findTopLeft(cells) {
|
|
75
162
|
let minRow = Infinity;
|
|
@@ -84,6 +171,141 @@ class CopyManager {
|
|
|
84
171
|
}
|
|
85
172
|
return topLeftCell;
|
|
86
173
|
}
|
|
174
|
+
snapshotCells(cells) {
|
|
175
|
+
return cells.map((cell) => {
|
|
176
|
+
const sheet = this.workbookManager.getSheet({
|
|
177
|
+
workbookName: cell.workbookName,
|
|
178
|
+
sheetName: cell.sheetName
|
|
179
|
+
});
|
|
180
|
+
const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
|
|
181
|
+
const content = sheet?.content.get(key);
|
|
182
|
+
const metadata = this.workbookManager.getCellMetadata(cell);
|
|
183
|
+
return {
|
|
184
|
+
address: cell,
|
|
185
|
+
content,
|
|
186
|
+
metadata
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
snapshotCellsWithStyles(cells) {
|
|
191
|
+
const allCellStyles = this.styleManager.getAllCellStyles();
|
|
192
|
+
const allConditionalStyles = this.styleManager.getAllConditionalStyles();
|
|
193
|
+
return cells.map((cell) => {
|
|
194
|
+
const sheet = this.workbookManager.getSheet({
|
|
195
|
+
workbookName: cell.workbookName,
|
|
196
|
+
sheetName: cell.sheetName
|
|
197
|
+
});
|
|
198
|
+
const key = import_utils.getCellReference(cell);
|
|
199
|
+
const content = sheet?.content.get(key);
|
|
200
|
+
const metadata = this.workbookManager.getCellMetadata(cell);
|
|
201
|
+
const matchingCellStyles = allCellStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && import_utils.isCellInRange(cell, area.range)));
|
|
202
|
+
const matchingConditionalStyles = allConditionalStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && import_utils.isCellInRange(cell, area.range)));
|
|
203
|
+
return {
|
|
204
|
+
address: cell,
|
|
205
|
+
content,
|
|
206
|
+
metadata,
|
|
207
|
+
matchingCellStyles,
|
|
208
|
+
matchingConditionalStyles
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
applyStylesFromSnapshot(snapshot, targetCell) {
|
|
213
|
+
if (snapshot.matchingCellStyles) {
|
|
214
|
+
for (const style of snapshot.matchingCellStyles) {
|
|
215
|
+
const newStyle = {
|
|
216
|
+
areas: [
|
|
217
|
+
{
|
|
218
|
+
workbookName: targetCell.workbookName,
|
|
219
|
+
sheetName: targetCell.sheetName,
|
|
220
|
+
range: {
|
|
221
|
+
start: { col: targetCell.colIndex, row: targetCell.rowIndex },
|
|
222
|
+
end: {
|
|
223
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
224
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
],
|
|
229
|
+
style: style.style
|
|
230
|
+
};
|
|
231
|
+
this.styleManager.addCellStyle(newStyle);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (snapshot.matchingConditionalStyles) {
|
|
235
|
+
for (const style of snapshot.matchingConditionalStyles) {
|
|
236
|
+
const newStyle = {
|
|
237
|
+
areas: [
|
|
238
|
+
{
|
|
239
|
+
workbookName: targetCell.workbookName,
|
|
240
|
+
sheetName: targetCell.sheetName,
|
|
241
|
+
range: {
|
|
242
|
+
start: { col: targetCell.colIndex, row: targetCell.rowIndex },
|
|
243
|
+
end: {
|
|
244
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
245
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
condition: style.condition
|
|
251
|
+
};
|
|
252
|
+
this.styleManager.addConditionalStyle(newStyle);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
copyCellContentFromSnapshot(snapshot, targetCell, sourceTopLeft, options) {
|
|
257
|
+
if (!snapshot.content) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
let targetContent;
|
|
261
|
+
const copyType = options.type ?? "formula";
|
|
262
|
+
if (copyType === "value") {
|
|
263
|
+
const evalResult = this.evaluationManager.getCellEvaluationResult(snapshot.address);
|
|
264
|
+
if (!evalResult || evalResult.type !== "value") {
|
|
265
|
+
targetContent = snapshot.content;
|
|
266
|
+
} else {
|
|
267
|
+
const result = evalResult.result;
|
|
268
|
+
if (result.type === "number") {
|
|
269
|
+
targetContent = result.value;
|
|
270
|
+
} else if (result.type === "string") {
|
|
271
|
+
targetContent = result.value;
|
|
272
|
+
} else if (result.type === "boolean") {
|
|
273
|
+
targetContent = result.value;
|
|
274
|
+
} else {
|
|
275
|
+
targetContent = snapshot.content;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
if (typeof snapshot.content === "string" && snapshot.content.startsWith("=")) {
|
|
280
|
+
targetContent = this.adjustFormulaReferences(snapshot.content, {
|
|
281
|
+
colIndex: snapshot.address.colIndex,
|
|
282
|
+
rowIndex: snapshot.address.rowIndex
|
|
283
|
+
}, {
|
|
284
|
+
colIndex: targetCell.colIndex,
|
|
285
|
+
rowIndex: targetCell.rowIndex
|
|
286
|
+
});
|
|
287
|
+
} else {
|
|
288
|
+
targetContent = snapshot.content;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const targetSheet = this.workbookManager.getSheet({
|
|
292
|
+
workbookName: targetCell.workbookName,
|
|
293
|
+
sheetName: targetCell.sheetName
|
|
294
|
+
});
|
|
295
|
+
if (targetSheet) {
|
|
296
|
+
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
297
|
+
targetSheet.content.set(targetKey, targetContent);
|
|
298
|
+
}
|
|
299
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
300
|
+
if (snapshot.metadata) {
|
|
301
|
+
this.workbookManager.setCellMetadata(targetCell, {
|
|
302
|
+
...snapshot.metadata
|
|
303
|
+
});
|
|
304
|
+
} else {
|
|
305
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
87
309
|
copyCellContent(sourceCell, targetCell, sourceTopLeft, options) {
|
|
88
310
|
const sheet = this.workbookManager.getSheet({
|
|
89
311
|
workbookName: sourceCell.workbookName,
|
|
@@ -98,7 +320,8 @@ class CopyManager {
|
|
|
98
320
|
return;
|
|
99
321
|
}
|
|
100
322
|
let targetContent;
|
|
101
|
-
|
|
323
|
+
const copyType = options.type ?? "formula";
|
|
324
|
+
if (copyType === "value") {
|
|
102
325
|
const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
|
|
103
326
|
if (!evalResult || evalResult.type !== "value") {
|
|
104
327
|
targetContent = cellContent;
|
|
@@ -135,6 +358,14 @@ class CopyManager {
|
|
|
135
358
|
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
136
359
|
targetSheet.content.set(targetKey, targetContent);
|
|
137
360
|
}
|
|
361
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
362
|
+
const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
|
|
363
|
+
if (sourceMetadata) {
|
|
364
|
+
this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
|
|
365
|
+
} else {
|
|
366
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
138
369
|
}
|
|
139
370
|
adjustFormulaReferences(formula, sourceAddress, targetAddress) {
|
|
140
371
|
try {
|
|
@@ -192,34 +423,42 @@ class CopyManager {
|
|
|
192
423
|
const allConditionalStyles = this.styleManager.getAllConditionalStyles();
|
|
193
424
|
const allCellStyles = this.styleManager.getAllCellStyles();
|
|
194
425
|
for (const style of allConditionalStyles) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
426
|
+
for (const area of style.areas) {
|
|
427
|
+
if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
|
|
428
|
+
const intersection = import_range_utils.intersectRanges(area.range, sourceRange);
|
|
429
|
+
if (intersection) {
|
|
430
|
+
const newStyle = {
|
|
431
|
+
areas: [
|
|
432
|
+
{
|
|
433
|
+
workbookName: target.workbookName,
|
|
434
|
+
sheetName: target.sheetName,
|
|
435
|
+
range: this.adjustRange(intersection, rowOffset, colOffset)
|
|
436
|
+
}
|
|
437
|
+
],
|
|
438
|
+
condition: style.condition
|
|
439
|
+
};
|
|
440
|
+
this.styleManager.addConditionalStyle(newStyle);
|
|
441
|
+
}
|
|
207
442
|
}
|
|
208
443
|
}
|
|
209
444
|
}
|
|
210
445
|
for (const style of allCellStyles) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
446
|
+
for (const area of style.areas) {
|
|
447
|
+
if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
|
|
448
|
+
const intersection = import_range_utils.intersectRanges(area.range, sourceRange);
|
|
449
|
+
if (intersection) {
|
|
450
|
+
const newStyle = {
|
|
451
|
+
areas: [
|
|
452
|
+
{
|
|
453
|
+
workbookName: target.workbookName,
|
|
454
|
+
sheetName: target.sheetName,
|
|
455
|
+
range: this.adjustRange(intersection, rowOffset, colOffset)
|
|
456
|
+
}
|
|
457
|
+
],
|
|
458
|
+
style: style.style
|
|
459
|
+
};
|
|
460
|
+
this.styleManager.addCellStyle(newStyle);
|
|
461
|
+
}
|
|
223
462
|
}
|
|
224
463
|
}
|
|
225
464
|
}
|
|
@@ -257,22 +496,15 @@ class CopyManager {
|
|
|
257
496
|
}
|
|
258
497
|
clearSourceCells(cells) {
|
|
259
498
|
for (const cell of cells) {
|
|
260
|
-
|
|
261
|
-
workbookName: cell.workbookName,
|
|
262
|
-
sheetName: cell.sheetName
|
|
263
|
-
});
|
|
264
|
-
if (sheet) {
|
|
265
|
-
const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
|
|
266
|
-
sheet.content.delete(key);
|
|
267
|
-
}
|
|
499
|
+
this.workbookManager.setCellContent(cell, "");
|
|
268
500
|
}
|
|
269
501
|
}
|
|
270
502
|
fillAreas(seedRange, targetRanges, options) {
|
|
271
503
|
for (const targetRange of targetRanges) {
|
|
272
504
|
this.fillRangeWithSeed(seedRange, targetRange, {
|
|
273
|
-
copyContent: options
|
|
274
|
-
copyStyles:
|
|
275
|
-
contentType: options.type,
|
|
505
|
+
copyContent: this.shouldInclude(options, "content"),
|
|
506
|
+
copyStyles: this.shouldInclude(options, "style"),
|
|
507
|
+
contentType: options.type ?? "formula",
|
|
276
508
|
adjustFormulas: true
|
|
277
509
|
});
|
|
278
510
|
}
|
|
@@ -308,7 +540,7 @@ class CopyManager {
|
|
|
308
540
|
this.copyCellContentWithOffset(seedCell, targetCell, rowDelta, colDelta, {
|
|
309
541
|
type: options.contentType,
|
|
310
542
|
cut: false,
|
|
311
|
-
|
|
543
|
+
include: ["content"]
|
|
312
544
|
});
|
|
313
545
|
}
|
|
314
546
|
if (options.copyStyles) {
|
|
@@ -346,7 +578,7 @@ class CopyManager {
|
|
|
346
578
|
this.copyCellContentWithOffset(sourceCell, targetCell, 0, colDelta, {
|
|
347
579
|
type: options.contentType,
|
|
348
580
|
cut: false,
|
|
349
|
-
|
|
581
|
+
include: ["content"]
|
|
350
582
|
});
|
|
351
583
|
}
|
|
352
584
|
if (options.copyStyles) {
|
|
@@ -419,7 +651,8 @@ class CopyManager {
|
|
|
419
651
|
return;
|
|
420
652
|
}
|
|
421
653
|
let targetContent;
|
|
422
|
-
|
|
654
|
+
const copyType = options.type ?? "formula";
|
|
655
|
+
if (copyType === "value") {
|
|
423
656
|
const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
|
|
424
657
|
if (!evalResult || evalResult.type !== "value") {
|
|
425
658
|
targetContent = cellContent;
|
|
@@ -450,6 +683,14 @@ class CopyManager {
|
|
|
450
683
|
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
451
684
|
targetSheet.content.set(targetKey, targetContent);
|
|
452
685
|
}
|
|
686
|
+
if (this.shouldInclude(options, "metadata")) {
|
|
687
|
+
const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
|
|
688
|
+
if (sourceMetadata) {
|
|
689
|
+
this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
|
|
690
|
+
} else {
|
|
691
|
+
this.workbookManager.setCellMetadata(targetCell, undefined);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
453
694
|
}
|
|
454
695
|
adjustFormulaWithOffset(formula, rowDelta, colDelta) {
|
|
455
696
|
try {
|
|
@@ -517,50 +758,64 @@ class CopyManager {
|
|
|
517
758
|
}
|
|
518
759
|
};
|
|
519
760
|
for (const style of allConditionalStyles) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
761
|
+
for (const area of style.areas) {
|
|
762
|
+
if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
|
|
763
|
+
const intersection = import_range_utils.intersectRanges(area.range, sourceCellRange);
|
|
764
|
+
if (intersection) {
|
|
765
|
+
const newStyle = {
|
|
766
|
+
areas: [
|
|
767
|
+
{
|
|
768
|
+
workbookName: targetCell.workbookName,
|
|
769
|
+
sheetName: targetCell.sheetName,
|
|
770
|
+
range: {
|
|
771
|
+
start: {
|
|
772
|
+
col: targetCell.colIndex,
|
|
773
|
+
row: targetCell.rowIndex
|
|
774
|
+
},
|
|
775
|
+
end: {
|
|
776
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
777
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
778
|
+
}
|
|
779
|
+
}
|
|
532
780
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
781
|
+
],
|
|
782
|
+
condition: style.condition
|
|
783
|
+
};
|
|
784
|
+
this.styleManager.addConditionalStyle(newStyle);
|
|
785
|
+
}
|
|
538
786
|
}
|
|
539
787
|
}
|
|
540
788
|
}
|
|
541
789
|
for (const style of allCellStyles) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
790
|
+
for (const area of style.areas) {
|
|
791
|
+
if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
|
|
792
|
+
const intersection = import_range_utils.intersectRanges(area.range, sourceCellRange);
|
|
793
|
+
if (intersection) {
|
|
794
|
+
const newStyle = {
|
|
795
|
+
areas: [
|
|
796
|
+
{
|
|
797
|
+
workbookName: targetCell.workbookName,
|
|
798
|
+
sheetName: targetCell.sheetName,
|
|
799
|
+
range: {
|
|
800
|
+
start: {
|
|
801
|
+
col: targetCell.colIndex,
|
|
802
|
+
row: targetCell.rowIndex
|
|
803
|
+
},
|
|
804
|
+
end: {
|
|
805
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
806
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
807
|
+
}
|
|
808
|
+
}
|
|
554
809
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
810
|
+
],
|
|
811
|
+
style: style.style
|
|
812
|
+
};
|
|
813
|
+
this.styleManager.addCellStyle(newStyle);
|
|
814
|
+
}
|
|
560
815
|
}
|
|
561
816
|
}
|
|
562
817
|
}
|
|
563
818
|
}
|
|
564
819
|
}
|
|
565
820
|
|
|
566
|
-
//# debugId=
|
|
821
|
+
//# debugId=97C1B0F68AA50A6E64756E2164756E21
|