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

X-original-commit: aed5b96
Signed-off-by: Rémi Rahir (rar) <[email protected]>
Signed-off-by: Vincent Schippefilt (vsc) <[email protected]>
  • Loading branch information
VincentSchippefilt committed Feb 7, 2024
1 parent c22e2e2 commit 8b0d079
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/plugins/core/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
format: cell.format ? getItemId<Format>(cell.format, formats) : undefined,
content: cell.content || undefined,
};
if (cell instanceof FormulaCellWithDependencies) {
cells[xc].content = cell.contentWithFixedReferences || undefined;
}
}
_sheet.cells = cells;
}
Expand Down Expand Up @@ -657,7 +654,7 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
}
}

class FormulaCellWithDependencies implements FormulaCell {
export class FormulaCellWithDependencies implements FormulaCell {
readonly isFormula = true;
readonly compiledFormula: RangeCompiledFormula;
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Zone,
invalidateDependenciesCommands,
} from "../../../types/index";
import { FormulaCellWithDependencies } from "../../core";
import { UIPlugin, UIPluginConfig } from "../../ui_plugin";
import { CoreViewCommand, invalidateEvaluationCommands } from "./../../../types/commands";
import { Evaluator } from "./evaluator";
Expand Down Expand Up @@ -281,7 +282,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 @@ -305,7 +305,12 @@ 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 = formulaCell.contentWithFixedReferences;
} else {
content = !isExported ? newContent : exportedCellData.content;
}
exportedSheetData.cells[xc] = { ...exportedCellData, value, isFormula, content, format };
}
}
Expand Down
56 changes: 56 additions & 0 deletions tests/model/__snapshots__/model.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Model export formula with unbound zone stays unbound 1`] = `
{
"borders": {},
"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": [],
"dataValidationRules": [],
"figures": [],
"filterTables": [],
"headerGroups": {
"COL": [],
"ROW": [],
},
"id": "Sheet1",
"isVisible": true,
"merges": [],
"name": "Sheet1",
"rowNumber": 100,
"rows": {},
},
],
"styles": {},
"uniqueFigureIds": true,
"version": 14,
}
`;
15 changes: 15 additions & 0 deletions tests/model/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,19 @@ describe("Model", () => {
"5"
);
});

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 8b0d079

Please sign in to comment.