diff --git a/src/plugins/core/cell.ts b/src/plugins/core/cell.ts index f1267d9a6c..4850d78a56 100644 --- a/src/plugins/core/cell.ts +++ b/src/plugins/core/cell.ts @@ -266,9 +266,6 @@ export class CellPlugin extends CorePlugin implements CoreState { format: cell.format ? getItemId(cell.format, formats) : undefined, content: cell.content || undefined, }; - if (cell instanceof FormulaCellWithDependencies) { - cells[xc].content = cell.contentWithFixedReferences || undefined; - } } _sheet.cells = cells; } @@ -657,7 +654,7 @@ export class CellPlugin extends CorePlugin implements CoreState { } } -class FormulaCellWithDependencies implements FormulaCell { +export class FormulaCellWithDependencies implements FormulaCell { readonly isFormula = true; readonly compiledFormula: RangeCompiledFormula; constructor( diff --git a/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts b/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts index 1757866a38..3f30cc1b08 100644 --- a/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts +++ b/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts @@ -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"; @@ -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; @@ -305,7 +305,12 @@ export class EvaluationPlugin extends UIPlugin { const format = newFormat ? getItemId(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 }; } } diff --git a/tests/model/__snapshots__/model.test.ts.snap b/tests/model/__snapshots__/model.test.ts.snap new file mode 100644 index 0000000000..a734a0f311 --- /dev/null +++ b/tests/model/__snapshots__/model.test.ts.snap @@ -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, +} +`; diff --git a/tests/model/model.test.ts b/tests/model/model.test.ts index 4434ed02d1..01425c0b95 100644 --- a/tests/model/model.test.ts +++ b/tests/model/model.test.ts @@ -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(); + }); });