Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] Export xlsx: export value for non-exportable formulas #4147

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/core/cell.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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