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

Task: 3895465
X-original-commit: 0ef57de
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
rrahir authored and LucasLefevre committed May 3, 2024
1 parent 73595ee commit d6678ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Expand Up @@ -323,8 +323,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 instanceof FormulaCellWithDependencies) {
content = formulaCell.contentWithFixedReferences;
} else {
content = !isExported ? newContent : exportedCellData.content;
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 { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets";
import { Model } from "../../src/model";
Expand Down Expand Up @@ -751,7 +751,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 () {
return { value: 42, format: "0.00%" };
Expand All @@ -760,10 +760,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 d6678ac

Please sign in to comment.