Skip to content

Commit

Permalink
[FIX] export: unbound formula stays unbound in snapshots
Browse files Browse the repository at this point in the history
In the PR #3364 I try to
fix the export to excel of unbound zones by fixing them. However I have
not taken into account the normal expor in spreadsheet that is done when
generating snapshot.

This fix keeps the unbound zones in snapshots, while convert them into
bound zones in excel export.

closes #3622

X-original-commit: 0ed2720
Signed-off-by: Rémi Rahir (rar) <[email protected]>
Signed-off-by: Vincent Schippefilt (vsc) <[email protected]>
  • Loading branch information
VincentSchippefilt committed Feb 6, 2024
1 parent b157972 commit b2452e3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/plugins/core/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
format: cell.format ? getItemId<Format>(cell.format, formats) : undefined,
content: cell.content || undefined,
};

// if there is a formula but no dependencies (maybe because the cell is in error), no need to recompute the formula text
if (cell.isFormula && cell.dependencies.length) {
cells[xc].content = this.buildFormulaContent(_sheet.id, cell, cell.dependencies, true);
}
}
_sheet.cells = cells;
}
Expand Down Expand Up @@ -606,7 +601,7 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
}
}

class FormulaCellWithDependencies {
export class FormulaCellWithDependencies {
readonly isFormula = true;
constructor(
readonly id: UID,
Expand Down
14 changes: 12 additions & 2 deletions src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
UID,
Zone,
} from "../../../types/index";
import { FormulaCellWithDependencies } from "../../core";
import { UIPlugin, UIPluginConfig } from "../../ui_plugin";
import { CoreViewCommand } from "./../../../types/commands";
import { Evaluator } from "./evaluator";
Expand Down Expand Up @@ -266,7 +267,6 @@ export class EvaluationPlugin extends UIPlugin {
const evaluatedCell = this.evaluator.getEvaluatedCell(position);

const xc = toXC(position.col, position.row);

const value = evaluatedCell.value;
let isFormula = false;
let newContent: string | undefined = undefined;
Expand All @@ -290,7 +290,17 @@ export class EvaluationPlugin extends UIPlugin {
const format = newFormat
? getItemId<Format>(newFormat, data.formats)
: exportedCellData.format;
const content = !isExported ? newContent : exportedCellData.content;
let content;
if (formulaCell instanceof FormulaCellWithDependencies) {
content = this.getters.buildFormulaContent(
exportedSheetData.id,
formulaCell,
formulaCell.dependencies,
true
);
} else {
content = !isExported ? newContent : exportedCellData.content;
}
exportedSheetData.cells[xc] = { ...exportedCellData, value, isFormula, content, format };
}
}
Expand Down
52 changes: 52 additions & 0 deletions tests/__snapshots__/model.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Model export formula with unbound zone stays unbound 1`] = `
{
"borders": {},
"entities": {},
"formats": {},
"revisionId": "START_REVISION",
"settings": {
"locale": {
"code": "en_US",
"dateFormat": "m/d/yyyy",
"decimalSeparator": ".",
"formulaArgSeparator": ",",
"name": "English (US)",
"thousandsSeparator": ",",
"timeFormat": "hh:mm:ss a",
},
},
"sheets": [
{
"areGridLinesVisible": true,
"cells": {
"A1": {
"content": "=SUM(A3:3)",
"format": undefined,
"style": undefined,
},
"A2": {
"content": "=SUM(A3:A)",
"format": undefined,
"style": undefined,
},
},
"colNumber": 26,
"cols": {},
"conditionalFormats": [],
"figures": [],
"filterTables": [],
"id": "Sheet1",
"isVisible": true,
"merges": [],
"name": "Sheet1",
"rowNumber": 100,
"rows": {},
},
],
"styles": {},
"uniqueFigureIds": true,
"version": 14,
}
`;
15 changes: 15 additions & 0 deletions tests/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,19 @@ describe("Model", () => {
);
corePluginRegistry.remove("myCorePlugin");
});

test("export formula with unbound zone stays unbound", () => {
const modelData = {
sheets: [
{
cells: {
A1: { content: "=SUM(A3:3)" },
A2: { content: "=SUM(A3:A)" },
},
},
],
};
const model = new Model(modelData);
expect(model.exportData()).toMatchSnapshot();
});
});

0 comments on commit b2452e3

Please sign in to comment.