Skip to content

Commit

Permalink
[FIX] Export xlsx: export value for non-exportable formulas
Browse files Browse the repository at this point in the history
The recent fix in #3622
combined with a slight refactoring of the export for Excel in
#2090 let to a situation where
cells with non-exportable formulas containing references did not have
their content replaced by the evaluated result.

Task: 3895465
X-original-commit: c8df5d0
  • Loading branch information
rrahir committed Apr 27, 2024
1 parent 1f97287 commit ed2bdf3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,19 @@ export class EvaluationPlugin extends UIPlugin {
const format = newFormat
? getItemId<Format>(newFormat, data.formats)
: exportedCellData.format;
<<<<<<< HEAD
let content;
if (isFormula && formulaCell instanceof FormulaCellWithDependencies) {
content = this.getters.getFormulaCellContent(
||||||| parent of e518d5b9b (temp)
let content;
if (formulaCell instanceof FormulaCellWithDependencies) {
content = this.getters.buildFormulaContent(
=======
let content: string | undefined;
if (isExported && formulaCell instanceof FormulaCellWithDependencies) {
content = this.getters.buildFormulaContent(
>>>>>>> e518d5b9b (temp)
exportedSheetData.id,
formulaCell.compiledFormula,
formulaCell.compiledFormula.dependencies,
Expand Down
24 changes: 23 additions & 1 deletion tests/xlsx/xlsx_export.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD:tests/xlsx/xlsx_export.test.ts
import { functionRegistry } from "../../src/functions";
import { buildSheetLink, toXC } from "../../src/helpers";
import { createEmptyExcelWorkbookData } from "../../src/migrations/data";
Expand All @@ -6,6 +7,25 @@ import { BasePlugin } from "../../src/plugins/base_plugin";
import { ExcelWorkbookData } from "../../src/types";
import { adaptFormulaToExcel } from "../../src/xlsx/functions/cells";
import { escapeXml, parseXML } from "../../src/xlsx/helpers/xml_helpers";
||||||| parent of e518d5b9b (temp):tests/xlsx_export.test.ts
import { functionRegistry } from "../src/functions";
import { buildSheetLink, toXC } from "../src/helpers";
import { createEmptyExcelWorkbookData } from "../src/migrations/data";
import { Model } from "../src/model";
import { BasePlugin } from "../src/plugins/base_plugin";
import { ExcelWorkbookData } from "../src/types";
import { adaptFormulaToExcel } from "../src/xlsx/functions/cells";
import { escapeXml, parseXML } from "../src/xlsx/helpers/xml_helpers";
=======
import { arg, functionRegistry } from "../src/functions";
import { buildSheetLink, toXC } from "../src/helpers";
import { createEmptyExcelWorkbookData } from "../src/migrations/data";
import { Model } from "../src/model";
import { BasePlugin } from "../src/plugins/base_plugin";
import { ExcelWorkbookData } from "../src/types";
import { adaptFormulaToExcel } from "../src/xlsx/functions/cells";
import { escapeXml, parseXML } from "../src/xlsx/helpers/xml_helpers";
>>>>>>> e518d5b9b (temp):tests/xlsx_export.test.ts
import {
createChart,
createFilter,
Expand Down Expand Up @@ -739,7 +759,7 @@ describe("Test XLSX export", () => {

functionRegistry.add("NON.EXPORTABLE", {
description: "a non exportable formula",
args: [],
args: [arg('range (any, range<any>, ,default="asdf")', "")],
returns: ["NUMBER"],
compute: function (): number {
return 42;
Expand All @@ -751,10 +771,12 @@ describe("Test XLSX export", () => {
});

setCellContent(model, "A1", "=1+NON.EXPORTABLE()");
setCellContent(model, "A2", "=1+NON.EXPORTABLE(A1)");

const exported = getExportedExcelData(model);

expect(exported.sheets[0].cells["A1"]?.content).toEqual("43");
expect(exported.sheets[0].cells["A2"]?.content).toEqual("43");
const formatId = exported.sheets[0].cells["A1"]?.format;
expect(formatId).toEqual(1);
expect(exported.formats[formatId!]).toEqual("0.00%");
Expand Down

0 comments on commit ed2bdf3

Please sign in to comment.