Skip to content

Commit

Permalink
fix(formula): fix lookup bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 authored and wpxp123456 committed Oct 19, 2024
1 parent 83451b0 commit af7e40a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
17 changes: 12 additions & 5 deletions packages/engine-formula/src/engine/ast-node/function-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,21 @@ export class FunctionNode extends BaseAstNode {
return;
}

const lookupVectorOrArrayRange = (lookupVectorOrArray as BaseReferenceObject).getRangeData();
let lookupCountRow: number;
let lookupCountColumn: number;

const resultVectorRange = (resultVector as BaseReferenceObject).getRangeData();
if (lookupVectorOrArray?.isReferenceObject()) {
const lookupVectorOrArrayRange = (lookupVectorOrArray as BaseReferenceObject).getRangeData();
const { startRow, startColumn, endRow, endColumn } = lookupVectorOrArrayRange;

const { startRow, startColumn, endRow, endColumn } = lookupVectorOrArrayRange;
lookupCountRow = endRow - startRow + 1;
lookupCountColumn = endColumn - startColumn + 1;
} else {
lookupCountRow = lookupVectorOrArray?.isArray() ? (lookupVectorOrArray as ArrayValueObject).getRowCount() : 1;
lookupCountColumn = lookupVectorOrArray?.isArray() ? (lookupVectorOrArray as ArrayValueObject).getColumnCount() : 1;
}

const lookupCountRow = endRow - startRow + 1;
const lookupCountColumn = endColumn - startColumn + 1;
const resultVectorRange = (resultVector as BaseReferenceObject).getRangeData();

const { startRow: reStartRow, startColumn: reStartColumn, endRow: reEndRow, endColumn: reEndColumn } = resultVectorRange;

Expand Down
5 changes: 3 additions & 2 deletions packages/engine-formula/src/functions/base-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { BaseReferenceObject, FunctionVariantType, NodeValueType } from '..
import type { ArrayBinarySearchType } from '../engine/utils/compare';
import type { ArrayValueObject } from '../engine/value-object/array-value-object';
import type { IDefinedNameMapItem } from '../services/defined-names.service';

import { Disposable } from '@univerjs/core';

Check failure on line 24 in packages/engine-formula/src/functions/base-function.ts

View workflow job for this annotation

GitHub Actions / eslint

'Disposable' is defined but never used
import { ErrorType } from '../basics/error-type';
import { regexTestSingeRange, regexTestSingleColumn, regexTestSingleRow } from '../basics/regex';
import { compareToken } from '../basics/token';
Expand Down Expand Up @@ -288,7 +288,8 @@ export class BaseFunction {
}

if (resultValue.isNull()) {
return ErrorValueObject.create(ErrorType.NA);
// return ErrorValueObject.create(ErrorType.NA);
return NumberValueObject.create(0);
}

return resultValue;
Expand Down
4 changes: 2 additions & 2 deletions packages/engine-formula/src/functions/lookup/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

import type { Nullable } from '@univerjs/core';

import { ErrorType } from '../../../basics/error-type';
import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
import { ErrorType } from '../../../basics/error-type';
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';

export class Lookup extends BaseFunction {
override minParams = 2;
Expand Down

0 comments on commit af7e40a

Please sign in to comment.