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.

closes #4147

Task: 3895465
X-original-commit: c8df5d0
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
rrahir authored and LucasLefevre committed May 3, 2024
1 parent 6eb4353 commit e8d1444
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/plugins/core/cell.ts
Expand Up @@ -639,7 +639,7 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
}
}

export class FormulaCellWithDependencies implements FormulaCell {
class FormulaCellWithDependencies implements FormulaCell {
readonly isFormula = true;
readonly compiledFormula: RangeCompiledFormula;
constructor(
Expand Down
Expand Up @@ -19,7 +19,6 @@ import {
Zone,
invalidateDependenciesCommands,
} 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 @@ -313,8 +312,8 @@ export class EvaluationPlugin extends UIPlugin {
const format = newFormat
? getItemId<Format>(newFormat, data.formats)
: exportedCellData.format;
let content;
if (isFormula && formulaCell instanceof FormulaCellWithDependencies) {
let content: string | undefined;
if (isExported && isFormula && formulaCell?.compiledFormula.dependencies.length) {
content = this.getters.getFormulaCellContent(
exportedSheetData.id,
formulaCell.compiledFormula,
Expand Down
6 changes: 4 additions & 2 deletions tests/xlsx/xlsx_export.test.ts
@@ -1,4 +1,4 @@
import { functionRegistry } from "../../src/functions";
import { arg, functionRegistry } from "../../src/functions";
import { buildSheetLink, toXC } from "../../src/helpers";
import { createEmptyExcelWorkbookData } from "../../src/migrations/data";
import { Model } from "../../src/model";
Expand Down Expand Up @@ -739,7 +739,7 @@ describe("Test XLSX export", () => {

functionRegistry.add("NON.EXPORTABLE", {
description: "a non exportable formula",
args: [],
args: [arg('range (any, range<any>, ,default="a")', "")],
returns: ["NUMBER"],
compute: function (): number {
return 42;
Expand All @@ -751,10 +751,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 e8d1444

Please sign in to comment.