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 #3621

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 743ac9b commit 29b26c7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/plugins/core/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,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
10 changes: 10 additions & 0 deletions src/plugins/ui_core_views/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,16 @@ export class EvaluationPlugin extends UIPlugin {
if (cell.format !== evaluatedCell.format) {
exportedCellData.computedFormat = evaluatedCell.format;
}

// 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) {
exportedCellData.content = this.getters.buildFormulaContent(
sheet.id,
cell,
cell.dependencies,
true
);
}
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/__snapshots__/model.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Model export formula with unbound zone stays unbound 1`] = `
Object {
"borders": Object {},
"entities": Object {},
"formats": Object {},
"revisionId": "START_REVISION",
"sheets": Array [
Object {
"areGridLinesVisible": true,
"cells": Object {
"A1": Object {
"content": "=SUM(A3:3)",
"format": undefined,
"style": undefined,
},
"A2": Object {
"content": "=SUM(A3:A)",
"format": undefined,
"style": undefined,
},
},
"colNumber": 26,
"cols": Object {},
"conditionalFormats": Array [],
"figures": Array [],
"filterTables": Array [],
"id": "Sheet1",
"isVisible": true,
"merges": Array [],
"name": "Sheet1",
"rowNumber": 100,
"rows": Object {},
},
],
"styles": Object {},
"uniqueFigureIds": true,
"version": 13,
}
`;
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 29b26c7

Please sign in to comment.