Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(formula): add functions, fix function calculation error (#1395)

Dushusir885ba4b18295
diff --git a/packages/core/src/shared/generate.ts b/packages/core/src/shared/generate.ts
index 80488d2dca..3c8f1a2cd7 100644
--- a/packages/core/src/shared/generate.ts
+++ b/packages/core/src/shared/generate.ts
@@ -19,7 +19,7 @@
* @param val The number or string to be judged
* @returns Result
*/
-export function isRealNum(val: string | number) {
+export function isRealNum(val: string | number | boolean) {
if (val === null || val.toString().replace(/\s/g, '') === '') {
return false;
}
diff --git a/packages/engine-formula/src/basics/__tests__/date.spec.ts b/packages/engine-formula/src/basics/__tests__/date.spec.ts
index f2832a4d3a..3cb015a85b 100644
--- a/packages/engine-formula/src/basics/__tests__/date.spec.ts
+++ b/packages/engine-formula/src/basics/__tests__/date.spec.ts
@@ -15,7 +15,7 @@
*/
import { describe, expect, it } from 'vitest';
-import { excelDateSerial, excelSerialToDate, formatDateDefault } from '../date';
+import { excelDateSerial, excelSerialToDate, formatDateDefault, isValidDateStr } from '../date';
describe('Test date', () => {
it('Function excelDateSerial', () => {
@@ -32,4 +32,10 @@ describe('Test date', () => {
expect(formatDateDefault(excelSerialToDate(367))).toBe('1901/01/01');
expect(formatDateDefault(excelSerialToDate(45324))).toBe('2024/02/02');
});
+ it('Function isValidDateStr', () => {
+ expect(isValidDateStr('2020-1-1')).toBeTruthy();
+ expect(isValidDateStr('2020/1/31')).toBeTruthy();
+ expect(isValidDateStr('2020-2-31')).toBeFalsy();
+ expect(isValidDateStr('2020/001/31')).toBeFalsy();
+ });
});
diff --git a/packages/engine-formula/src/basics/common.ts b/packages/engine-formula/src/basics/common.ts
index 8a6121de66..e0251ad62e 100644
--- a/packages/engine-formula/src/basics/common.ts
+++ b/packages/engine-formula/src/basics/common.ts
@@ -17,8 +17,11 @@
import type {
BooleanNumber,
ICellData,
+ IColumnData,
+ IObjectArrayPrimitiveType,
IObjectMatrixPrimitiveType,
IRange,
+ IRowData,
IUnitRange,
Nullable,
ObjectMatrix,
@@ -46,6 +49,8 @@ export interface ISheetItem {
cellData: ObjectMatrix<ICellData>;
rowCount: number;
columnCount: number;
+ rowData: IObjectArrayPrimitiveType<Partial<IRowData>>;
+ columnData: IObjectArrayPrimitiveType<Partial<IColumnData>>;
}
export interface ISheetData {
diff --git a/packages/engine-formula/src/basics/date.ts b/packages/engine-formula/src/basics/date.ts
index 9a3b3201de..8762704942 100644
--- a/packages/engine-formula/src/basics/date.ts
+++ b/packages/engine-formula/src/basics/date.ts
@@ -73,3 +73,38 @@ export function formatDateDefault(date: Date): string {
// Concatenate year, month, and day with '/' as separator to form yyyy/mm/dd format
return `${year}/${month}/${day}`;
}
+
+/**
+ * Validate date string
+ *
+ * TODO @Dushusir: Internationalization and more format support, can be reused when editing and saving cells, like "2020年1月1日"
+ * @param dateStr
+ * @returns
+ */
+export function isValidDateStr(dateStr: string): boolean {
+ // Regular expression to validate date format
+ const regex = /^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/;
+
+ // Check if the date format is correct
+ if (!regex.test(dateStr)) {
+ return false;
+ }
+ // Convert date string to local time format
+ const normalizedDateStr = dateStr.replace(/-/g, '/').replace(/T.+/, '');
+ const dateWithTime = new Date(`${normalizedDateStr}`);
+
+ // Check if the date is valid
+ if (Number.isNaN(dateWithTime.getTime())) {
+ return false;
+ }
+
+ // Convert the parsed date back to the same format as the original date string for comparison
+ const year = dateWithTime.getFullYear();
+ const month = (dateWithTime.getMonth() + 1).toString().padStart(2, '0');
+ const day = dateWithTime.getDate().toString().padStart(2, '0');
+ const reconstructedDateStr = `${year}-${month}-${day}`;
+
+ const dateStrPad = dateStr.replace(/\//g, '-').split('-').map((v) => v.padStart(2, '0')).join('-');
+
+ return dateStrPad === reconstructedDateStr;
+}
diff --git a/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts b/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts
index 3cfba249a7..8868104d4f 100644
--- a/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts
+++ b/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts
@@ -229,6 +229,8 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
cellData: new ObjectMatrix(sheetConfig.cellData),
rowCount: sheetConfig.rowCount,
columnCount: sheetConfig.columnCount,
+ rowData: sheetConfig.rowData,
+ columnData: sheetConfig.columnData,
};
});
diff --git a/packages/engine-formula/src/engine/ast-node/function-node.ts b/packages/engine-formula/src/engine/ast-node/function-node.ts
index 6ff8bc5011..0a4e043e48 100644
--- a/packages/engine-formula/src/engine/ast-node/function-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/function-node.ts
@@ -104,10 +104,14 @@ export class FunctionNode extends BaseAstNode {
for (let i = 0; i < childrenCount; i++) {
const object = children[i].getValue();
+
if (object == null) {
continue;
}
- if (object.isReferenceObject()) {
+
+ // In the SUBTOTAL function, we need to get rowData information, we can only use ReferenceObject
+ if (object.isReferenceObject() && !this._functionExecutor.needsReferenceObject) {
+ // Array converted from reference object needs to be marked
variants.push((object as BaseReferenceObject).toArrayValueObject());
} else {
variants.push(object as BaseValueObject);
@@ -139,7 +143,7 @@ export class FunctionNode extends BaseAstNode {
const children = this.getChildren();
const childrenCount = children.length;
- if (this._functionExecutor.name !== 'LOOKUP' || childrenCount !== 3) {
+ if (!this._functionExecutor.needsExpandParams || childrenCount !== 3) {
return;
}
diff --git a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
index efa9f0ca81..fa58b8d4a1 100644
--- a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
+++ b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
@@ -321,6 +321,14 @@ export class BaseReferenceObject extends ObjectClassType {
return this.getCurrentActiveSheetData().columnCount;
}
+ getRowData() {
+ return this.getCurrentActiveSheetData().rowData;
+ }
+
+ getColumnData() {
+ return this.getCurrentActiveSheetData().columnData;
+ }
+
isCell() {
return false;
}
diff --git a/packages/engine-formula/src/engine/utils/__tests__/math-kit.spec.ts b/packages/engine-formula/src/engine/utils/__tests__/math-kit.spec.ts
new file mode 100644
index 0000000000..677adee4be
--- /dev/null
+++ b/packages/engine-formula/src/engine/utils/__tests__/math-kit.spec.ts
@@ -0,0 +1,29 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+import { truncateNumber } from '../math-kit';
+
+describe('Test math kit', () => {
+ it('Function truncateNumber', () => {
+ expect(truncateNumber('1234567890123456')).toBe(1234567890123450);
+ expect(truncateNumber('123.4567890123456789')).toBe(123.456789012345);
+ expect(truncateNumber('0.1234567890123456789')).toBe(0.123456789012345);
+ expect(truncateNumber('1.234567890123456e+20')).toBe(123456789012345000000);
+ expect(truncateNumber('123456789012345')).toBe(123456789012345);
+ expect(truncateNumber('0.000000000000123456')).toBe(0.000000000000123456);
+ });
+});
diff --git a/packages/engine-formula/src/engine/utils/__tests__/object-covert.spec.ts b/packages/engine-formula/src/engine/utils/__tests__/object-covert.spec.ts
new file mode 100644
index 0000000000..93fd1d95d7
--- /dev/null
+++ b/packages/engine-formula/src/engine/utils/__tests__/object-covert.spec.ts
@@ -0,0 +1,27 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { convertTonNumber } from '../object-covert';
+import { BooleanValueObject } from '../../value-object/primitive-object';
+
+describe('Test object cover', () => {
+ it('Function convertTonNumber', () => {
+ expect(convertTonNumber(new BooleanValueObject(true)).getValue()).toBe(1);
+ expect(convertTonNumber(new BooleanValueObject(false)).getValue()).toBe(0);
+ });
+});
diff --git a/packages/engine-formula/src/engine/utils/math-kit.ts b/packages/engine-formula/src/engine/utils/math-kit.ts
index 1a9ce50b6c..b8d5c0c0c8 100644
--- a/packages/engine-formula/src/engine/utils/math-kit.ts
+++ b/packages/engine-formula/src/engine/utils/math-kit.ts
@@ -46,6 +46,50 @@ export function ceil(base: number, precision: number): number {
return Math.ceil(multiply(base, factor)) / factor;
}
+export function mod(base: number, divisor: number): number {
+ const bigNumber = new Big(base);
+ const bigDivisor = new Big(divisor);
+
+ const quotient = Math.floor(base / divisor);
+
+ const result = bigNumber.minus(bigDivisor.times(quotient));
+
+ return result.toNumber();
+}
+
export function pow(base: number, exponent: number): number {
return base ** exponent;
}
+
+/**
+ * Excel can display numbers with up to about 15 digits of precision. This includes the sum of the integer part and the decimal part
+ * @param input
+ * @returns
+ */
+export function truncateNumber(input: number | string): number {
+ const num = new Big(input);
+ const numStr = num.toFixed(); // Convert to fixed-point notation
+
+ const parts = numStr.split('.');
+ let integerPart = parts[0];
+ let decimalPart = parts.length > 1 ? parts[1] : '';
+
+ // Handle integer part greater than 15 digits
+ if (integerPart.length > 15) {
+ integerPart = integerPart.slice(0, 15) + '0'.repeat(integerPart.length - 15);
+ }
+
+ // Handle decimal part for numbers with an integer part of '0' and leading zeros
+ if (integerPart === '0') {
+ const nonZeroIndex = decimalPart.search(/[1-9]/); // Find the first non-zero digit
+ if (nonZeroIndex !== -1 && nonZeroIndex + 15 < decimalPart.length) {
+ decimalPart = decimalPart.slice(0, nonZeroIndex + 15);
+ }
+ } else if (integerPart.length + decimalPart.length > 15) {
+ // Adjust decimal part if total length exceeds 15
+ decimalPart = decimalPart.slice(0, 15 - integerPart.length);
+ }
+
+ // Convert back to number, may cause precision loss for very large or small numbers
+ return Number.parseFloat(integerPart + (decimalPart ? `.${decimalPart}` : ''));
+}
diff --git a/packages/engine-formula/src/engine/utils/object-covert.ts b/packages/engine-formula/src/engine/utils/object-covert.ts
new file mode 100644
index 0000000000..346c55b3ef
--- /dev/null
+++ b/packages/engine-formula/src/engine/utils/object-covert.ts
@@ -0,0 +1,27 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { BaseValueObject } from '../value-object/base-value-object';
+import { NumberValueObject } from '../value-object/primitive-object';
+
+export function convertTonNumber(valueObject: BaseValueObject) {
+ const currentValue = valueObject.getValue();
+ let result = 0;
+ if (currentValue) {
+ result = 1;
+ }
+ return new NumberValueObject(result, true);
+}
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts
index 735052b709..4e47110b78 100644
--- a/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts
@@ -103,7 +103,7 @@ describe('arrayValueObject test', () => {
});
expect(originValueObject.count()?.getValue()).toBe(6);
});
- it('CountA', () => {
+ it('Counta', () => {
const originValueObject = new ArrayValueObject({
calculateValueList: transformToValueObject([
[1, ' ', 1.23, true, false],
diff --git a/packages/engine-formula/src/engine/value-object/array-value-object.ts b/packages/engine-formula/src/engine/value-object/array-value-object.ts
index 4cd31708c7..34111a420d 100644
--- a/packages/engine-formula/src/engine/value-object/array-value-object.ts
+++ b/packages/engine-formula/src/engine/value-object/array-value-object.ts
@@ -32,6 +32,7 @@ enum BatchOperatorType {
PLUS,
MULTIPLY,
DIVIDED,
+ MOD,
COMPARE,
CONCATENATE_FRONT,
CONCATENATE_BACK,
@@ -753,7 +754,8 @@ export class ArrayValueObject extends BaseValueObject {
return false; // break
}
- if (valueObject.isString() || valueObject.isNull()) {
+ // ignore boolean value in array, but not ignore in normal value object
+ if (valueObject.isString() || valueObject.isNull() || valueObject.isBoolean()) {
return true; // continue
}
@@ -780,7 +782,8 @@ export class ArrayValueObject extends BaseValueObject {
return false; // break
}
- if (valueObject.isString() || valueObject.isNull()) {
+ // ignore boolean value in array, but not ignore in normal value object
+ if (valueObject.isString() || valueObject.isNull() || valueObject.isBoolean()) {
return true; // continue
}
@@ -862,6 +865,19 @@ export class ArrayValueObject extends BaseValueObject {
return this._batchOperator(valueObject, BatchOperatorType.DIVIDED);
}
+ override mod(valueObject: BaseValueObject): BaseValueObject {
+ return this._batchOperator(valueObject, BatchOperatorType.MOD);
+ }
+
+ override modInverse(valueObject: BaseValueObject): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return valueObject.mod(currentValue);
+ });
+ }
+
override compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject {
return this._batchOperator(valueObject, BatchOperatorType.COMPARE, operator);
}
@@ -1052,13 +1068,13 @@ export class ArrayValueObject extends BaseValueObject {
});
}
- override mean(): BaseValueObject {
+ override mean(ddof: number = 0): BaseValueObject {
const sum = this.sum();
// Like sum, ignore strings and booleans
const count = this.count();
- return sum.divided(count);
+ return sum.divided(ddof === 0 ? count : count.minusBy(1));
}
override median(): BaseValueObject {
@@ -1084,20 +1100,31 @@ export class ArrayValueObject extends BaseValueObject {
return allValue.get(0, (count - 1) / 2);
}
- // TODO ddof, ignore strings and booleans
- override var(): BaseValueObject {
+ /**
+ * ┌──────────────┬────────────────────────────────┬───────────────────┐
+ * │ Function │ Ignore logical values and text │ Type │
+ * ├──────────────┼────────────────────────────────┼───────────────────┤
+ * │ VAR.S (VAR) │ TRUE │ sample │
+ * │ VAR.P (VARP) │ TRUE │ entire population │
+ * │ VARA │ FALSE │ sample │
+ * │ VARPA │ FALSE │ entire population │
+ * └──────────────┴────────────────────────────────┴───────────────────┘
+ *
+ * for VARPA and VARA, strings and FALSE are counted as 0, TRUE is counted as 1
+ * for VAR.S/VAR, or VAR.P/VARP, strings,TRUE and FALSE are ignored
+ * Since sum ignores strings and booleans, they are ignored here too, and VAR.S and VAR.P are used more
+ *
+ * VAR.S assumes that its arguments are a sample of the population, like numpy.var(data, ddof=1)
+ * VAR.P assumes that its arguments are the entire population, like numpy.var(data, ddof=0)
+ * numpy.var uses ddof=0 (Delta Degrees of Freedom) by default, so we use ddof=0 here
+ *
+ */
+ override var(ddof: number = 0): BaseValueObject {
const mean = this.mean();
// let isError = null;
const squaredDifferences: BaseValueObject[][] = [[]];
this.iterator((valueObject: Nullable<BaseValueObject>) => {
- // for VARPA and VARA, strings and FALSE are counted as 0, TRUE is counted as 1
- // for VAR.S/VAR, or VAR.P/VARP, strings,TRUE and FALSE are ignored
- // Since sum ignores strings and booleans, they are ignored here too, and VAR.S and VAR.P are used more
-
- // VAR.S assumes that its arguments are a sample of the population, like numpy.var(data, ddof=1)
- // VAR.P assumes that its arguments are the entire population, like numpy.var(data, ddof=0)
- // numpy.var uses ddof=0 by default, so we use ddof=0 here
if (valueObject == null || valueObject.isError() || valueObject.isString() || valueObject.isBoolean() || valueObject.isNull()) {
return;
}
@@ -1111,7 +1138,7 @@ export class ArrayValueObject extends BaseValueObject {
squaredDifferences[0].push(baseValueObject);
});
- const { _rowCount, _columnCount, _unitId, _sheetId, _currentRow, _currentColumn } = this;
+ const { _unitId, _sheetId, _currentRow, _currentColumn } = this;
const squaredDifferencesArrayObject = new ArrayValueObject({
calculateValueList: squaredDifferences,
@@ -1123,19 +1150,19 @@ export class ArrayValueObject extends BaseValueObject {
column: _currentColumn,
});
- return squaredDifferencesArrayObject.mean();
+ return squaredDifferencesArrayObject.mean(ddof);
}
/**
- * STDEV.P: ddof=0, ignore strings and booleans
- * STDEV.S: ddof=1, ignore strings and booleans
+ * STDEV.P (STDEVP): ddof=0, ignore strings and booleans
+ * STDEV.S (STDEV): ddof=1, ignore strings and booleans
*
* STDEVPA: ddof=0,
* STDEVA: ddof=1,
* @returns
*/
- override std(): BaseValueObject {
- const variance = this.var();
+ override std(ddof: number = 0): BaseValueObject {
+ const variance = this.var(ddof);
if (variance.isError()) {
return variance;
@@ -1375,7 +1402,7 @@ export class ArrayValueObject extends BaseValueObject {
if (rowValuePositions != null) {
rowValuePositions.forEach((rowPositions, rowValue) => {
- let currentValue: Nullable<BaseValueObject>;
+ let currentValue: Nullable<BaseValueObject> = new NullValueObject(0); // handle blank cell
if (typeof rowValue === 'string') {
currentValue = new StringValueObject(rowValue);
} else if (typeof rowValue === 'number') {
@@ -1384,10 +1411,6 @@ export class ArrayValueObject extends BaseValueObject {
currentValue = new BooleanValueObject(rowValue);
}
- if (currentValue == null) {
- return true;
- }
-
const matchResult = currentValue.compare(valueObject, operator as compareToken);
if ((matchResult as BooleanValueObject).getValue() === true) {
rowPositions.forEach((index) => {
@@ -1450,6 +1473,9 @@ export class ArrayValueObject extends BaseValueObject {
case BatchOperatorType.DIVIDED:
result[r][column] = currentValue.divided(valueObject);
break;
+ case BatchOperatorType.MOD:
+ result[r][column] = currentValue.mod(valueObject);
+ break;
case BatchOperatorType.COMPARE:
if (!operator) {
result[r][column] = new ErrorValueObject(ErrorType.VALUE);
@@ -1598,6 +1624,9 @@ export class ArrayValueObject extends BaseValueObject {
case BatchOperatorType.DIVIDED:
rowList[c] = currentValue.divided(opValue);
break;
+ case BatchOperatorType.MOD:
+ rowList[c] = currentValue.mod(opValue);
+ break;
case BatchOperatorType.COMPARE:
if (!operator) {
rowList[c] = new ErrorValueObject(ErrorType.VALUE);
diff --git a/packages/engine-formula/src/engine/value-object/base-value-object.ts b/packages/engine-formula/src/engine/value-object/base-value-object.ts
index 1e58c81349..b99f173f1c 100644
--- a/packages/engine-formula/src/engine/value-object/base-value-object.ts
+++ b/packages/engine-formula/src/engine/value-object/base-value-object.ts
@@ -151,11 +151,26 @@ export class BaseValueObject extends ObjectClassType {
return new ErrorValueObject(ErrorType.NAME);
}
+ mod(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ /**
+ * return every value in the array after the callback function, excluding the error value
+ * @param callbackFn
+ * @returns
+ */
map(callbackFn: callbackMapFnType): BaseValueObject {
/** abstract */
return new ErrorValueObject(ErrorType.NAME);
}
+ /**
+ * return every value in the array after the callback function
+ * @param callbackFn
+ * @returns
+ */
mapValue(callbackFn: callbackMapFnType): BaseValueObject {
/** abstract */
return new ErrorValueObject(ErrorType.NAME);
@@ -224,6 +239,11 @@ export class BaseValueObject extends ObjectClassType {
return new ErrorValueObject(ErrorType.NAME);
}
+ modInverse(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
compareBy(value: string | number | boolean, operator: compareToken): BaseValueObject {
/** abstract */
return new ErrorValueObject(ErrorType.NAME);
diff --git a/packages/engine-formula/src/engine/value-object/primitive-object.ts b/packages/engine-formula/src/engine/value-object/primitive-object.ts
index 33596894a0..da4ced5066 100644
--- a/packages/engine-formula/src/engine/value-object/primitive-object.ts
+++ b/packages/engine-formula/src/engine/value-object/primitive-object.ts
@@ -21,7 +21,7 @@ import { BooleanValue, ConcatenateType } from '../../basics/common';
import { ERROR_TYPE_SET, ErrorType } from '../../basics/error-type';
import { compareToken } from '../../basics/token';
import { compareWithWildcard, isWildcard } from '../utils/compare';
-import { ceil, floor, pow, round } from '../utils/math-kit';
+import { ceil, floor, mod, pow, round } from '../utils/math-kit';
import { BaseValueObject, ErrorValueObject } from './base-value-object';
export type PrimitiveValueType = string | boolean | number | null;
@@ -47,6 +47,10 @@ export class NullValueObject extends BaseValueObject {
return new NumberValueObject(0, true).divided(valueObject);
}
+ override mod(valueObject: BaseValueObject): BaseValueObject {
+ return new NumberValueObject(0, true).mod(valueObject);
+ }
+
override compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject {
if (valueObject.isString()) {
return new StringValueObject('').compare(valueObject, operator);
@@ -251,6 +255,10 @@ export class BooleanValueObject extends BaseValueObject {
return this._convertTonNumber().divided(valueObject);
}
+ override mod(valueObject: BaseValueObject): BaseValueObject {
+ return this._convertTonNumber().mod(valueObject);
+ }
+
override compare(valueObject: BaseValueObject, operator: compareToken): BaseValueObject {
return this._convertTonNumber().compare(valueObject, operator);
}
@@ -457,6 +465,51 @@ export class NumberValueObject extends BaseValueObject {
return object;
}
+ override mod(valueObject: BaseValueObject): BaseValueObject {
+ if (valueObject.isArray()) {
+ return valueObject.modInverse(this);
+ }
+
+ const currentValue = this.getValue();
+ const value = valueObject.getValue();
+
+ if (valueObject.isNull()) {
+ return new ErrorValueObject(ErrorType.DIV_BY_ZERO);
+ }
+
+ if (typeof value === 'string') {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+ if (typeof value === 'number') {
+ if (value === 0) {
+ return new ErrorValueObject(ErrorType.DIV_BY_ZERO);
+ }
+
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return new ErrorValueObject(ErrorType.NUM);
+ }
+
+ const result = mod(currentValue, value);
+
+ if (!Number.isFinite(result)) {
+ return new ErrorValueObject(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+ if (typeof value === 'boolean') {
+ const booleanValue = value ? 1 : 0;
+
+ if (booleanValue === 0) {
+ return new ErrorValueObject(ErrorType.DIV_BY_ZERO);
+ }
+
+ return new NumberValueObject(mod(currentValue, booleanValue));
+ }
+
+ return this;
+ }
+
override concatenateFront(valueObject: BaseValueObject): BaseValueObject {
if (valueObject.isArray()) {
return valueObject.concatenateBack(this);
diff --git a/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts b/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts
index 3d8e9ad513..6c59089dc8 100644
--- a/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts
+++ b/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts
@@ -228,6 +228,8 @@ export function createFunctionTestBed(workbookConfig?: IWorkbookData, dependenci
cellData: new ObjectMatrix(sheetConfig.cellData),
rowCount: sheetConfig.rowCount,
columnCount: sheetConfig.columnCount,
+ rowData: sheetConfig.rowData,
+ columnData: sheetConfig.columnData,
};
});
diff --git a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts
index f2ccf25493..5d4f83f871 100644
--- a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts
+++ b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts
@@ -19,8 +19,6 @@ import { beforeEach, describe, expect, it } from 'vitest';
import type { IWorkbookData } from '@univerjs/core';
import { LocaleType } from '@univerjs/core';
-import type { ArrayValueObject, BaseValueObject, LexerNode } from '../..';
-import { FUNCTION_NAMES_DATE, FUNCTION_NAMES_LOGICAL, FUNCTION_NAMES_LOOKUP, FUNCTION_NAMES_MATH, FUNCTION_NAMES_STATISTICAL, FUNCTION_NAMES_TEXT, IFunctionService } from '../..';
import { Lexer } from '../../engine/analysis/lexer';
import { AstTreeBuilder } from '../../engine/analysis/parser';
import type { BaseAstNode } from '../../engine/ast-node/base-ast-node';
@@ -41,6 +39,16 @@ import { Plus } from '../meta/plus';
import { FUNCTION_NAMES_META } from '../meta/function-names';
import { Minus } from '../meta/minus';
import { Concatenate } from '../text/concatenate';
+import { FUNCTION_NAMES_LOGICAL } from '../logical/function-names';
+import { FUNCTION_NAMES_MATH } from '../math/function-names';
+import { FUNCTION_NAMES_LOOKUP } from '../lookup/function-names';
+import { FUNCTION_NAMES_STATISTICAL } from '../statistical/function-names';
+import { FUNCTION_NAMES_DATE } from '../date/function-names';
+import { FUNCTION_NAMES_TEXT } from '../text/function-names';
+import { IFunctionService } from '../../services/function.service';
+import type { ArrayValueObject } from '../../engine/value-object/array-value-object';
+import type { LexerNode } from '../../engine/analysis/lexer-node';
+import type { BaseValueObject } from '../../engine/value-object/base-value-object';
import { createFunctionTestBed } from './create-function-test-bed';
const getFunctionsTestWorkbookData = (): IWorkbookData => {
diff --git a/packages/engine-formula/src/functions/base-function.ts b/packages/engine-formula/src/functions/base-function.ts
index b62745b4dc..64ddaea7c7 100644
--- a/packages/engine-formula/src/functions/base-function.ts
+++ b/packages/engine-formula/src/functions/base-function.ts
@@ -15,7 +15,7 @@
*/
import type { Nullable } from '@univerjs/core';
-import { Disposable } from '@univerjs/core';
+import { Disposable, isRealNum } from '@univerjs/core';
import { ErrorType } from '../basics/error-type';
import type { IFunctionNames } from '../basics/function';
@@ -25,7 +25,9 @@ import type { ArrayBinarySearchType } from '../engine/utils/compare';
import { ArrayOrderSearchType } from '../engine/utils/compare';
import type { ArrayValueObject } from '../engine/value-object/array-value-object';
import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';
-import type { PrimitiveValueType } from '../engine/value-object/primitive-object';
+import { NumberValueObject, type PrimitiveValueType } from '../engine/value-object/primitive-object';
+import { convertTonNumber } from '../engine/utils/object-covert';
+import { createNewArray } from '../engine/utils/array-object';
export class BaseFunction extends Disposable {
private _unitId: Nullable<string>;
@@ -33,6 +35,16 @@ export class BaseFunction extends Disposable {
private _row: number = -1;
private _column: number = -1;
+ /**
+ * Whether the function needs to expand the parameters
+ */
+ needsExpandParams: boolean = false;
+
+ /**
+ * Whether the function needs to pass in reference object
+ */
+ needsReferenceObject: boolean = false;
+
constructor(private _name: IFunctionNames) {
super();
}
@@ -380,4 +392,84 @@ export class BaseFunction extends Disposable {
}
return resultArray.slice(undefined, [position.column, position.column + 1]);
}
+
+ flattenArray(variants: BaseValueObject[], ignoreLogicalValuesAndText: boolean = true): ArrayValueObject | BaseValueObject {
+ const flattenValues: BaseValueObject[][] = [];
+ flattenValues[0] = [];
+
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isError()) {
+ return variant;
+ }
+
+ if (variant.isString()) {
+ const value = variant.getValue();
+ const isStringNumber = isRealNum(value);
+
+ if (!isStringNumber) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ variant = new NumberValueObject(value);
+ }
+
+ if (variant.isBoolean()) {
+ variant = convertTonNumber(variant);
+ }
+
+ if (variant.isNull()) {
+ variant = new NumberValueObject(0);
+ }
+
+ if (variant.isArray()) {
+ let errorValue: Nullable<BaseValueObject>;
+
+ (variant as ArrayValueObject).iterator((valueObject) => {
+ if (valueObject == null || valueObject.isNull()) {
+ return true;
+ }
+
+ if (ignoreLogicalValuesAndText && (valueObject.isString() || valueObject.isBoolean())) {
+ return true;
+ }
+
+ valueObject = this._includingLogicalValuesAndText(valueObject);
+
+ if (valueObject.isError()) {
+ errorValue = valueObject;
+ return false;
+ }
+
+ flattenValues[0].push(valueObject);
+ });
+
+ if (errorValue?.isError()) {
+ return errorValue;
+ }
+ } else {
+ flattenValues[0].push(variant);
+ }
+ }
+
+ return createNewArray(flattenValues, 1, flattenValues[0].length);
+ }
+
+ private _includingLogicalValuesAndText(valueObject: BaseValueObject) {
+ // Including logical values
+ if (valueObject.isBoolean()) {
+ valueObject = convertTonNumber(valueObject);
+ }
+
+ // Including number string
+ if (valueObject.isString()) {
+ const value = Number(valueObject.getValue());
+
+ // Non-text numbers also need to be counted to the sample size
+ valueObject = new NumberValueObject(isNaN(value) ? 0 : value);
+ }
+
+ return valueObject;
+ }
}
diff --git a/packages/engine-formula/src/functions/compatibility/function-map.ts b/packages/engine-formula/src/functions/compatibility/function-map.ts
index 98e1a1308d..d7b1206aba 100644
--- a/packages/engine-formula/src/functions/compatibility/function-map.ts
+++ b/packages/engine-formula/src/functions/compatibility/function-map.ts
@@ -14,4 +14,15 @@
* limitations under the License.
*/
-export const functionCompatibility = [];
+import { StdevP } from '../statistical/stdev-p';
+import { StdevS } from '../statistical/stdev-s';
+import { VarP } from '../statistical/var-p';
+import { VarS } from '../statistical/var-s';
+import { FUNCTION_NAMES_COMPATIBILITY } from './function-names';
+
+export const functionCompatibility = [
+ [StdevS, FUNCTION_NAMES_COMPATIBILITY.STDEV],
+ [StdevP, FUNCTION_NAMES_COMPATIBILITY.STDEVP],
+ [VarS, FUNCTION_NAMES_COMPATIBILITY.VAR],
+ [VarP, FUNCTION_NAMES_COMPATIBILITY.VARP],
+];
diff --git a/packages/engine-formula/src/functions/date/date/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/date/__tests__/index.spec.ts
index ede45fc13e..a6ac6cd2aa 100644
--- a/packages/engine-formula/src/functions/date/date/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/date/date/__tests__/index.spec.ts
@@ -20,7 +20,7 @@ import { FUNCTION_NAMES_DATE } from '../../function-names';
import { DateFunction } from '..';
import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
-import { ErrorType } from '../../../..';
+import { ErrorType } from '../../../../basics/error-type';
describe('Test date function', () => {
const textFunction = new DateFunction(FUNCTION_NAMES_DATE.DATE);
diff --git a/packages/engine-formula/src/functions/date/day/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/day/__tests__/index.spec.ts
index 35f966ef85..df8ed1a081 100644
--- a/packages/engine-formula/src/functions/date/day/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/date/day/__tests__/index.spec.ts
@@ -18,7 +18,7 @@ import { describe, expect, it } from 'vitest';
import { FUNCTION_NAMES_DATE } from '../../function-names';
import { Day } from '..';
-import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
describe('Test day function', () => {
@@ -26,9 +26,15 @@ describe('Test day function', () => {
describe('Day', () => {
it('Serial number is normal', () => {
- const serialNumber = new NumberValueObject(43831);
+ const serialNumber = new NumberValueObject(43832);
const result = textFunction.calculate(serialNumber);
- expect(result.getValue()).toStrictEqual(1);
+ expect(result.getValue()).toStrictEqual(2);
+ });
+
+ it('Serial number is date string', () => {
+ const serialNumber = new StringValueObject('2020-01-02');
+ const result = textFunction.calculate(serialNumber);
+ expect(result.getValue()).toStrictEqual(2);
});
it('Serial number is array', () => {
@@ -43,7 +49,7 @@ describe('Test day function', () => {
column: 0,
});
const result = textFunction.calculate(serialNumber);
- expect(transformToValue(result.getArrayValue())).toStrictEqual([[1, '#VALUE!', 1, 1, 0, '#VALUE!'], [0, 9, 2, '#VALUE!', '#NUM!', 14]]);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([[1, '#VALUE!', 1, 1, 0, 0], [0, 9, 2, '#VALUE!', '#NUM!', 14]]);
});
});
});
diff --git a/packages/engine-formula/src/functions/date/day/index.ts b/packages/engine-formula/src/functions/date/day/index.ts
index 999913a041..cd917e85c9 100644
--- a/packages/engine-formula/src/functions/date/day/index.ts
+++ b/packages/engine-formula/src/functions/date/day/index.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { excelSerialToDate } from '../../../basics/date';
+import { excelSerialToDate, isValidDateStr } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
@@ -27,41 +27,46 @@ export class Day extends BaseFunction {
return new ErrorValueObject(ErrorType.NA);
}
- if (serialNumber.isError()) {
- return serialNumber;
+ if (serialNumber.isArray()) {
+ return serialNumber.map((serialNumberObject) => this._handleSingleObject(serialNumberObject));
}
- if (serialNumber.isArray()) {
- return serialNumber.map((serialNumberObject) => {
- if (serialNumberObject.isError()) {
- return serialNumberObject;
- }
+ return this._handleSingleObject(serialNumber);
+ }
- if (serialNumberObject.isString() || serialNumberObject.isNull()) {
- return new ErrorValueObject(ErrorType.VALUE);
- }
+ private _handleSingleObject(serialNumberObject: BaseValueObject) {
+ if (serialNumberObject.isError()) {
+ return serialNumberObject;
+ }
- const dateSerial = +serialNumberObject.getValue();
+ let date: Date;
+ const dateValue = serialNumberObject.getValue();
- if (dateSerial < 0) {
- return new ErrorValueObject(ErrorType.NUM);
- }
+ if (serialNumberObject.isString()) {
+ if (!isValidDateStr(`${dateValue}`)) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
- // Excel serial 0 is 1900-01-00
- // Google Sheets serial 0 is 1899-12-30
- if (dateSerial === 0) {
- return new NumberValueObject(0);
- }
+ date = new Date(`${dateValue}`);
+ } else {
+ const dateSerial = +serialNumberObject.getValue();
- const date = excelSerialToDate(dateSerial);
+ if (dateSerial < 0) {
+ return new ErrorValueObject(ErrorType.NUM);
+ }
- const month = date.getDate();
- const valueObject = new NumberValueObject(month);
+ // Excel serial 0 is 1900-01-00
+ // Google Sheets serial 0 is 1899-12-30
+ if (dateSerial === 0) {
+ return new NumberValueObject(0);
+ }
- return valueObject;
- });
+ date = excelSerialToDate(dateSerial);
}
- return new NumberValueObject(excelSerialToDate(+serialNumber.getValue()).getDate());
+ const month = date.getDate();
+ const valueObject = new NumberValueObject(month);
+
+ return valueObject;
}
}
diff --git a/packages/engine-formula/src/functions/date/month/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/month/__tests__/index.spec.ts
index a95e803403..2370623cbf 100644
--- a/packages/engine-formula/src/functions/date/month/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/date/month/__tests__/index.spec.ts
@@ -18,7 +18,7 @@ import { describe, expect, it } from 'vitest';
import { FUNCTION_NAMES_DATE } from '../../function-names';
import { Month } from '..';
-import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
describe('Test month function', () => {
@@ -31,6 +31,12 @@ describe('Test month function', () => {
expect(result.getValue()).toStrictEqual(1);
});
+ it('Serial number is date string', () => {
+ const serialNumber = new StringValueObject('2020-01-02');
+ const result = textFunction.calculate(serialNumber);
+ expect(result.getValue()).toStrictEqual(1);
+ });
+
it('Serial number is array', () => {
const serialNumber = new ArrayValueObject({
calculateValueList: transformToValueObject([[1, ' ', 1.23, true, false, null],
diff --git a/packages/engine-formula/src/functions/date/month/index.ts b/packages/engine-formula/src/functions/date/month/index.ts
index 93e2cf86f5..1cba9decf9 100644
--- a/packages/engine-formula/src/functions/date/month/index.ts
+++ b/packages/engine-formula/src/functions/date/month/index.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { excelSerialToDate } from '../../../basics/date';
+import { excelSerialToDate, isValidDateStr } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
@@ -27,41 +27,46 @@ export class Month extends BaseFunction {
return new ErrorValueObject(ErrorType.NA);
}
- if (serialNumber.isError()) {
- return serialNumber;
+ if (serialNumber.isArray()) {
+ return serialNumber.map((serialNumberObject) => this._handleSingleObject(serialNumberObject));
}
- if (serialNumber.isArray()) {
- return serialNumber.map((serialNumberObject) => {
- if (serialNumberObject.isError()) {
- return serialNumberObject;
- }
+ return this._handleSingleObject(serialNumber);
+ }
- if (serialNumberObject.isString()) {
- return new ErrorValueObject(ErrorType.VALUE);
- }
+ private _handleSingleObject(serialNumberObject: BaseValueObject) {
+ if (serialNumberObject.isError()) {
+ return serialNumberObject;
+ }
- const dateSerial = +serialNumberObject.getValue();
+ let date: Date;
+ const dateValue = serialNumberObject.getValue();
- if (dateSerial < 0) {
- return new ErrorValueObject(ErrorType.NUM);
- }
+ if (serialNumberObject.isString()) {
+ if (!isValidDateStr(`${dateValue}`)) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
- // Excel serial 0 is 1900-01-00
- // Google Sheets serial 0 is 1899-12-30
- if (dateSerial === 0) {
- return new NumberValueObject(1);
- }
+ date = new Date(`${dateValue}`);
+ } else {
+ const dateSerial = +serialNumberObject.getValue();
- const date = excelSerialToDate(dateSerial);
+ if (dateSerial < 0) {
+ return new ErrorValueObject(ErrorType.NUM);
+ }
- const month = date.getUTCMonth() + 1;
- const valueObject = new NumberValueObject(month);
+ // Excel serial 0 is 1900-01-00
+ // Google Sheets serial 0 is 1899-12-30
+ if (dateSerial === 0) {
+ return new NumberValueObject(1);
+ }
- return valueObject;
- });
+ date = excelSerialToDate(dateSerial);
}
- return new NumberValueObject(excelSerialToDate(+serialNumber.getValue()).getUTCMonth() + 1);
+ const month = date.getUTCMonth() + 1;
+ const valueObject = new NumberValueObject(month);
+
+ return valueObject;
}
}
diff --git a/packages/engine-formula/src/functions/date/year/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/year/__tests__/index.spec.ts
index e0e41e4771..ef76ab6527 100644
--- a/packages/engine-formula/src/functions/date/year/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/date/year/__tests__/index.spec.ts
@@ -18,7 +18,7 @@ import { describe, expect, it } from 'vitest';
import { FUNCTION_NAMES_DATE } from '../../function-names';
import { Year } from '..';
-import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
describe('Test year function', () => {
@@ -30,6 +30,11 @@ describe('Test year function', () => {
const result = textFunction.calculate(serialNumber);
expect(result.getValue()).toStrictEqual(2020);
});
+ it('Serial number is date string', () => {
+ const serialNumber = new StringValueObject('2020-01-02');
+ const result = textFunction.calculate(serialNumber);
+ expect(result.getValue()).toStrictEqual(2020);
+ });
it('Serial number is array', () => {
const serialNumber = new ArrayValueObject({
diff --git a/packages/engine-formula/src/functions/date/year/index.ts b/packages/engine-formula/src/functions/date/year/index.ts
index 4e2210e56b..ad85e24413 100644
--- a/packages/engine-formula/src/functions/date/year/index.ts
+++ b/packages/engine-formula/src/functions/date/year/index.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { excelSerialToDate } from '../../../basics/date';
+import { excelSerialToDate, isValidDateStr } from '../../../basics/date';
import { ErrorType } from '../../../basics/error-type';
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
@@ -27,41 +27,46 @@ export class Year extends BaseFunction {
return new ErrorValueObject(ErrorType.NA);
}
- if (serialNumber.isError()) {
- return serialNumber;
+ if (serialNumber.isArray()) {
+ return serialNumber.map((serialNumberObject) => this._handleSingleObject(serialNumberObject));
}
- if (serialNumber.isArray()) {
- return serialNumber.map((serialNumberObject, rowIndex, columnIndex) => {
- if (serialNumberObject.isError()) {
- return serialNumberObject;
- }
+ return this._handleSingleObject(serialNumber);
+ }
- if (serialNumberObject.isString()) {
- return new ErrorValueObject(ErrorType.VALUE);
- }
+ private _handleSingleObject(serialNumberObject: BaseValueObject) {
+ if (serialNumberObject.isError()) {
+ return serialNumberObject;
+ }
- const dateSerial = +serialNumberObject.getValue();
+ let date: Date;
+ const dateValue = serialNumberObject.getValue();
- if (dateSerial < 0) {
- return new ErrorValueObject(ErrorType.NUM);
- }
+ if (serialNumberObject.isString()) {
+ if (!isValidDateStr(`${dateValue}`)) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
- // Excel serial 0 is 1900-01-00
- // Google Sheets serial 0 is 1899-12-30
- if (dateSerial === 0) {
- return new NumberValueObject(1900);
- }
+ date = new Date(`${dateValue}`);
+ } else {
+ const dateSerial = +dateValue;
- const date = excelSerialToDate(dateSerial);
+ if (dateSerial < 0) {
+ return new ErrorValueObject(ErrorType.NUM);
+ }
- const year = date.getUTCFullYear();
- const valueObject = new NumberValueObject(year);
+ // Excel serial 0 is 1900-01-00
+ // Google Sheets serial 0 is 1899-12-30
+ if (dateSerial === 0) {
+ return new NumberValueObject(1900);
+ }
- return valueObject;
- });
+ date = excelSerialToDate(dateSerial);
}
- return new NumberValueObject(excelSerialToDate(+serialNumber.getValue()).getUTCFullYear());
+ const year = date.getUTCFullYear();
+ const valueObject = new NumberValueObject(year);
+
+ return valueObject;
}
}
diff --git a/packages/engine-formula/src/functions/information/function-map.ts b/packages/engine-formula/src/functions/information/function-map.ts
index f632d641c0..cc505e92d4 100644
--- a/packages/engine-formula/src/functions/information/function-map.ts
+++ b/packages/engine-formula/src/functions/information/function-map.ts
@@ -16,7 +16,23 @@
import { FUNCTION_NAMES_INFORMATION } from './function-names';
import { Isblank } from './isblank';
+import { Iserr } from './iserr';
+import { Iserror } from './iserror';
+import { Islogical } from './islogical';
+import { Isna } from './isna';
+import { Isnontext } from './isnontext';
+import { Isnumber } from './isnumber';
+import { Isref } from './isref';
+import { Istext } from './istext';
export const functionInformation = [
[Isblank, FUNCTION_NAMES_INFORMATION.ISBLANK],
+ [Iserr, FUNCTION_NAMES_INFORMATION.ISERR],
+ [Iserror, FUNCTION_NAMES_INFORMATION.ISERROR],
+ [Islogical, FUNCTION_NAMES_INFORMATION.ISLOGICAL],
+ [Isna, FUNCTION_NAMES_INFORMATION.ISNA],
+ [Isnontext, FUNCTION_NAMES_INFORMATION.ISNONTEXT],
+ [Isnumber, FUNCTION_NAMES_INFORMATION.ISNUMBER],
+ [Isref, FUNCTION_NAMES_INFORMATION.ISREF],
+ [Istext, FUNCTION_NAMES_INFORMATION.ISTEXT],
];
diff --git a/packages/engine-formula/src/functions/information/isblank/index.ts b/packages/engine-formula/src/functions/information/isblank/index.ts
index ad0ab2d3fa..a4284a078c 100644
--- a/packages/engine-formula/src/functions/information/isblank/index.ts
+++ b/packages/engine-formula/src/functions/information/isblank/index.ts
@@ -29,7 +29,7 @@ export class Isblank extends BaseFunction {
if (value.isNull()) {
return new BooleanValueObject(true);
} else if (value.isArray()) {
- return (value as ArrayValueObject).map((valueObject) => {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
if (valueObject.isNull()) {
return new BooleanValueObject(true);
}
diff --git a/packages/engine-formula/src/functions/information/iserr/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/iserr/__tests__/index.spec.ts
new file mode 100644
index 0000000000..5ed8687f9d
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/iserr/__tests__/index.spec.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Iserr } from '..';
+
+describe('Test iserr function', () => {
+ const textFunction = new Iserr(FUNCTION_NAMES_INFORMATION.ISERR);
+
+ describe('Iserr', () => {
+ it('value error', () => {
+ const value = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(value);
+ expect(result.getValue()).toBe(false);
+ });
+
+ it('value array', () => {
+ const value = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null, ErrorType.NA, ErrorType.DIV_BY_ZERO, ErrorType.SPILL, ErrorType.NULL],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE, ErrorType.REF, ErrorType.NUM, ErrorType.NAME, null],
+ ]),
+ rowCount: 2,
+ columnCount: 10,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [false, false, false, false, false, false, false, true, true, true],
+ [false, false, false, false, false, true, true, true, true, false],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/information/iserr/index.ts b/packages/engine-formula/src/functions/information/iserr/index.ts
new file mode 100644
index 0000000000..aa77aab806
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/iserr/index.ts
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Iserr extends BaseFunction {
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (value.getValue() === ErrorType.NA) {
+ return new BooleanValueObject(false);
+ }
+
+ if (value.isError()) {
+ return new BooleanValueObject(true);
+ } else if (value.isArray()) {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
+ if (valueObject.getValue() === ErrorType.NA) {
+ return new BooleanValueObject(false);
+ }
+
+ if (valueObject.isError()) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ });
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/information/iserror/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/iserror/__tests__/index.spec.ts
new file mode 100644
index 0000000000..fa9766ca72
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/iserror/__tests__/index.spec.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Iserror } from '..';
+
+describe('Test iserror function', () => {
+ const textFunction = new Iserror(FUNCTION_NAMES_INFORMATION.ISERROR);
+
+ describe('Iserror', () => {
+ it('value error', () => {
+ const value = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(value);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('value array', () => {
+ const value = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null, ErrorType.NA, ErrorType.DIV_BY_ZERO, ErrorType.SPILL, ErrorType.NULL],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE, ErrorType.REF, ErrorType.NUM, ErrorType.NAME, null],
+ ]),
+ rowCount: 2,
+ columnCount: 10,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [false, false, false, false, false, false, true, true, true, true],
+ [false, false, false, false, false, true, true, true, true, false],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/information/iserror/index.ts b/packages/engine-formula/src/functions/information/iserror/index.ts
new file mode 100644
index 0000000000..cd143ba94a
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/iserror/index.ts
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Iserror extends BaseFunction {
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (value.isError()) {
+ return new BooleanValueObject(true);
+ } else if (value.isArray()) {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
+ if (valueObject.isError()) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ });
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/information/islogical/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/islogical/__tests__/index.spec.ts
new file mode 100644
index 0000000000..8c751f0354
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/islogical/__tests__/index.spec.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Islogical } from '..';
+import { BooleanValueObject } from '../../../../engine/value-object/primitive-object';
+
+describe('Test islogical function', () => {
+ const textFunction = new Islogical(FUNCTION_NAMES_INFORMATION.ISLOGICAL);
+
+ describe('Islogical', () => {
+ it('value logical', () => {
+ const value = new BooleanValueObject(true);
+ const result = textFunction.calculate(value);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('value array', () => {
+ const value = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null, ErrorType.NA, ErrorType.DIV_BY_ZERO, ErrorType.SPILL, ErrorType.NULL],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE, ErrorType.REF, ErrorType.NUM, ErrorType.NAME, null],
+ ]),
+ rowCount: 2,
+ columnCount: 10,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [false, false, false, true, true, false, false, false, false, false],
+ [false, false, false, false, false, false, false, false, false, false],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/information/islogical/index.ts b/packages/engine-formula/src/functions/information/islogical/index.ts
new file mode 100644
index 0000000000..5d6152b95d
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/islogical/index.ts
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Islogical extends BaseFunction {
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (value.isBoolean()) {
+ return new BooleanValueObject(true);
+ } else if (value.isArray()) {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
+ if (valueObject.isBoolean()) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ });
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/information/isna/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isna/__tests__/index.spec.ts
new file mode 100644
index 0000000000..90daa65250
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isna/__tests__/index.spec.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Isna } from '..';
+
+describe('Test isna function', () => {
+ const textFunction = new Isna(FUNCTION_NAMES_INFORMATION.ISNA);
+
+ describe('Isna', () => {
+ it('value error', () => {
+ const value = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(value);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('value array', () => {
+ const value = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null, ErrorType.NA, ErrorType.DIV_BY_ZERO, ErrorType.SPILL, ErrorType.NULL],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE, ErrorType.REF, ErrorType.NUM, ErrorType.NAME, null],
+ ]),
+ rowCount: 2,
+ columnCount: 10,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [false, false, false, false, false, false, true, false, false, false],
+ [false, false, false, false, false, false, false, false, false, false],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/information/isna/index.ts b/packages/engine-formula/src/functions/information/isna/index.ts
new file mode 100644
index 0000000000..d6b38ce77b
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isna/index.ts
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Isna extends BaseFunction {
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (value.getValue() === ErrorType.NA) {
+ return new BooleanValueObject(true);
+ } else if (value.isArray()) {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
+ if (valueObject.getValue() === ErrorType.NA) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ });
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/information/isnontext/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isnontext/__tests__/index.spec.ts
new file mode 100644
index 0000000000..bd47f9ee87
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isnontext/__tests__/index.spec.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Isnontext } from '..';
+import { StringValueObject } from '../../../../engine/value-object/primitive-object';
+
+describe('Test isnontext function', () => {
+ const textFunction = new Isnontext(FUNCTION_NAMES_INFORMATION.ISNONTEXT);
+
+ describe('Isnontext', () => {
+ it('value text', () => {
+ const value = new StringValueObject('test');
+ const result = textFunction.calculate(value);
+ expect(result.getValue()).toBe(false);
+ });
+
+ it('value array', () => {
+ const value = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null, ErrorType.NA, ErrorType.DIV_BY_ZERO, ErrorType.SPILL, ErrorType.NULL],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE, ErrorType.REF, ErrorType.NUM, ErrorType.NAME, null],
+ ]),
+ rowCount: 2,
+ columnCount: 10,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [true, false, true, true, true, true, true, true, true, true],
+ [true, true, true, false, true, true, true, true, true, true],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/information/isnontext/index.ts b/packages/engine-formula/src/functions/information/isnontext/index.ts
new file mode 100644
index 0000000000..4c9cc58658
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isnontext/index.ts
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Isnontext extends BaseFunction {
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (!value.isArray() && !value.isString()) {
+ return new BooleanValueObject(true);
+ } else if (value.isArray()) {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
+ if (!valueObject.isString()) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ });
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/information/isnumber/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isnumber/__tests__/index.spec.ts
new file mode 100644
index 0000000000..bddb6090b9
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isnumber/__tests__/index.spec.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Isnumber } from '..';
+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+
+describe('Test isnumber function', () => {
+ const textFunction = new Isnumber(FUNCTION_NAMES_INFORMATION.ISNUMBER);
+
+ describe('Isnumber', () => {
+ it('value number', () => {
+ const value = new NumberValueObject(1);
+ const result = textFunction.calculate(value);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('value array', () => {
+ const value = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null, ErrorType.NA, ErrorType.DIV_BY_ZERO, ErrorType.SPILL, ErrorType.NULL],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE, ErrorType.REF, ErrorType.NUM, ErrorType.NAME, null],
+ ]),
+ rowCount: 2,
+ columnCount: 10,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [true, false, true, false, false, false, false, false, false, false],
+ [true, true, true, false, true, false, false, false, false, false],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/information/isnumber/index.ts b/packages/engine-formula/src/functions/information/isnumber/index.ts
new file mode 100644
index 0000000000..9c9b83de60
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isnumber/index.ts
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Isnumber extends BaseFunction {
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (value.isNumber()) {
+ return new BooleanValueObject(true);
+ } else if (value.isArray()) {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
+ if (valueObject.isNumber()) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ });
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts
new file mode 100644
index 0000000000..4e8938c16a
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts
@@ -0,0 +1,248 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import type { IWorkbookData } from '@univerjs/core';
+import { CellValueType, LocaleType } from '@univerjs/core';
+import { Lexer } from '../../../../engine/analysis/lexer';
+import type { LexerNode } from '../../../../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../../../../engine/analysis/parser';
+import type { BaseAstNode } from '../../../../engine/ast-node/base-ast-node';
+import { Interpreter } from '../../../../engine/interpreter/interpreter';
+import { IFormulaCurrentConfigService } from '../../../../services/current-data.service';
+import { IFunctionService } from '../../../../services/function.service';
+import { IFormulaRuntimeService } from '../../../../services/runtime.service';
+import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import type { BaseValueObject, ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { Isref } from '..';
+
+const getTestWorkbookData = (): IWorkbookData => {
+ return {
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: 2,
+ t: CellValueType.NUMBER,
+ },
+ },
+ 1: {
+ 0: {
+ v: 3,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: 4,
+ t: CellValueType.NUMBER,
+ },
+ 2: {
+ v: 'B2',
+ t: CellValueType.STRING,
+ },
+ 3: {
+ v: 'R2C2',
+ t: CellValueType.STRING,
+ },
+ },
+ 2: {
+ 0: {
+ v: 1,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: ' ',
+ t: CellValueType.STRING,
+ },
+ 2: {
+ v: 1.23,
+ t: CellValueType.NUMBER,
+ },
+ 3: {
+ v: true,
+ t: CellValueType.BOOLEAN,
+ },
+ 4: {
+ v: false,
+ t: CellValueType.BOOLEAN,
+ },
+ },
+ 3: {
+ 0: {
+ v: 0,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: '100',
+ },
+ 2: {
+ v: '2.34',
+ },
+ 3: {
+ v: 'test',
+ t: CellValueType.STRING,
+ },
+ 4: {
+ v: -3,
+ t: CellValueType.NUMBER,
+ },
+ },
+ 5: {
+ 0: {
+ v: 'Tom',
+ t: CellValueType.STRING,
+ },
+ 1: {
+ v: 'Sarah',
+ t: CellValueType.STRING,
+ },
+ },
+ 6: {
+ 0: {
+ v: 'Alex',
+ t: CellValueType.STRING,
+ },
+ 1: {
+ v: 'Mickey',
+ t: CellValueType.STRING,
+ },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ };
+};
+describe('Test isref function', () => {
+ let get: Injector['get'];
+ let lexer: Lexer;
+ let astTreeBuilder: AstTreeBuilder;
+ let interpreter: Interpreter;
+ let calculate: (formula: string) => Promise<(string | number | boolean | null)[][] | string | number | boolean>;
+
+ beforeEach(() => {
+ const testBed = createFunctionTestBed(getTestWorkbookData());
+
+ get = testBed.get;
+
+ lexer = get(Lexer);
+ astTreeBuilder = get(AstTreeBuilder);
+ interpreter = get(Interpreter);
+
+ const functionService = get(IFunctionService);
+
+ const formulaCurrentConfigService = get(IFormulaCurrentConfigService);
+
+ const formulaRuntimeService = get(IFormulaRuntimeService);
+
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ forceCalculate: false,
+ numfmtItemMap: {},
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyUnitFeatureMap: {},
+ excludedCell: {},
+ allUnitData: {
+ [testBed.unitId]: testBed.sheetData,
+ },
+ });
+
+ const sheetItem = testBed.sheetData[testBed.sheetId];
+
+ formulaRuntimeService.setCurrent(
+ 0,
+ 0,
+ sheetItem.rowCount,
+ sheetItem.columnCount,
+ testBed.sheetId,
+ testBed.unitId
+ );
+
+ functionService.registerExecutors(
+ new Isref(FUNCTION_NAMES_INFORMATION.ISREF)
+ );
+
+ calculate = async (formula: string) => {
+ const lexerNode = lexer.treeBuilder(formula);
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ if ((result as ErrorValueObject).isError()) {
+ return (result as ErrorValueObject).getValue();
+ } else if ((result as ArrayValueObject).isArray()) {
+ return (result as ArrayValueObject).toValue();
+ }
+ return (result as BaseValueObject).getValue();
+ };
+ });
+
+ describe('Isref', () => {
+ it('value reference single cell', async () => {
+ const result = await calculate('=ISREF(A1)');
+
+ expect(result).toBe(true);
+ });
+
+ it('value reference range', async () => {
+ const result = await calculate('=ISREF(A6:B6)');
+
+ expect(result).toBe(true);
+ });
+
+ it('value reference wrong cell', async () => {
+ const result = await calculate('=ISREF(XYZ1)');
+
+ expect(result).toBe(false);
+ });
+
+ it('value reference text', async () => {
+ const result = await calculate('=ISREF("A1")');
+
+ expect(result).toBe(false);
+ });
+
+ it('value reference logical', async () => {
+ const result = await calculate('=ISREF(TRUE)');
+
+ expect(result).toBe(false);
+ });
+
+ it('value reference number', async () => {
+ const result = await calculate('=ISREF(1)');
+
+ expect(result).toBe(false);
+ });
+ });
+ // supports array string
+});
diff --git a/packages/engine-formula/src/functions/information/isref/index.ts b/packages/engine-formula/src/functions/information/isref/index.ts
new file mode 100644
index 0000000000..de91983e53
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/isref/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { BooleanValueObject } from '../../..';
+import { ErrorType } from '../../../basics/error-type';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Isref extends BaseFunction {
+ override needsReferenceObject = true;
+
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (value.isReferenceObject()) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/information/istext/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/istext/__tests__/index.spec.ts
new file mode 100644
index 0000000000..b466d54f23
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/istext/__tests__/index.spec.ts
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_INFORMATION } from '../../function-names';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Istext } from '..';
+import { StringValueObject } from '../../../../engine/value-object/primitive-object';
+
+describe('Test istext function', () => {
+ const textFunction = new Istext(FUNCTION_NAMES_INFORMATION.ISTEXT);
+
+ describe('Istext', () => {
+ it('value text', () => {
+ const value = new StringValueObject('test');
+ const result = textFunction.calculate(value);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('value array', () => {
+ const value = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null, ErrorType.NA, ErrorType.DIV_BY_ZERO, ErrorType.SPILL, ErrorType.NULL],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE, ErrorType.REF, ErrorType.NUM, ErrorType.NAME, null],
+ ]),
+ rowCount: 2,
+ columnCount: 10,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [false, true, false, false, false, false, false, false, false, false],
+ [false, false, false, true, false, false, false, false, false, false],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/information/istext/index.ts b/packages/engine-formula/src/functions/information/istext/index.ts
new file mode 100644
index 0000000000..e1adcfe647
--- /dev/null
+++ b/packages/engine-formula/src/functions/information/istext/index.ts
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Istext extends BaseFunction {
+ override calculate(value: BaseValueObject) {
+ if (value == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (value.isString()) {
+ return new BooleanValueObject(true);
+ } else if (value.isArray()) {
+ return (value as ArrayValueObject).mapValue((valueObject) => {
+ if (valueObject.isString()) {
+ return new BooleanValueObject(true);
+ }
+
+ return new BooleanValueObject(false);
+ });
+ }
+
+ return new BooleanValueObject(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts
new file mode 100644
index 0000000000..1a462e9b89
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts
@@ -0,0 +1,151 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import { Lexer } from '../../../../engine/analysis/lexer';
+import type { LexerNode } from '../../../../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../../../../engine/analysis/parser';
+import type { BaseAstNode } from '../../../../engine/ast-node/base-ast-node';
+import { Interpreter } from '../../../../engine/interpreter/interpreter';
+import { IFormulaCurrentConfigService } from '../../../../services/current-data.service';
+import { IFunctionService } from '../../../../services/function.service';
+import { IFormulaRuntimeService } from '../../../../services/runtime.service';
+import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Column } from '..';
+import type { BaseValueObject, ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+
+describe('Test column', () => {
+ let get: Injector['get'];
+ let lexer: Lexer;
+ let astTreeBuilder: AstTreeBuilder;
+ let interpreter: Interpreter;
+
+ beforeEach(() => {
+ const testBed = createFunctionTestBed();
+
+ get = testBed.get;
+
+ lexer = get(Lexer);
+ astTreeBuilder = get(AstTreeBuilder);
+ interpreter = get(Interpreter);
+
+ const functionService = get(IFunctionService);
+
+ const formulaCurrentConfigService = get(IFormulaCurrentConfigService);
+
+ const formulaRuntimeService = get(IFormulaRuntimeService);
+
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ forceCalculate: false,
+ numfmtItemMap: {},
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyUnitFeatureMap: {},
+ excludedCell: {},
+ allUnitData: {
+ [testBed.unitId]: testBed.sheetData,
+ },
+ });
+
+ const sheetItem = testBed.sheetData[testBed.sheetId];
+
+ formulaRuntimeService.setCurrent(
+ 0,
+ 0,
+ sheetItem.rowCount,
+ sheetItem.columnCount,
+ testBed.sheetId,
+ testBed.unitId
+ );
+
+ functionService.registerExecutors(
+ new Column(FUNCTION_NAMES_LOOKUP.COLUMN)
+ );
+ });
+
+ describe('Column', () => {
+ it('No reference', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMN()');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toStrictEqual(1);
+ });
+ it('Reference single cell', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMN(C1)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ArrayValueObject).toValue()).toStrictEqual([[3]]);
+ });
+ it('Reference array cell', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMN(C2:F3)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ArrayValueObject).toValue()).toStrictEqual([[3, 4, 5, 6]]);
+ });
+ it('Text parameters', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMN("A5")');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Boolean params TRUE', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMN(TRUE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Boolean params FALSE', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMN(FALSE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Number params', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMN(11)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/column/index.ts b/packages/engine-formula/src/functions/lookup/column/index.ts
new file mode 100644
index 0000000000..bf64e3d022
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/column/index.ts
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import type { BaseValueObject, IArrayValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Column extends BaseFunction {
+ override calculate(
+ reference?: BaseValueObject
+ ) {
+ if (reference == null) {
+ return new NumberValueObject(this.column + 1);
+ }
+
+ if (reference.isError()) {
+ return reference;
+ }
+
+ if (!reference.isArray()) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const column = (reference as ArrayValueObject).getCurrentColumn();
+ const columnCount = (reference as ArrayValueObject).getColumnCount();
+
+ const calculateValueList = [];
+ for (let i = 0; i < columnCount; i++) {
+ calculateValueList.push(new NumberValueObject(column + i + 1));
+ }
+
+ const arrayValueObjectData: IArrayValueObject = {
+ calculateValueList: [calculateValueList],
+ rowCount: 1,
+ columnCount,
+ unitId: this.unitId || '',
+ sheetId: this.subUnitId || '',
+ row: this.row,
+ column: this.column,
+ };
+
+ return new ArrayValueObject(arrayValueObjectData);
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts
new file mode 100644
index 0000000000..ceaf6b70b3
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts
@@ -0,0 +1,150 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import { Lexer } from '../../../../engine/analysis/lexer';
+import type { LexerNode } from '../../../../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../../../../engine/analysis/parser';
+import type { BaseAstNode } from '../../../../engine/ast-node/base-ast-node';
+import { Interpreter } from '../../../../engine/interpreter/interpreter';
+import { IFormulaCurrentConfigService } from '../../../../services/current-data.service';
+import { IFunctionService } from '../../../../services/function.service';
+import { IFormulaRuntimeService } from '../../../../services/runtime.service';
+import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Columns } from '..';
+import type { BaseValueObject, ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test columns', () => {
+ let get: Injector['get'];
+ let lexer: Lexer;
+ let astTreeBuilder: AstTreeBuilder;
+ let interpreter: Interpreter;
+
+ beforeEach(() => {
+ const testBed = createFunctionTestBed();
+
+ get = testBed.get;
+
+ lexer = get(Lexer);
+ astTreeBuilder = get(AstTreeBuilder);
+ interpreter = get(Interpreter);
+
+ const functionService = get(IFunctionService);
+
+ const formulaCurrentConfigService = get(IFormulaCurrentConfigService);
+
+ const formulaRuntimeService = get(IFormulaRuntimeService);
+
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ forceCalculate: false,
+ numfmtItemMap: {},
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyUnitFeatureMap: {},
+ excludedCell: {},
+ allUnitData: {
+ [testBed.unitId]: testBed.sheetData,
+ },
+ });
+
+ const sheetItem = testBed.sheetData[testBed.sheetId];
+
+ formulaRuntimeService.setCurrent(
+ 0,
+ 0,
+ sheetItem.rowCount,
+ sheetItem.columnCount,
+ testBed.sheetId,
+ testBed.unitId
+ );
+
+ functionService.registerExecutors(
+ new Columns(FUNCTION_NAMES_LOOKUP.COLUMNS)
+ );
+ });
+
+ describe('Columns', () => {
+ it('Reference single cell', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMNS(C1)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Reference array cell', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMNS(C2:F3)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(4);
+ });
+ it('No reference', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMNS()');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Text params', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMNS("A5")');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Boolean params TRUE', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMNS(TRUE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Boolean params FALSE', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMNS(FALSE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Number params', async () => {
+ const lexerNode = lexer.treeBuilder('=COLUMNS(11)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/columns/index.ts b/packages/engine-formula/src/functions/lookup/columns/index.ts
new file mode 100644
index 0000000000..ba3ffe6548
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/columns/index.ts
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Columns extends BaseFunction {
+ override calculate(
+ reference?: BaseValueObject
+ ) {
+ if (reference == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (reference.isError()) {
+ return reference;
+ }
+
+ if (reference.isString() || reference.isNumber() || reference.isBoolean()) {
+ return new NumberValueObject(1);
+ }
+
+ if (!reference.isArray()) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const columnCount = (reference as ArrayValueObject).getColumnCount();
+
+ return new NumberValueObject(columnCount);
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/function-map.ts b/packages/engine-formula/src/functions/lookup/function-map.ts
index 38337a9979..090acfb602 100644
--- a/packages/engine-formula/src/functions/lookup/function-map.ts
+++ b/packages/engine-formula/src/functions/lookup/function-map.ts
@@ -15,20 +15,30 @@
*/
import { Address } from './address';
+import { Column } from './column';
+import { Columns } from './columns';
import { FUNCTION_NAMES_LOOKUP } from './function-names';
import { Hlookup } from './hlookup';
import { Indirect } from './indirect';
import { Lookup } from './lookup';
import { Match } from './match';
import { Offset } from './offset';
+import { Row } from './row';
+import { Rows } from './rows';
import { Vlookup } from './vlookup';
import { Xlookup } from './xlookup';
import { Xmatch } from './xmatch';
+import { Index } from './index';
export const functionLookup = [
[Address, FUNCTION_NAMES_LOOKUP.ADDRESS],
+ [Column, FUNCTION_NAMES_LOOKUP.COLUMN],
+ [Columns, FUNCTION_NAMES_LOOKUP.COLUMNS],
+ [Index, FUNCTION_NAMES_LOOKUP.INDEX],
[Indirect, FUNCTION_NAMES_LOOKUP.INDIRECT],
[Offset, FUNCTION_NAMES_LOOKUP.OFFSET],
+ [Row, FUNCTION_NAMES_LOOKUP.ROW],
+ [Rows, FUNCTION_NAMES_LOOKUP.ROWS],
[Vlookup, FUNCTION_NAMES_LOOKUP.VLOOKUP],
[Lookup, FUNCTION_NAMES_LOOKUP.LOOKUP],
[Match, FUNCTION_NAMES_LOOKUP.MATCH],
diff --git a/packages/engine-formula/src/functions/lookup/hlookup/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/hlookup/__tests__/index.spec.ts
index 7503e5c794..dfc354a21e 100644
--- a/packages/engine-formula/src/functions/lookup/hlookup/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/lookup/hlookup/__tests__/index.spec.ts
@@ -69,7 +69,7 @@ describe('Test hlookup', () => {
new NumberValueObject(3),
new NumberValueObject(0)
) as BaseValueObject;
- expect(resultObject.getValue().toString()).toBe(ErrorType.VALUE);
+ expect(resultObject.getValue().toString()).toBe(ErrorType.REF);
});
it('Not match', async () => {
@@ -122,7 +122,7 @@ describe('Test hlookup', () => {
arrayValueObject1.clone(),
new NumberValueObject(3)
) as BaseValueObject;
- expect(resultObject.getValue().toString()).toBe(ErrorType.VALUE);
+ expect(resultObject.getValue().toString()).toBe(ErrorType.REF);
});
it('Approximate not match', async () => {
@@ -154,4 +154,14 @@ describe('Test hlookup', () => {
expect(resultObject.getValue().toString()).toBe('Third');
});
});
+ describe('Error', () => {
+ it('TableArray is number', () => {
+ const result = textFunction.calculate(
+ new NumberValueObject(1),
+ new NumberValueObject(1),
+ new NumberValueObject(1)
+ );
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+ });
});
diff --git a/packages/engine-formula/src/functions/lookup/hlookup/index.ts b/packages/engine-formula/src/functions/lookup/hlookup/index.ts
index 2c9c52906d..edf8064bcd 100644
--- a/packages/engine-formula/src/functions/lookup/hlookup/index.ts
+++ b/packages/engine-formula/src/functions/lookup/hlookup/index.ts
@@ -40,7 +40,7 @@ export class Hlookup extends BaseFunction {
}
if (!tableArray.isArray()) {
- return new ErrorValueObject(ErrorType.VALUE);
+ return new ErrorValueObject(ErrorType.NA);
}
if (rowIndexNum.isError()) {
@@ -68,13 +68,11 @@ export class Hlookup extends BaseFunction {
const resultArray = (tableArray as ArrayValueObject).slice([rowIndexNumValue - 1, rowIndexNumValue]);
if (searchArray == null || resultArray == null) {
- return new ErrorValueObject(ErrorType.VALUE);
+ return new ErrorValueObject(ErrorType.REF);
}
if (lookupValue.isArray()) {
- return lookupValue.map((value) => {
- return this._handleSingleObject(value, searchArray, resultArray, rangeLookupValue);
- });
+ return lookupValue.map((value) => this._handleSingleObject(value, searchArray, resultArray, rangeLookupValue));
}
return this._handleSingleObject(lookupValue, searchArray, resultArray, rangeLookupValue);
diff --git a/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts b/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts
new file mode 100644
index 0000000000..8b8d435238
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts
@@ -0,0 +1,723 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import type { IWorkbookData } from '@univerjs/core';
+import { CellValueType, LocaleType } from '@univerjs/core';
+import { Lexer } from '../../../../engine/analysis/lexer';
+import type { LexerNode } from '../../../../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../../../../engine/analysis/parser';
+import type { BaseAstNode } from '../../../../engine/ast-node/base-ast-node';
+import { Interpreter } from '../../../../engine/interpreter/interpreter';
+import { IFormulaCurrentConfigService } from '../../../../services/current-data.service';
+import { IFunctionService } from '../../../../services/function.service';
+import { IFormulaRuntimeService } from '../../../../services/runtime.service';
+import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import type { BaseValueObject, ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { Index } from '..';
+import { ErrorType } from '../../../../basics/error-type';
+
+const getTestWorkbookData = (): IWorkbookData => {
+ return {
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: 2,
+ t: CellValueType.NUMBER,
+ },
+ },
+ 1: {
+ 0: {
+ v: 3,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: 4,
+ t: CellValueType.NUMBER,
+ },
+ 2: {
+ v: 'B2',
+ t: CellValueType.STRING,
+ },
+ 3: {
+ v: 'R2C2',
+ t: CellValueType.STRING,
+ },
+ },
+ 2: {
+ 0: {
+ v: 1,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: ' ',
+ t: CellValueType.STRING,
+ },
+ 2: {
+ v: 1.23,
+ t: CellValueType.NUMBER,
+ },
+ 3: {
+ v: true,
+ t: CellValueType.BOOLEAN,
+ },
+ 4: {
+ v: false,
+ t: CellValueType.BOOLEAN,
+ },
+ },
+ 3: {
+ 0: {
+ v: 0,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: '100',
+ },
+ 2: {
+ v: '2.34',
+ },
+ 3: {
+ v: 'test',
+ t: CellValueType.STRING,
+ },
+ 4: {
+ v: -3,
+ t: CellValueType.NUMBER,
+ },
+ },
+ 5: {
+ 0: {
+ v: 'Tom',
+ t: CellValueType.STRING,
+ },
+ 1: {
+ v: 'Sarah',
+ t: CellValueType.STRING,
+ },
+ },
+ 6: {
+ 0: {
+ v: 'Alex',
+ t: CellValueType.STRING,
+ },
+ 1: {
+ v: 'Mickey',
+ t: CellValueType.STRING,
+ },
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ };
+};
+describe('Test index', () => {
+ let get: Injector['get'];
+ let lexer: Lexer;
+ let astTreeBuilder: AstTreeBuilder;
+ let interpreter: Interpreter;
+ let calculate: (formula: string) => Promise<(string | number | boolean | null)[][] | string | number | boolean>;
+
+ beforeEach(() => {
+ const testBed = createFunctionTestBed(getTestWorkbookData());
+
+ get = testBed.get;
+
+ lexer = get(Lexer);
+ astTreeBuilder = get(AstTreeBuilder);
+ interpreter = get(Interpreter);
+
+ const functionService = get(IFunctionService);
+
+ const formulaCurrentConfigService = get(IFormulaCurrentConfigService);
+
+ const formulaRuntimeService = get(IFormulaRuntimeService);
+
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ forceCalculate: false,
+ numfmtItemMap: {},
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyUnitFeatureMap: {},
+ excludedCell: {},
+ allUnitData: {
+ [testBed.unitId]: testBed.sheetData,
+ },
+ });
+
+ const sheetItem = testBed.sheetData[testBed.sheetId];
+
+ formulaRuntimeService.setCurrent(
+ 0,
+ 0,
+ sheetItem.rowCount,
+ sheetItem.columnCount,
+ testBed.sheetId,
+ testBed.unitId
+ );
+
+ functionService.registerExecutors(
+ new Index(FUNCTION_NAMES_LOOKUP.INDEX)
+ );
+
+ calculate = async (formula: string) => {
+ const lexerNode = lexer.treeBuilder(formula);
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ if ((result as ErrorValueObject).isError()) {
+ return (result as ErrorValueObject).getValue();
+ } else if ((result as ArrayValueObject).isArray()) {
+ return (result as ArrayValueObject).toValue();
+ }
+ return (result as BaseValueObject).getValue();
+ };
+ });
+
+ describe('One row', () => {
+ it('Column number null, different row parameters', async () => {
+ // null
+ const result = await calculate('=INDEX(A6:B6)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+ });
+
+ it('Column number blank cell, different row parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B6,)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B6,,)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B6,0,)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // Not exceed the maximum number of rows
+ result = await calculate('=INDEX(A6:B6,1,)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // Exceeds maximum number of rows
+ result = await calculate('=INDEX(A6:B6,2,)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B6,A3:F4,)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Tom']]);
+ });
+
+ it('Column number 0, different row parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B6,0)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B6,,0)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B6,0,0)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // Not exceed the maximum number of rows
+ result = await calculate('=INDEX(A6:B6,1,0)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah']]);
+
+ // Exceeds maximum number of rows
+ result = await calculate('=INDEX(A6:B6,2,0)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B6,A3:F4,0)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Tom']]);
+ });
+
+ it('Column number does not exceed the maximum number of columns, different row parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B6,2)');
+
+ expect(result).toStrictEqual([['Sarah']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B6,,2)');
+
+ expect(result).toStrictEqual([['Sarah']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B6,0,2)');
+
+ expect(result).toStrictEqual([['Sarah']]);
+
+ // Not exceed the maximum number of rows
+ result = await calculate('=INDEX(A6:B6,1,2)');
+
+ expect(result).toStrictEqual([['Sarah']]);
+
+ // Exceeds maximum number of rows
+ result = await calculate('=INDEX(A6:B6,2,2)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B6,A3:F4,2)');
+
+ expect(result).toStrictEqual([['Sarah', ErrorType.VALUE, 'Sarah', 'Sarah', 'Sarah', 'Sarah'], ['Sarah', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Sarah']]);
+ });
+
+ it('Column number exceeds the maximum number of columns, different row parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B6,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B6,,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // 0
+ result = await calculate('=INDEX(A6:B6,0,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Not exceed the maximum number of rows
+ result = await calculate('=INDEX(A6:B6,1,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Exceeds maximum number of rows
+ result = await calculate('=INDEX(A6:B6,2,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B6,A3:F4,3)');
+
+ expect(result).toStrictEqual([[ErrorType.REF, ErrorType.VALUE, ErrorType.REF, ErrorType.REF, ErrorType.REF, ErrorType.REF], [ErrorType.REF, ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, ErrorType.REF]]);
+ });
+
+ it('Column number array, different row parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B6,A3:A5)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B6,,A3:A5)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B6,0,A3:A5)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // Not exceed the maximum number of rows
+ result = await calculate('=INDEX(A6:B6,1,A3:A5)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // Exceeds maximum number of rows
+ result = await calculate('=INDEX(A6:B6,2,A3:A5)');
+
+ expect(result).toStrictEqual([[ErrorType.REF], [ErrorType.REF], [ErrorType.REF]]);
+
+ // Array
+ result = await calculate('=INDEX(A6:B6,A3:F4,A3:A5)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Tom'], [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA]]);
+ });
+ });
+
+ describe('One column', () => {
+ it('Row number null, different column parameters', async () => {
+ // null
+ const result = await calculate('=INDEX(A6:A7)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+ });
+
+ it('Row number blank cell, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:A7,)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:A7,,)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:A7,,0)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:A7,,1)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:A7,,2)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:A7,,A3:F4)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Tom']]);
+ });
+
+ it('Row number 0, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:A7,0)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:A7,0,)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:A7,0,0)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:A7,0,1)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:A7,0,2)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:A7,0,A3:F4)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Tom']]);
+ });
+
+ it('Row number does not exceed the maximum number of rows, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:A7,2)');
+
+ expect(result).toStrictEqual([['Alex']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:A7,2,)');
+
+ expect(result).toStrictEqual([['Alex']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:A7,2,0)');
+
+ expect(result).toStrictEqual([['Alex']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:A7,2,1)');
+
+ expect(result).toStrictEqual([['Alex']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:A7,2,2)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:A7,2,A3:F4)');
+
+ expect(result).toStrictEqual([['Alex', ErrorType.VALUE, 'Alex', 'Alex', 'Alex', 'Alex'], ['Alex', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Alex']]);
+ });
+
+ it('Row number exceeds the maximum number of rows, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:A7,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:A7,3,)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // 0
+ result = await calculate('=INDEX(A6:A7,3,0)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:A7,3,1)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:A7,3,2)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:A7,3,A3:F4)');
+
+ expect(result).toStrictEqual([[ErrorType.REF, ErrorType.VALUE, ErrorType.REF, ErrorType.REF, ErrorType.REF, ErrorType.REF], [ErrorType.REF, ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, ErrorType.REF]]);
+ });
+
+ it('Row number array, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:A7,A3:A5)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:A7,A3:A5,)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:A7,A3:A5,0)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:A7,A3:A5,1)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:A7,A3:A5,2)');
+
+ expect(result).toStrictEqual([[ErrorType.REF], [ErrorType.REF], [ErrorType.REF]]);
+
+ // Array
+ result = await calculate('=INDEX(A6:A7,A3:A5,A3:F4)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, 'Tom'], [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA]]);
+ });
+ });
+
+ describe('Multi rows and columns', () => {
+ it('Row number null, different column parameters', async () => {
+ // null
+ const result = await calculate('=INDEX(A6:B7)');
+
+ // reference Google Sheets
+ expect(result).toStrictEqual([['Tom', 'Sarah'], ['Alex', 'Mickey']]);
+ });
+
+ it('Row number blank cell, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B7,)');
+
+ // reference Google Sheets
+ expect(result).toStrictEqual([['Tom', 'Sarah'], ['Alex', 'Mickey']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B7,,)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah'], ['Alex', 'Mickey']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B7,,0)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah'], ['Alex', 'Mickey']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:B7,,1)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:B7,,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B7,,A3:F4)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, 'Sarah', ErrorType.VALUE, ErrorType.VALUE, 'Tom']]);
+ });
+
+ it('Row number 0, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B7,0)');
+
+ // reference Google Sheets
+ expect(result).toStrictEqual([['Tom', 'Sarah'], ['Alex', 'Mickey']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B7,0,)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah'], ['Alex', 'Mickey']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B7,0,0)');
+
+ expect(result).toStrictEqual([['Tom', 'Sarah'], ['Alex', 'Mickey']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:B7,0,1)');
+
+ expect(result).toStrictEqual([['Tom'], ['Alex']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:B7,0,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B7,0,A3:F4)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, 'Sarah', ErrorType.VALUE, ErrorType.VALUE, 'Tom']]);
+ });
+
+ it('Row number does not exceed the maximum number of rows, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B7,2)');
+
+ // reference Google Sheets
+ expect(result).toStrictEqual([['Alex', 'Mickey']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B7,2,)');
+
+ expect(result).toStrictEqual([['Alex', 'Mickey']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B7,2,0)');
+
+ expect(result).toStrictEqual([['Alex', 'Mickey']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:B7,2,1)');
+
+ expect(result).toStrictEqual([['Alex']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:B7,2,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B7,2,A3:F4)');
+
+ expect(result).toStrictEqual([['Alex', ErrorType.VALUE, 'Alex', 'Alex', 'Alex', 'Alex'], ['Alex', ErrorType.REF, 'Mickey', ErrorType.VALUE, ErrorType.VALUE, 'Alex']]);
+ });
+
+ it('Row number exceeds the maximum number of rows, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B7,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B7,3,)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // 0
+ result = await calculate('=INDEX(A6:B7,3,0)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:B7,3,1)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:B7,3,3)');
+
+ expect(result).toBe(ErrorType.REF);
+
+ // Array
+ result = await calculate('=INDEX(A6:B7,3,A3:F4)');
+
+ expect(result).toStrictEqual([[ErrorType.REF, ErrorType.VALUE, ErrorType.REF, ErrorType.REF, ErrorType.REF, ErrorType.REF], [ErrorType.REF, ErrorType.REF, ErrorType.REF, ErrorType.VALUE, ErrorType.VALUE, ErrorType.REF]]);
+ });
+
+ it('Row number array, different column parameters', async () => {
+ // null
+ let result = await calculate('=INDEX(A6:B7,A3:A5)');
+
+ // reference Google Sheets
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // blank cell
+ result = await calculate('=INDEX(A6:B7,A3:A5,)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // 0
+ result = await calculate('=INDEX(A6:B7,A3:A5,0)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // Not exceed the maximum number of columns
+ result = await calculate('=INDEX(A6:B7,A3:A5,1)');
+
+ expect(result).toStrictEqual([['Tom'], ['Tom'], ['Tom']]);
+
+ // Exceeds maximum number of columns
+ result = await calculate('=INDEX(A6:B7,A3:A5,3)');
+
+ expect(result).toStrictEqual([[ErrorType.REF], [ErrorType.REF], [ErrorType.REF]]);
+
+ // Array
+ result = await calculate('=INDEX(A6:B7,A3:A5,A3:F4)');
+
+ expect(result).toStrictEqual([['Tom', ErrorType.VALUE, 'Tom', 'Tom', 'Tom', 'Tom'], ['Tom', ErrorType.REF, 'Sarah', ErrorType.VALUE, ErrorType.VALUE, 'Tom'], [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA]]);
+ });
+ });
+ // supports array string
+});
diff --git a/packages/engine-formula/src/functions/lookup/index/index.ts b/packages/engine-formula/src/functions/lookup/index/index.ts
new file mode 100644
index 0000000000..072f348d0a
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/index/index.ts
@@ -0,0 +1,192 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Index extends BaseFunction {
+ override calculate(reference: BaseValueObject, rowNum: BaseValueObject, columnNum?: BaseValueObject, areaNum?: BaseValueObject) {
+ if (reference == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (reference.isError()) {
+ return reference;
+ }
+
+ if (rowNum?.isError()) {
+ return rowNum;
+ }
+
+ if (columnNum?.isError()) {
+ return columnNum;
+ }
+
+ if (areaNum?.isError()) {
+ return areaNum;
+ }
+
+ if (!reference.isArray()) {
+ return new ErrorValueObject(ErrorType.REF);
+ }
+
+ const referenceRowCount = (reference as ArrayValueObject).getRowCount();
+ const referenceColumnCount = (reference as ArrayValueObject).getColumnCount();
+
+ // When there is only one row, the rowNum is considered to be the column number.
+ // =INDEX(A6:B6,2) equals =INDEX(A6:B6,1,2)
+ if (referenceRowCount === 1 && referenceColumnCount > 1 && columnNum == null) {
+ columnNum = rowNum ?? new NumberValueObject(0);
+ rowNum = new NumberValueObject(0);
+ } else {
+ rowNum = rowNum ?? new NumberValueObject(0);
+ columnNum = columnNum ?? new NumberValueObject(0);
+ }
+
+ areaNum = areaNum ?? new NumberValueObject(1);
+
+ // get max row length
+ const maxRowLength = Math.max(
+ rowNum.isArray() ? (rowNum as ArrayValueObject).getRowCount() : 1,
+ columnNum.isArray() ? (columnNum as ArrayValueObject).getRowCount() : 1,
+ areaNum.isArray() ? (areaNum as ArrayValueObject).getRowCount() : 1
+ );
+
+ // get max column length
+ const maxColumnLength = Math.max(
+ rowNum.isArray() ? (rowNum as ArrayValueObject).getColumnCount() : 1,
+ columnNum.isArray() ? (columnNum as ArrayValueObject).getColumnCount() : 1,
+ areaNum.isArray() ? (areaNum as ArrayValueObject).getColumnCount() : 1
+ );
+
+ // If maxRowLength and maxColumnLength are both 1, pick the value from the reference array
+ // Otherwise, filter the results from the reference according to the specified rowNum/columnNum/areaNum, take the upper left corner cell value of each result array, and then form an array with maxRowLength row number and maxColumnLength column number.
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return this._calculateSingleCell(reference as ArrayValueObject, rowNum, columnNum, areaNum);
+ } else {
+ const rowNumArray = expandArrayValueObject(maxRowLength, maxColumnLength, rowNum, new ErrorValueObject(ErrorType.NA));
+ const columnNumArray = expandArrayValueObject(maxRowLength, maxColumnLength, columnNum, new ErrorValueObject(ErrorType.NA));
+ const areaNumArray = expandArrayValueObject(maxRowLength, maxColumnLength, areaNum, new ErrorValueObject(ErrorType.NA));
+
+ return rowNumArray.map((rowNumValue, rowIndex, columnIndex) => {
+ const columnNumValue = columnNumArray.get(rowIndex, columnIndex);
+ const areaNumValue = areaNumArray.get(rowIndex, columnIndex);
+
+ const result = this._calculateSingleCell(reference as ArrayValueObject, rowNumValue, columnNumValue, areaNumValue);
+
+ if (result.isArray()) {
+ return (result as ArrayValueObject).getFirstCell();
+ }
+
+ return result;
+ });
+ }
+ }
+
+ private _calculateSingleCell(reference: ArrayValueObject, rowNum: BaseValueObject, columnNum: BaseValueObject, areaNum: BaseValueObject) {
+ if (rowNum.isError()) {
+ return rowNum;
+ }
+
+ const rowNumberValue = this._getNumberValue(rowNum);
+
+ if (rowNumberValue === undefined || rowNumberValue < 0) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ if (columnNum.isError()) {
+ return columnNum;
+ }
+
+ const columnNumberValue = this._getNumberValue(columnNum);
+
+ if (columnNumberValue === undefined || columnNumberValue < 0) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ // TODO areaNum
+ if (areaNum.isError()) {
+ return areaNum;
+ }
+
+ const areaNumberValue = this._getAreaNumberValue(areaNum);
+
+ if (areaNumberValue === undefined || areaNumberValue < 1) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ const rowParam = rowNumberValue === 0 ? [undefined] : [rowNumberValue - 1, rowNumberValue];
+ const columnParam = columnNumberValue === 0 ? [undefined] : [columnNumberValue - 1, columnNumberValue];
+
+ const result = reference.slice(rowParam, columnParam);
+
+ if (!result) {
+ return new ErrorValueObject(ErrorType.REF);
+ }
+
+ return result;
+ }
+
+ private _getNumberValue(numberValueObject?: BaseValueObject) {
+ if (numberValueObject == null) {
+ return 0;
+ }
+
+ let logicValue = 0;
+
+ if (numberValueObject.isBoolean()) {
+ const logicV = numberValueObject.getValue() as boolean;
+ if (logicV === true) {
+ logicValue = 1;
+ }
+ } else if (numberValueObject.isString()) {
+ return;
+ } else if (numberValueObject.isNumber()) {
+ logicValue = Math.floor(numberValueObject.getValue() as number);
+ } else if (numberValueObject.isNull()) {
+ logicValue = 0;
+ }
+
+ return logicValue;
+ }
+
+ private _getAreaNumberValue(numberValueObject?: BaseValueObject) {
+ if (numberValueObject == null) {
+ return 1;
+ }
+
+ let logicValue = 0;
+
+ if (numberValueObject.isBoolean()) {
+ const logicV = numberValueObject.getValue() as boolean;
+ if (logicV === true) {
+ logicValue = 1;
+ }
+ } else if (numberValueObject.isString()) {
+ return;
+ } else if (numberValueObject.isNumber()) {
+ logicValue = Math.floor(numberValueObject.getValue() as number);
+ } else if (numberValueObject.isNull()) {
+ logicValue = 0;
+ }
+
+ return logicValue;
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/lookup/index.ts b/packages/engine-formula/src/functions/lookup/lookup/index.ts
index f11600f97b..7da80f8765 100644
--- a/packages/engine-formula/src/functions/lookup/lookup/index.ts
+++ b/packages/engine-formula/src/functions/lookup/lookup/index.ts
@@ -23,6 +23,8 @@ import { BaseFunction } from '../../base-function';
import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
export class Lookup extends BaseFunction {
+ override needsExpandParams = true;
+
override calculate(
lookupValue: BaseValueObject,
lookupVectorOrArray: ArrayValueObject,
diff --git a/packages/engine-formula/src/functions/lookup/match/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/match/__tests__/index.spec.ts
index 7989a9ca7b..4e947bee17 100644
--- a/packages/engine-formula/src/functions/lookup/match/__tests__/index.spec.ts
+++ b/packages/engine-formula/src/functions/lookup/match/__tests__/index.spec.ts
@@ -22,7 +22,7 @@ import {
} from '../../../../engine/value-object/primitive-object';
import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
import { Match } from '..';
-import { ErrorType } from '../../../..';
+import { ErrorType } from '../../../../basics/error-type';
describe('Test match', () => {
const textFunction = new Match(FUNCTION_NAMES_LOOKUP.MATCH);
diff --git a/packages/engine-formula/src/functions/lookup/match/index.ts b/packages/engine-formula/src/functions/lookup/match/index.ts
index bc39b57258..381f85ba35 100644
--- a/packages/engine-formula/src/functions/lookup/match/index.ts
+++ b/packages/engine-formula/src/functions/lookup/match/index.ts
@@ -63,15 +63,11 @@ export class Match extends BaseFunction {
}
if (lookupValue.isArray()) {
- return lookupValue.map((value) => {
- const result = this._handleSingleObject(
- value,
- lookupArray,
- matchTypeValue
- );
-
- return result;
- });
+ return lookupValue.map((value) => this._handleSingleObject(
+ value,
+ lookupArray,
+ matchTypeValue
+ ));
}
return this._handleSingleObject(
diff --git a/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts
new file mode 100644
index 0000000000..d0bdabc91e
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts
@@ -0,0 +1,151 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import { Lexer } from '../../../../engine/analysis/lexer';
+import type { LexerNode } from '../../../../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../../../../engine/analysis/parser';
+import type { BaseAstNode } from '../../../../engine/ast-node/base-ast-node';
+import { Interpreter } from '../../../../engine/interpreter/interpreter';
+import { IFormulaCurrentConfigService } from '../../../../services/current-data.service';
+import { IFunctionService } from '../../../../services/function.service';
+import { IFormulaRuntimeService } from '../../../../services/runtime.service';
+import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Row } from '..';
+import type { BaseValueObject, ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test row', () => {
+ let get: Injector['get'];
+ let lexer: Lexer;
+ let astTreeBuilder: AstTreeBuilder;
+ let interpreter: Interpreter;
+
+ beforeEach(() => {
+ const testBed = createFunctionTestBed();
+
+ get = testBed.get;
+
+ lexer = get(Lexer);
+ astTreeBuilder = get(AstTreeBuilder);
+ interpreter = get(Interpreter);
+
+ const functionService = get(IFunctionService);
+
+ const formulaCurrentConfigService = get(IFormulaCurrentConfigService);
+
+ const formulaRuntimeService = get(IFormulaRuntimeService);
+
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ forceCalculate: false,
+ numfmtItemMap: {},
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyUnitFeatureMap: {},
+ excludedCell: {},
+ allUnitData: {
+ [testBed.unitId]: testBed.sheetData,
+ },
+ });
+
+ const sheetItem = testBed.sheetData[testBed.sheetId];
+
+ formulaRuntimeService.setCurrent(
+ 0,
+ 0,
+ sheetItem.rowCount,
+ sheetItem.columnCount,
+ testBed.sheetId,
+ testBed.unitId
+ );
+
+ functionService.registerExecutors(
+ new Row(FUNCTION_NAMES_LOOKUP.ROW)
+ );
+ });
+
+ describe('Row', () => {
+ it('No reference', async () => {
+ const lexerNode = lexer.treeBuilder('=ROW()');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toStrictEqual(1);
+ });
+ it('Reference single cell', async () => {
+ const lexerNode = lexer.treeBuilder('=ROW(A5)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ArrayValueObject).toValue()).toStrictEqual([[5]]);
+ });
+ it('Reference array cell', async () => {
+ const lexerNode = lexer.treeBuilder('=ROW(A5:B10)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ArrayValueObject).toValue()).toStrictEqual([[5], [6], [7], [8], [9], [10]]);
+ });
+ it('Text parameters', async () => {
+ const lexerNode = lexer.treeBuilder('=ROW("A5")');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Boolean params TRUE', async () => {
+ const lexerNode = lexer.treeBuilder('=ROW(TRUE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Boolean params FALSE', async () => {
+ const lexerNode = lexer.treeBuilder('=ROW(FALSE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Number params', async () => {
+ const lexerNode = lexer.treeBuilder('=ROW(11)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/row/index.ts b/packages/engine-formula/src/functions/lookup/row/index.ts
new file mode 100644
index 0000000000..a8b113e24b
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/row/index.ts
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import type { BaseValueObject, IArrayValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Row extends BaseFunction {
+ override calculate(
+ reference?: BaseValueObject
+ ) {
+ if (reference == null) {
+ return new NumberValueObject(this.row + 1);
+ }
+
+ if (reference.isError()) {
+ return reference;
+ }
+
+ if (!reference.isArray()) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const row = (reference as ArrayValueObject).getCurrentRow();
+ const rowCount = (reference as ArrayValueObject).getRowCount();
+
+ const calculateValueList = [];
+ for (let i = 0; i < rowCount; i++) {
+ calculateValueList.push([new NumberValueObject(row + i + 1)]);
+ }
+
+ const arrayValueObjectData: IArrayValueObject = {
+ calculateValueList,
+ rowCount,
+ columnCount: 1,
+ unitId: this.unitId || '',
+ sheetId: this.subUnitId || '',
+ row: this.row,
+ column: this.column,
+ };
+
+ return new ArrayValueObject(arrayValueObjectData);
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts
new file mode 100644
index 0000000000..990b563172
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts
@@ -0,0 +1,150 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import { Lexer } from '../../../../engine/analysis/lexer';
+import type { LexerNode } from '../../../../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../../../../engine/analysis/parser';
+import type { BaseAstNode } from '../../../../engine/ast-node/base-ast-node';
+import { Interpreter } from '../../../../engine/interpreter/interpreter';
+import { IFormulaCurrentConfigService } from '../../../../services/current-data.service';
+import { IFunctionService } from '../../../../services/function.service';
+import { IFormulaRuntimeService } from '../../../../services/runtime.service';
+import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Rows } from '..';
+import type { BaseValueObject, ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test rows', () => {
+ let get: Injector['get'];
+ let lexer: Lexer;
+ let astTreeBuilder: AstTreeBuilder;
+ let interpreter: Interpreter;
+
+ beforeEach(() => {
+ const testBed = createFunctionTestBed();
+
+ get = testBed.get;
+
+ lexer = get(Lexer);
+ astTreeBuilder = get(AstTreeBuilder);
+ interpreter = get(Interpreter);
+
+ const functionService = get(IFunctionService);
+
+ const formulaCurrentConfigService = get(IFormulaCurrentConfigService);
+
+ const formulaRuntimeService = get(IFormulaRuntimeService);
+
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ forceCalculate: false,
+ numfmtItemMap: {},
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyUnitFeatureMap: {},
+ excludedCell: {},
+ allUnitData: {
+ [testBed.unitId]: testBed.sheetData,
+ },
+ });
+
+ const sheetItem = testBed.sheetData[testBed.sheetId];
+
+ formulaRuntimeService.setCurrent(
+ 0,
+ 0,
+ sheetItem.rowCount,
+ sheetItem.columnCount,
+ testBed.sheetId,
+ testBed.unitId
+ );
+
+ functionService.registerExecutors(
+ new Rows(FUNCTION_NAMES_LOOKUP.ROWS)
+ );
+ });
+
+ describe('Rows', () => {
+ it('Reference single cell', async () => {
+ const lexerNode = lexer.treeBuilder('=ROWS(C1)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Reference array cell', async () => {
+ const lexerNode = lexer.treeBuilder('=ROWS(C2:F3)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(2);
+ });
+ it('No reference', async () => {
+ const lexerNode = lexer.treeBuilder('=ROWS()');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as ErrorValueObject).getValue()).toBe(ErrorType.NA);
+ });
+ it('Text params', async () => {
+ const lexerNode = lexer.treeBuilder('=ROWS("A5")');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Boolean params TRUE', async () => {
+ const lexerNode = lexer.treeBuilder('=ROWS(TRUE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Boolean params FALSE', async () => {
+ const lexerNode = lexer.treeBuilder('=ROWS(FALSE)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ it('Number params', async () => {
+ const lexerNode = lexer.treeBuilder('=ROWS(11)');
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ expect((result as BaseValueObject).getValue()).toBe(1);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/rows/index.ts b/packages/engine-formula/src/functions/lookup/rows/index.ts
new file mode 100644
index 0000000000..c1343608ed
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/rows/index.ts
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Rows extends BaseFunction {
+ override calculate(
+ reference?: BaseValueObject
+ ) {
+ if (reference == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (reference.isError()) {
+ return reference;
+ }
+
+ if (reference.isString() || reference.isNumber() || reference.isBoolean()) {
+ return new NumberValueObject(1);
+ }
+
+ if (!reference.isArray()) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const rowCount = (reference as ArrayValueObject).getRowCount();
+
+ return new NumberValueObject(rowCount);
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/vlookup/index.ts b/packages/engine-formula/src/functions/lookup/vlookup/index.ts
index 4e53e512cc..edc42d967a 100644
--- a/packages/engine-formula/src/functions/lookup/vlookup/index.ts
+++ b/packages/engine-formula/src/functions/lookup/vlookup/index.ts
@@ -72,9 +72,7 @@ export class Vlookup extends BaseFunction {
}
if (lookupValue.isArray()) {
- return lookupValue.map((value) => {
- return this._handleSingleObject(value, searchArray, resultArray, rangeLookupValue);
- });
+ return lookupValue.map((value) => this._handleSingleObject(value, searchArray, resultArray, rangeLookupValue));
}
return this._handleSingleObject(lookupValue, searchArray, resultArray, rangeLookupValue);
diff --git a/packages/engine-formula/src/functions/lookup/xmatch/index.ts b/packages/engine-formula/src/functions/lookup/xmatch/index.ts
index 9ced78717a..e325e87351 100644
--- a/packages/engine-formula/src/functions/lookup/xmatch/index.ts
+++ b/packages/engine-formula/src/functions/lookup/xmatch/index.ts
@@ -77,16 +77,12 @@ export class Xmatch extends BaseFunction {
}
if (lookupValue.isArray()) {
- return lookupValue.map((value) => {
- const result = this._handleSingleObject(
- value,
- lookupArray,
- matchModeValue,
- searchModeValue
- );
-
- return result;
- });
+ return lookupValue.map((value) => this._handleSingleObject(
+ value,
+ lookupArray,
+ matchModeValue,
+ searchModeValue
+ ));
}
return this._handleSingleObject(
diff --git a/packages/engine-formula/src/functions/math/function-map.ts b/packages/engine-formula/src/functions/math/function-map.ts
index 3badc4c8f4..837d4e1f7a 100644
--- a/packages/engine-formula/src/functions/math/function-map.ts
+++ b/packages/engine-formula/src/functions/math/function-map.ts
@@ -19,7 +19,10 @@ import { Acos } from './acos';
import { Acosh } from './acosh';
import { Acot } from './acot';
import { FUNCTION_NAMES_MATH } from './function-names';
+import { Mod } from './mod';
import { Power } from './power';
+import { Product } from './product';
+import { Subtotal } from './subtotal';
import { Sum } from './sum';
import { Sumif } from './sumif';
import { Sumifs } from './sumifs';
@@ -29,8 +32,11 @@ export const functionMath = [
[Acos, FUNCTION_NAMES_MATH.ACOS],
[Acosh, FUNCTION_NAMES_MATH.ACOSH],
[Acot, FUNCTION_NAMES_MATH.ACOT],
+ [Mod, FUNCTION_NAMES_MATH.MOD],
+ [Subtotal, FUNCTION_NAMES_MATH.SUBTOTAL],
[Sum, FUNCTION_NAMES_MATH.SUM],
[Sumif, FUNCTION_NAMES_MATH.SUMIF],
[Sumifs, FUNCTION_NAMES_MATH.SUMIFS],
[Power, FUNCTION_NAMES_MATH.POWER],
+ [Product, FUNCTION_NAMES_MATH.PRODUCT],
];
diff --git a/packages/engine-formula/src/functions/math/mod/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/mod/__tests__/index.spec.ts
new file mode 100644
index 0000000000..8a08e0c35f
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/mod/__tests__/index.spec.ts
@@ -0,0 +1,112 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_MATH } from '../../function-names';
+import { Mod } from '..';
+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test mod function', () => {
+ const textFunction = new Mod(FUNCTION_NAMES_MATH.MOD);
+
+ describe('Mod', () => {
+ it('Number is single cell, power is single cell', () => {
+ const number = new NumberValueObject(5);
+ const power = new NumberValueObject(2);
+ const result = textFunction.calculate(number, power);
+ expect(result.getValue()).toBe(1);
+ });
+
+ it('Number is single cell, power is array', () => {
+ const number = new NumberValueObject(5);
+ const power = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(number, power);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [0, ErrorType.VALUE, 0.08, 0, '#DIV/0!', '#DIV/0!'],
+ ['#DIV/0!', 5, 0.32, ErrorType.VALUE, -1, ErrorType.VALUE],
+ ]);
+ });
+
+ it('Number is array, power is single cell', () => {
+ const number = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const power = new NumberValueObject(2);
+ const result = textFunction.calculate(number, power);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [1, ErrorType.VALUE, 1.23, 1, 0, 0],
+ [0, 0, 0.34, ErrorType.VALUE, 1, ErrorType.VALUE],
+ ]);
+ });
+
+ it('Number is array, power is array', () => {
+ const number = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const power = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1],
+ [2],
+ [3],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(number, power);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [0, ErrorType.VALUE, 0.23, 0, 0, 0],
+ [0, 0, 0.34, ErrorType.VALUE, 1, ErrorType.VALUE],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/math/mod/index.ts b/packages/engine-formula/src/functions/math/mod/index.ts
new file mode 100644
index 0000000000..a5e7f8cb38
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/mod/index.ts
@@ -0,0 +1,38 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Mod extends BaseFunction {
+ override calculate(number: BaseValueObject, divisor: BaseValueObject) {
+ if (number == null || divisor == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (number.isError()) {
+ return number;
+ }
+
+ if (divisor.isError()) {
+ return divisor;
+ }
+
+ return number.mod(divisor);
+ }
+}
diff --git a/packages/engine-formula/src/functions/math/power/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/power/__tests__/index.spec.ts
new file mode 100644
index 0000000000..abb1866a74
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/power/__tests__/index.spec.ts
@@ -0,0 +1,112 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_MATH } from '../../function-names';
+import { Power } from '..';
+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test power function', () => {
+ const textFunction = new Power(FUNCTION_NAMES_MATH.POWER);
+
+ describe('Power', () => {
+ it('Number is single cell, power is single cell', () => {
+ const number = new NumberValueObject(5);
+ const power = new NumberValueObject(2);
+ const result = textFunction.calculate(number, power);
+ expect(result.getValue()).toBe(25);
+ });
+
+ it('Number is single cell, power is array', () => {
+ const number = new NumberValueObject(2);
+ const power = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(number, power);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [2, ErrorType.VALUE, 2.3456698984637576, 2, 1, 1],
+ [1, 1.2676506002282294e+30, 5.063026375881119, ErrorType.VALUE, 0.125, ErrorType.VALUE],
+ ]);
+ });
+
+ it('Number is array, power is single cell', () => {
+ const number = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const power = new NumberValueObject(2);
+ const result = textFunction.calculate(number, power);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [1, ErrorType.VALUE, 1.5128999999999999, 1, 0, 0],
+ [0, 10000, 5.4755999999999991, ErrorType.VALUE, 9, ErrorType.VALUE],
+ ]);
+ });
+
+ it('Number is array, power is array', () => {
+ const number = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const power = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1],
+ [2],
+ [3],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(number, power);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [1, ErrorType.VALUE, 1.23, 1, 0, 0],
+ [0, 10000, 5.4755999999999991, ErrorType.VALUE, 9, ErrorType.VALUE],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/math/power/index.ts b/packages/engine-formula/src/functions/math/power/index.ts
index 7a18937d3f..38f9f49530 100644
--- a/packages/engine-formula/src/functions/math/power/index.ts
+++ b/packages/engine-formula/src/functions/math/power/index.ts
@@ -15,12 +15,24 @@
*/
import { ErrorType } from '../../../basics/error-type';
-import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { BaseFunction } from '../../base-function';
export class Power extends BaseFunction {
- override calculate(numberVar: FunctionVariantType, powerVar: FunctionVariantType) {
- return new ErrorValueObject(ErrorType.VALUE);
+ override calculate(number: BaseValueObject, power: BaseValueObject) {
+ if (number == null || power == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (number.isError()) {
+ return number;
+ }
+
+ if (power.isError()) {
+ return power;
+ }
+
+ return number.pow(power);
}
}
diff --git a/packages/engine-formula/src/functions/math/product/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/product/__tests__/index.spec.ts
new file mode 100644
index 0000000000..c5d748dd7d
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/product/__tests__/index.spec.ts
@@ -0,0 +1,108 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_MATH } from '../../function-names';
+import { Product } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test product function', () => {
+ const textFunction = new Product(FUNCTION_NAMES_MATH.PRODUCT);
+
+ describe('Product', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('test');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ it('Var1 is number, var2 is string number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('2');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [null, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(-1726.92);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/math/product/index.ts b/packages/engine-formula/src/functions/math/product/index.ts
new file mode 100644
index 0000000000..b0ae8989db
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/product/index.ts
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { isRealNum } from '@univerjs/core';
+import type { ArrayValueObject } from '../../..';
+import { ErrorType } from '../../../basics/error-type';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Product extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ let accumulatorAll: BaseValueObject = new NumberValueObject(1);
+ for (let i = 0; i < variants.length; i++) {
+ let variant = variants[i];
+
+ if (variant.isError()) {
+ return variant;
+ }
+
+ if (variant.isString()) {
+ const value = variant.getValue();
+ const isStringNumber = isRealNum(value);
+
+ if (!isStringNumber) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ variant = new NumberValueObject(value);
+ }
+
+ if (variant.isArray()) {
+ variant = this._multiplyArray(variant as ArrayValueObject);
+
+ if (variant.isError()) {
+ return variant as ErrorValueObject;
+ }
+ }
+
+ if (variant.isNull()) {
+ continue;
+ }
+
+ accumulatorAll = accumulatorAll.multiply(variant);
+
+ if (accumulatorAll.isError()) {
+ return accumulatorAll;
+ }
+ }
+
+ return accumulatorAll;
+ }
+
+ private _multiplyArray(array: ArrayValueObject) {
+ let result: BaseValueObject = new NumberValueObject(1);
+ array.iterator((valueObject) => {
+ // 'test', ' ', blank cell, TRUE and FALSE are ignored
+ if (valueObject == null || valueObject.isString() || valueObject.isBoolean() || valueObject.isNull()) {
+ return true; // continue
+ }
+
+ if (valueObject.isError()) {
+ result = valueObject;
+ return false; // break
+ }
+
+ result = (result as NumberValueObject).multiply(
+ valueObject as BaseValueObject
+ ) as BaseValueObject;
+ });
+
+ return result;
+ }
+}
diff --git a/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts
new file mode 100644
index 0000000000..8905a88c88
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts
@@ -0,0 +1,359 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import type { IWorkbookData } from '@univerjs/core';
+import { BooleanNumber, CellValueType, LocaleType } from '@univerjs/core';
+import { Lexer } from '../../../../engine/analysis/lexer';
+import type { LexerNode } from '../../../../engine/analysis/lexer-node';
+import { AstTreeBuilder } from '../../../../engine/analysis/parser';
+import type { BaseAstNode } from '../../../../engine/ast-node/base-ast-node';
+import { Interpreter } from '../../../../engine/interpreter/interpreter';
+import { IFormulaCurrentConfigService } from '../../../../services/current-data.service';
+import { IFunctionService } from '../../../../services/function.service';
+import { IFormulaRuntimeService } from '../../../../services/runtime.service';
+import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed';
+import { FUNCTION_NAMES_MATH } from '../../function-names';
+import { Subtotal } from '..';
+import type { BaseValueObject, ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+
+const getTestWorkbookData = (): IWorkbookData => {
+ return {
+ id: 'test',
+ appVersion: '3.0.0-alpha',
+ sheets: {
+ sheet1: {
+ id: 'sheet1',
+ cellData: {
+ 0: {
+ 0: {
+ v: 1,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: 2,
+ t: CellValueType.NUMBER,
+ },
+ 2: {
+ v: ErrorType.NAME,
+ t: CellValueType.STRING,
+ },
+ },
+ 1: {
+ 0: {
+ v: 3,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: 4,
+ t: CellValueType.NUMBER,
+ },
+ 2: {
+ v: 'B2',
+ t: CellValueType.STRING,
+ },
+ 3: {
+ v: 'R2C2',
+ t: CellValueType.STRING,
+ },
+ },
+ 2: {
+ 0: {
+ v: 1,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: ' ',
+ t: CellValueType.STRING,
+ },
+ 2: {
+ v: 1.23,
+ t: CellValueType.NUMBER,
+ },
+ 3: {
+ v: true,
+ t: CellValueType.BOOLEAN,
+ },
+ 4: {
+ v: false,
+ t: CellValueType.BOOLEAN,
+ },
+ },
+ 3: {
+ 0: {
+ v: 0,
+ t: CellValueType.NUMBER,
+ },
+ 1: {
+ v: '100',
+ },
+ 2: {
+ v: '2.34',
+ },
+ 3: {
+ v: 'test',
+ t: CellValueType.STRING,
+ },
+ 4: {
+ v: -3,
+ t: CellValueType.NUMBER,
+ },
+ },
+ },
+ rowData: {
+ 3: {
+ hd: BooleanNumber.TRUE,
+ },
+ },
+ },
+ },
+ locale: LocaleType.ZH_CN,
+ name: '',
+ sheetOrder: [],
+ styles: {},
+ };
+};
+
+describe('Test subtotal', () => {
+ let get: Injector['get'];
+ let lexer: Lexer;
+ let astTreeBuilder: AstTreeBuilder;
+ let interpreter: Interpreter;
+ let calculate: (formula: string) => Promise<(string | number | boolean | null)[][] | string | number | boolean>;
+
+ beforeEach(() => {
+ const testBed = createFunctionTestBed(getTestWorkbookData());
+
+ get = testBed.get;
+
+ lexer = get(Lexer);
+ astTreeBuilder = get(AstTreeBuilder);
+ interpreter = get(Interpreter);
+
+ const functionService = get(IFunctionService);
+
+ const formulaCurrentConfigService = get(IFormulaCurrentConfigService);
+
+ const formulaRuntimeService = get(IFormulaRuntimeService);
+
+ formulaCurrentConfigService.load({
+ formulaData: {},
+ arrayFormulaCellData: {},
+ forceCalculate: false,
+ numfmtItemMap: {},
+ dirtyRanges: [],
+ dirtyNameMap: {},
+ dirtyUnitFeatureMap: {},
+ excludedCell: {},
+ allUnitData: {
+ [testBed.unitId]: testBed.sheetData,
+ },
+ });
+
+ const sheetItem = testBed.sheetData[testBed.sheetId];
+
+ formulaRuntimeService.setCurrent(
+ 0,
+ 0,
+ sheetItem.rowCount,
+ sheetItem.columnCount,
+ testBed.sheetId,
+ testBed.unitId
+ );
+
+ functionService.registerExecutors(
+ new Subtotal(FUNCTION_NAMES_MATH.SUBTOTAL)
+ );
+
+ calculate = async (formula: string) => {
+ const lexerNode = lexer.treeBuilder(formula);
+
+ const astNode = astTreeBuilder.parse(lexerNode as LexerNode);
+
+ const result = await interpreter.executeAsync(astNode as BaseAstNode);
+
+ if ((result as ErrorValueObject).isError()) {
+ return (result as ErrorValueObject).getValue();
+ } else if ((result as ArrayValueObject).isArray()) {
+ return (result as ArrayValueObject).toValue();
+ }
+ return (result as BaseValueObject).getValue();
+ };
+ });
+
+ describe('Subtotal common', () => {
+ it('FunctionNum is normal number, refs is non-reference object', async () => {
+ // number
+ let result = await calculate('=SUBTOTAL(1,1)');
+ expect(result).toBe(ErrorType.VALUE);
+
+ // string normal
+ result = await calculate('=SUBTOTAL(2,"test")');
+ expect(result).toBe(ErrorType.VALUE);
+
+ // string number
+ result = await calculate('=SUBTOTAL(3,"1")');
+ expect(result).toBe(ErrorType.VALUE);
+
+ // boolean true
+ result = await calculate('=SUBTOTAL(4,true)');
+ expect(result).toBe(ErrorType.VALUE);
+
+ // boolean false
+ result = await calculate('=SUBTOTAL(5,false)');
+ expect(result).toBe(ErrorType.VALUE);
+ });
+
+ it('FunctionNum is normal number, refs is error or blank cell', async () => {
+ // error
+ let result = await calculate('=SUBTOTAL(7,C1)');
+ expect(result).toBe(ErrorType.NAME);
+
+ // null
+ result = await calculate('=SUBTOTAL(1,D1)');
+ expect(result).toBe(ErrorType.DIV_BY_ZERO);
+
+ result = await calculate('=SUBTOTAL(2,D1)');
+ expect(result).toBe(0);
+
+ result = await calculate('=SUBTOTAL(3,D1)');
+ expect(result).toBe(0);
+
+ result = await calculate('=SUBTOTAL(4,D1)');
+ expect(result).toBe(0);
+
+ result = await calculate('=SUBTOTAL(5,D1)');
+ expect(result).toBe(0);
+
+ result = await calculate('=SUBTOTAL(6,D1)');
+ expect(result).toBe(0);
+
+ result = await calculate('=SUBTOTAL(7,D1)');
+ expect(result).toBe(ErrorType.DIV_BY_ZERO);
+
+ result = await calculate('=SUBTOTAL(8,D1)');
+ expect(result).toBe(ErrorType.DIV_BY_ZERO);
+
+ result = await calculate('=SUBTOTAL(9,D1)');
+ expect(result).toBe(0);
+
+ result = await calculate('=SUBTOTAL(10,D1)');
+ expect(result).toBe(ErrorType.DIV_BY_ZERO);
+
+ result = await calculate('=SUBTOTAL(11,D1)');
+ expect(result).toBe(ErrorType.DIV_BY_ZERO);
+ });
+
+ it('FunctionNum is normal number, ref1 is array, ref2 is array includes error', async () => {
+ const result = await calculate('=SUBTOTAL(9,A1:B2,C1:C2)');
+ expect(result).toBe(ErrorType.NAME);
+ });
+ });
+
+ describe('Subtotal every function, function number is single number', () => {
+ it('Average, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(1,A1:B2,A3:F4)');
+ expect(result).toBe(11.157);
+ });
+ it('Count, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(2,A1:B2,A3:F4)');
+ expect(result).toBe(10);
+ });
+ it('Counta, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(3,A1:B2,A3:F4)');
+ expect(result).toBe(14);
+ });
+ it('Max, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(4,A1:B2,A3:F4)');
+ expect(result).toBe(100);
+ });
+ it('Min, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(5,A1:B2,A3:F4)');
+ expect(result).toBe(-3);
+ });
+ it('Product, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(6,A1:B2,A3:F4)');
+ expect(typeof result === 'number' && Math.abs(result)).toBe(0);
+ });
+ it('Stdev.s, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(7,A1:B2,A3:F4)');
+ expect(result).toBe(31.27335040502625);
+ });
+ it('Stdev.p, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(8,A1:B2,A3:F4)');
+ expect(result).toBe(29.668505203329676);
+ });
+ it('sum, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(9,A1:B2,A3:F4)');
+ expect(result).toBe(111.57);
+ });
+ it('Var.s, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(10,A1:B2,A3:F4)');
+ expect(result).toBeCloseTo(978.0224456, 7);
+ });
+ it('Var.p, Var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(11,A1:B2,A3:F4)');
+ expect(result).toBe(880.220201);
+ });
+ });
+
+ describe('Subtotal every function, function number is array', () => {
+ it('Function num is array, var1 is array, var2 is array', async () => {
+ const result = await calculate('=SUBTOTAL(A1:B2,A1:B2,A3:F4)');
+ expect(result).toStrictEqual([[11.157, 10], [14, 100]]);
+ });
+ });
+ describe('Subtotal every function, including hidden row', () => {
+ it('Function num is normal number, var1 is array', async () => {
+ let result = await calculate('=SUBTOTAL(101,A3:F4)');
+ expect(result).toBe(1.115);
+
+ result = await calculate('=SUBTOTAL(102,A3:F4)');
+ expect(result).toBe(2);
+
+ result = await calculate('=SUBTOTAL(103,A3:F4)');
+ expect(result).toBe(5);
+
+ result = await calculate('=SUBTOTAL(104,A3:F4)');
+ expect(result).toBe(1.23);
+
+ result = await calculate('=SUBTOTAL(105,A3:F4)');
+ expect(result).toBe(1);
+
+ result = await calculate('=SUBTOTAL(106,A3:F4)');
+ expect(result).toBe(1.23);
+
+ result = await calculate('=SUBTOTAL(107,A3:F4)');
+ expect(result).toBeCloseTo(0.16263456, 7);
+
+ result = await calculate('=SUBTOTAL(108,A3:F4)');
+ expect(result).toBe(0.115);
+
+ result = await calculate('=SUBTOTAL(109,A3:F4)');
+ expect(result).toBe(2.23);
+
+ result = await calculate('=SUBTOTAL(110,A3:F4)');
+ expect(result).toBe(0.02645);
+
+ result = await calculate('=SUBTOTAL(111,A3:F4)');
+ expect(result).toBe(0.013225);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/math/subtotal/index.ts b/packages/engine-formula/src/functions/math/subtotal/index.ts
new file mode 100644
index 0000000000..1b6afdbf8c
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/subtotal/index.ts
@@ -0,0 +1,411 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IObjectArrayPrimitiveType, IRowData, Nullable } from '@univerjs/core';
+import { BooleanNumber } from '@univerjs/core';
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+import { createNewArray } from '../../../engine/utils/array-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import type { ArrayValueObject } from '../../..';
+
+enum FunctionNum {
+ AVERAGE = 1,
+ COUNT = 2,
+ COUNTA = 3,
+ MAX = 4,
+ MIN = 5,
+ PRODUCT = 6,
+ STDEV = 7,
+ STDEVP = 8,
+ SUM = 9,
+ VAR = 10,
+ VARP = 11,
+}
+
+enum FunctionNumIgnoreHidden {
+ AVERAGE = 101,
+ COUNT = 102,
+ COUNTA = 103,
+ MAX = 104,
+ MIN = 105,
+ PRODUCT = 106,
+ STDEV = 107,
+ STDEVP = 108,
+ SUM = 109,
+ VAR = 110,
+ VARP = 111,
+}
+
+export class Subtotal extends BaseFunction {
+ override needsReferenceObject = true;
+
+ override calculate(functionNum: FunctionVariantType, ...refs: FunctionVariantType[]) {
+ if (functionNum == null) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (functionNum.isError()) {
+ return functionNum;
+ }
+
+ if (refs.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ if (functionNum.isReferenceObject()) {
+ const result: BaseValueObject[][] = [];
+
+ (functionNum as BaseReferenceObject).iterator((valueObject, rowIndex, columnIndex) => {
+ if (result[rowIndex] == null) {
+ result[rowIndex] = [];
+ }
+
+ result[rowIndex][columnIndex] = this._handleSingleObject(
+ valueObject,
+ ...refs
+ );
+ });
+
+ return createNewArray(result, result.length, result[0].length);
+ }
+
+ return this._handleSingleObject(functionNum as BaseValueObject, ...refs);
+ }
+
+ private _handleSingleObject(functionNum: Nullable<BaseValueObject>, ...refs: FunctionVariantType[]) {
+ const indexNum = this._getIndexNumValue(functionNum);
+ let result;
+
+ if (indexNum instanceof ErrorValueObject) {
+ return indexNum;
+ }
+
+ switch (indexNum) {
+ case FunctionNum.AVERAGE:
+ result = this._average(false, ...refs);
+ break;
+ case FunctionNum.COUNT:
+ result = this._count(false, ...refs);
+ break;
+ case FunctionNum.COUNTA:
+ result = this._counta(false, ...refs);
+ break;
+ case FunctionNum.MAX:
+ result = this._max(false, ...refs);
+ break;
+ case FunctionNum.MIN:
+ result = this._min(false, ...refs);
+ break;
+ case FunctionNum.PRODUCT:
+ result = this._product(false, ...refs);
+ break;
+ case FunctionNum.STDEV:
+ result = this._stdev(false, ...refs);
+ break;
+ case FunctionNum.STDEVP:
+ result = this._stdevp(false, ...refs);
+ break;
+ case FunctionNum.SUM:
+ result = this._sum(false, ...refs);
+ break;
+ case FunctionNum.VAR:
+ result = this._var(false, ...refs);
+ break;
+ case FunctionNum.VARP:
+ result = this._varp(false, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.AVERAGE:
+ result = this._average(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.COUNT:
+ result = this._count(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.COUNTA:
+ result = this._counta(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.MAX:
+ result = this._max(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.MIN:
+ result = this._min(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.PRODUCT:
+ result = this._product(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.STDEV:
+ result = this._stdev(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.STDEVP:
+ result = this._stdevp(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.SUM:
+ result = this._sum(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.VAR:
+ result = this._var(true, ...refs);
+ break;
+ case FunctionNumIgnoreHidden.VARP:
+ result = this._varp(true, ...refs);
+ break;
+ default:
+ result = new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ return result as BaseValueObject;
+ }
+
+ private _getIndexNumValue(indexNum: Nullable<BaseValueObject>) {
+ // null, true, false, 0 , 1, ' 1',
+ const indexNumValue = indexNum ? Number(indexNum.getValue()) : 0;
+
+ if (isNaN(indexNumValue)) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ const indexNumValueInt = Math.floor(indexNumValue);
+
+ // 1-11, or 101-111
+ if ((indexNumValueInt >= 1 && indexNumValueInt <= 11) || (indexNumValueInt >= 101 && indexNumValueInt <= 111)) {
+ return indexNumValueInt;
+ }
+
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ private _average(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.mean();
+ }
+
+ private _count(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.count();
+ }
+
+ private _counta(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ let accumulatorAll: BaseValueObject = new NumberValueObject(0);
+ for (let i = 0; i < refs.length; i++) {
+ const variant = refs[i];
+
+ if (!variant.isReferenceObject()) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ const rowData = (variant as BaseReferenceObject).getRowData();
+
+ (variant as BaseReferenceObject).iterator((valueObject, rowIndex) => {
+ if (ignoreHidden && this._isRowHidden(rowData, rowIndex)) {
+ return true;
+ }
+
+ if (valueObject == null || valueObject.isNull()) {
+ return true;
+ }
+
+ accumulatorAll = accumulatorAll.plusBy(1);
+ });
+ }
+
+ return accumulatorAll;
+ }
+
+ private _max(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ if (this._isBlankArrayObject(flattenArray)) {
+ return new NumberValueObject(0);
+ }
+
+ return flattenArray.max();
+ }
+
+ private _min(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ if (this._isBlankArrayObject(flattenArray)) {
+ return new NumberValueObject(0);
+ }
+
+ return flattenArray.min();
+ }
+
+ private _product(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ if (this._isBlankArrayObject(flattenArray)) {
+ return new NumberValueObject(0);
+ }
+
+ let result: NumberValueObject = new NumberValueObject(1);
+ (flattenArray as ArrayValueObject).iterator((valueObject) => {
+ result = result.multiply(
+ valueObject as BaseValueObject
+ ) as NumberValueObject;
+ });
+
+ return result;
+ }
+
+ private _stdev(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ if (this._isBlankArrayObject(flattenArray)) {
+ return new ErrorValueObject(ErrorType.DIV_BY_ZERO);
+ }
+
+ return flattenArray.std(1);
+ }
+
+ private _stdevp(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ if (this._isBlankArrayObject(flattenArray)) {
+ return new ErrorValueObject(ErrorType.DIV_BY_ZERO);
+ }
+
+ return flattenArray.std();
+ }
+
+ private _sum(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.sum();
+ }
+
+ private _var(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ if (this._isBlankArrayObject(flattenArray)) {
+ return new ErrorValueObject(ErrorType.DIV_BY_ZERO);
+ }
+
+ return flattenArray.var(1);
+ }
+
+ private _varp(ignoreHidden: boolean, ...refs: FunctionVariantType[]) {
+ const flattenArray = this._flattenRefArray(ignoreHidden, ...refs);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ if (this._isBlankArrayObject(flattenArray)) {
+ return new ErrorValueObject(ErrorType.DIV_BY_ZERO);
+ }
+
+ return flattenArray.var();
+ }
+
+ private _flattenRefArray(ignoreHidden: boolean, ...variants: FunctionVariantType[]) {
+ const flattenValues: BaseValueObject[][] = [];
+ flattenValues[0] = [];
+
+ for (let i = 0; i < variants.length; i++) {
+ const variant = variants[i];
+
+ if (variant.isError()) {
+ return variant as ErrorValueObject;
+ }
+
+ if (!variant.isReferenceObject()) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ const rowData = (variant as BaseReferenceObject).getRowData();
+
+ let errorValue: Nullable<BaseValueObject>;
+
+ (variant as BaseReferenceObject).iterator((valueObject, rowIndex) => {
+ if (ignoreHidden && this._isRowHidden(rowData, rowIndex)) {
+ return true; // continue
+ }
+
+ // 'test', ' ', blank cell, TRUE and FALSE are ignored
+ if (valueObject == null || valueObject.isNull() || valueObject.isString() || valueObject.isBoolean()) {
+ return true;
+ }
+
+ if (valueObject.isError()) {
+ errorValue = valueObject;
+ return false; // break
+ }
+
+ flattenValues[0].push(valueObject);
+ });
+
+ if (errorValue?.isError()) {
+ return errorValue;
+ }
+ }
+
+ return createNewArray(flattenValues, 1, flattenValues[0].length);
+ }
+
+ private _isRowHidden(rowData: IObjectArrayPrimitiveType<Partial<IRowData>>, rowIndex: number
+ ) {
+ const row = rowData[rowIndex];
+ if (!row) {
+ return false;
+ }
+
+ return row.hd === BooleanNumber.TRUE;
+ }
+
+ private _isBlankArrayObject(arrayObject: BaseValueObject) {
+ return arrayObject.getArrayValue()[0].length === 0;
+ }
+}
diff --git a/packages/engine-formula/src/functions/math/sum/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sum/__tests__/index.spec.ts
new file mode 100644
index 0000000000..ea09f59925
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/sum/__tests__/index.spec.ts
@@ -0,0 +1,108 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_MATH } from '../../function-names';
+import { Sum } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test sum function', () => {
+ const textFunction = new Sum(FUNCTION_NAMES_MATH.SUM);
+
+ describe('Sum', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(3);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('test');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ it('Var1 is number, var2 is string number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('2');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(3);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(3);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(103.57);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/math/sum/index.ts b/packages/engine-formula/src/functions/math/sum/index.ts
index 027ecd7a32..9d6c100bd7 100644
--- a/packages/engine-formula/src/functions/math/sum/index.ts
+++ b/packages/engine-formula/src/functions/math/sum/index.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import { isRealNum } from '@univerjs/core';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
@@ -34,11 +35,14 @@ export class Sum extends BaseFunction {
}
if (variant.isString()) {
- return new ErrorValueObject(ErrorType.VALUE);
- }
+ const value = variant.getValue();
+ const isStringNumber = isRealNum(value);
- if (accumulatorAll.isError()) {
- return accumulatorAll;
+ if (!isStringNumber) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ variant = new NumberValueObject(value);
}
if (variant.isArray()) {
@@ -46,6 +50,10 @@ export class Sum extends BaseFunction {
}
accumulatorAll = accumulatorAll.plus(variant);
+
+ if (accumulatorAll.isError()) {
+ return accumulatorAll;
+ }
}
return accumulatorAll;
diff --git a/packages/engine-formula/src/functions/statistical/average/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/average/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a935690cc4
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/average/__tests__/index.spec.ts
@@ -0,0 +1,108 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Average } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test average function', () => {
+ const textFunction = new Average(FUNCTION_NAMES_STATISTICAL.AVERAGE);
+
+ describe('Average', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1.5);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('test');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ it('Var1 is number, var2 is string number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('2');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1.5);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1.5);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(14.795714285714286);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/average/index.ts b/packages/engine-formula/src/functions/statistical/average/index.ts
index 184e006df4..99d42338b2 100644
--- a/packages/engine-formula/src/functions/statistical/average/index.ts
+++ b/packages/engine-formula/src/functions/statistical/average/index.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import { isRealNum } from '@univerjs/core';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
@@ -28,23 +29,34 @@ export class Average extends BaseFunction {
let accumulatorSum: BaseValueObject = new NumberValueObject(0);
let accumulatorCount: BaseValueObject = new NumberValueObject(0);
for (let i = 0; i < variants.length; i++) {
- const variant = variants[i];
+ let variant = variants[i];
if (variant.isError()) {
return variant;
}
- if (accumulatorSum.isError()) {
- return accumulatorSum;
+ if (variant.isString()) {
+ const value = variant.getValue();
+ const isStringNumber = isRealNum(value);
+
+ if (!isStringNumber) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ variant = new NumberValueObject(value);
}
if (variant.isArray()) {
accumulatorSum = accumulatorSum.plus(variant.sum());
- accumulatorCount = accumulatorCount.plus(variant.count());
- } else {
- if (!variant.isNull()) {
- accumulatorCount = accumulatorCount.plus(new NumberValueObject(1));
+
+ if (accumulatorSum.isError()) {
+ return accumulatorSum;
}
+
+ accumulatorCount = accumulatorCount.plus(variant.count());
+ } else if (!variant.isNull()) {
+ accumulatorSum = accumulatorSum.plus(new NumberValueObject(variant.getValue()));
+ accumulatorCount = accumulatorCount.plus(new NumberValueObject(1));
}
}
diff --git a/packages/engine-formula/src/functions/statistical/count/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/count/__tests__/index.spec.ts
new file mode 100644
index 0000000000..bba99583b4
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/count/__tests__/index.spec.ts
@@ -0,0 +1,113 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Count } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test count function', () => {
+ const textFunction = new Count(FUNCTION_NAMES_STATISTICAL.COUNT);
+
+ describe('Count', () => {
+ it('Var1 is error', () => {
+ const var1 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(0);
+ });
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('test');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is string number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('2');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(3);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(7);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/count/index.ts b/packages/engine-formula/src/functions/statistical/count/index.ts
index 94779cdd5d..e4a13515d3 100644
--- a/packages/engine-formula/src/functions/statistical/count/index.ts
+++ b/packages/engine-formula/src/functions/statistical/count/index.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import { isRealNum } from '@univerjs/core';
import { ErrorType } from '../../../basics/error-type';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
@@ -36,10 +37,15 @@ export class Count extends BaseFunction {
if (variant.isArray()) {
variant = variant.count();
accumulatorAll = accumulatorAll.plus(variant as BaseValueObject);
- } else {
- if (!variant.isNull() && !variant.isString()) {
+ } else if (variant.isString()) {
+ const value = variant.getValue();
+ const isStringNumber = isRealNum(value);
+
+ if (isStringNumber) {
accumulatorAll = accumulatorAll.plus(new NumberValueObject(1));
}
+ } else if (!variant.isNull()) {
+ accumulatorAll = accumulatorAll.plus(new NumberValueObject(1));
}
}
diff --git a/packages/engine-formula/src/functions/statistical/counta/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/counta/__tests__/index.spec.ts
new file mode 100644
index 0000000000..473d87ee24
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/counta/__tests__/index.spec.ts
@@ -0,0 +1,113 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Counta } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test counta function', () => {
+ const textFunction = new Counta(FUNCTION_NAMES_STATISTICAL.COUNTA);
+
+ describe('Counta', () => {
+ it('Var1 is error', () => {
+ const var1 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('test');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is string number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('2');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(4);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(11);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/counta/index.ts b/packages/engine-formula/src/functions/statistical/counta/index.ts
index 5286262337..56f608e002 100644
--- a/packages/engine-formula/src/functions/statistical/counta/index.ts
+++ b/packages/engine-formula/src/functions/statistical/counta/index.ts
@@ -19,7 +19,7 @@ import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-ob
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
import { BaseFunction } from '../../base-function';
-export class CountA extends BaseFunction {
+export class Counta extends BaseFunction {
override calculate(...variants: BaseValueObject[]) {
if (variants.length === 0) {
return new ErrorValueObject(ErrorType.NA);
diff --git a/packages/engine-formula/src/functions/statistical/function-map.ts b/packages/engine-formula/src/functions/statistical/function-map.ts
index c886e708c9..222f77ed37 100644
--- a/packages/engine-formula/src/functions/statistical/function-map.ts
+++ b/packages/engine-formula/src/functions/statistical/function-map.ts
@@ -16,10 +16,18 @@
import { Average } from './average';
import { Count } from './count';
-import { CountA } from './counta';
+import { Counta } from './counta';
import { FUNCTION_NAMES_STATISTICAL } from './function-names';
import { Max } from './max';
import { Min } from './min';
+import { StdevP } from './stdev-p';
+import { StdevS } from './stdev-s';
+import { Stdeva } from './stdeva';
+import { Stdevpa } from './stdevpa';
+import { VarP } from './var-p';
+import { VarS } from './var-s';
+import { Vara } from './vara';
+import { Varpa } from './varpa';
export const functionStatistical = [
[Average, FUNCTION_NAMES_STATISTICAL.AVERAGE],
@@ -27,5 +35,13 @@ export const functionStatistical = [
[Max, FUNCTION_NAMES_STATISTICAL.MAX],
[Min, FUNCTION_NAMES_STATISTICAL.MIN],
[Min, FUNCTION_NAMES_STATISTICAL.MIN],
- [CountA, FUNCTION_NAMES_STATISTICAL.COUNTA],
+ [Counta, FUNCTION_NAMES_STATISTICAL.COUNTA],
+ [StdevP, FUNCTION_NAMES_STATISTICAL.STDEV_P],
+ [StdevS, FUNCTION_NAMES_STATISTICAL.STDEV_S],
+ [Stdeva, FUNCTION_NAMES_STATISTICAL.STDEVA],
+ [Stdevpa, FUNCTION_NAMES_STATISTICAL.STDEVPA],
+ [VarP, FUNCTION_NAMES_STATISTICAL.VAR_P],
+ [VarS, FUNCTION_NAMES_STATISTICAL.VAR_S],
+ [Vara, FUNCTION_NAMES_STATISTICAL.VARA],
+ [Varpa, FUNCTION_NAMES_STATISTICAL.VARPA],
];
diff --git a/packages/engine-formula/src/functions/statistical/max/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/max/__tests__/index.spec.ts
new file mode 100644
index 0000000000..2745fc7551
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/max/__tests__/index.spec.ts
@@ -0,0 +1,124 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Max } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test max function', () => {
+ const textFunction = new Max(FUNCTION_NAMES_STATISTICAL.MAX);
+
+ describe('Max', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('test');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ it('Var1 is number, var2 is string number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('2');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ it('Var1 is array not includes error, ignore boolean value ', () => {
+ const var1 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [-3, null],
+ [false, true],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(-3);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(100);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/max/index.ts b/packages/engine-formula/src/functions/statistical/max/index.ts
index ddd7ad7096..504acb1c51 100644
--- a/packages/engine-formula/src/functions/statistical/max/index.ts
+++ b/packages/engine-formula/src/functions/statistical/max/index.ts
@@ -14,7 +14,9 @@
* limitations under the License.
*/
+import { isRealNum } from '@univerjs/core';
import { ErrorType } from '../../../basics/error-type';
+import { convertTonNumber } from '../../../engine/utils/object-covert';
import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
import { BaseFunction } from '../../base-function';
@@ -33,8 +35,27 @@ export class Max extends BaseFunction {
return variant;
}
+ if (variant.isString()) {
+ const value = variant.getValue();
+ const isStringNumber = isRealNum(value);
+
+ if (!isStringNumber) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ variant = new NumberValueObject(value);
+ }
+
+ if (variant.isBoolean()) {
+ variant = convertTonNumber(variant);
+ }
+
if (variant.isArray()) {
variant = variant.max();
+
+ if (variant.isError()) {
+ return variant as ErrorValueObject;
+ }
}
if (variant.isNull()) {
@@ -42,18 +63,6 @@ export class Max extends BaseFunction {
}
accumulatorAll = this._validator(accumulatorAll, variant as BaseValueObject);
-
- // const variant = variants[i];
-
- // if (variant.isReferenceObject() || (variant.isValueObject() && (variant as BaseValueObject).isArray())) {
- // (variant as BaseReferenceObject | ArrayValueObject).iterator((valueObject, row, column) => {
- // if (!valueObject.isError() && !(valueObject as BaseValueObject).isString()) {
- // accumulatorAll = this._validator(accumulatorAll, valueObject as BaseValueObject);
- // }
- // });
- // } else if (!(variant as BaseValueObject).isString()) {
- // accumulatorAll = this._validator(accumulatorAll, variant as BaseValueObject);
- // }
}
return accumulatorAll;
diff --git a/packages/engine-formula/src/functions/statistical/min/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/min/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a406d165c8
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/min/__tests__/index.spec.ts
@@ -0,0 +1,124 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Min } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test min function', () => {
+ const textFunction = new Min(FUNCTION_NAMES_STATISTICAL.MIN);
+
+ describe('Min', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new StringValueObject('test');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ it('Var1 is number, var2 is string number', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new StringValueObject('1');
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ it('Var1 is array not includes error, ignore boolean value ', () => {
+ const var1 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [3, null],
+ [false, true],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(3);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(-3);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/min/index.ts b/packages/engine-formula/src/functions/statistical/min/index.ts
index 58d39e4102..5b932ed48a 100644
--- a/packages/engine-formula/src/functions/statistical/min/index.ts
+++ b/packages/engine-formula/src/functions/statistical/min/index.ts
@@ -14,7 +14,9 @@
* limitations under the License.
*/
+import { isRealNum } from '@univerjs/core';
import { ErrorType } from '../../../basics/error-type';
+import { convertTonNumber } from '../../../engine/utils/object-covert';
import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
import { NumberValueObject } from '../../../engine/value-object/primitive-object';
@@ -34,8 +36,27 @@ export class Min extends BaseFunction {
return variant as ErrorValueObject;
}
+ if (variant.isString()) {
+ const value = variant.getValue();
+ const isStringNumber = isRealNum(value);
+
+ if (!isStringNumber) {
+ return new ErrorValueObject(ErrorType.VALUE);
+ }
+
+ variant = new NumberValueObject(value);
+ }
+
+ if (variant.isBoolean()) {
+ variant = convertTonNumber(variant);
+ }
+
if (variant.isArray()) {
variant = variant.min();
+
+ if (variant.isError()) {
+ return variant as ErrorValueObject;
+ }
}
if (variant.isNull()) {
@@ -43,16 +64,6 @@ export class Min extends BaseFunction {
}
accumulatorAll = this._validator(accumulatorAll, variant as BaseValueObject);
-
- // if (variant.isReferenceObject() || (variant.isValueObject() && (variant as BaseValueObject).isArray())) {
- // (variant as BaseReferenceObject | ArrayValueObject).iterator((valueObject, row, column) => {
- // if (!valueObject.isError() && !(valueObject as BaseValueObject).isString()) {
- // accumulatorAll = this._validator(accumulatorAll, valueObject as BaseValueObject);
- // }
- // });
- // } else if (!(variant as BaseValueObject).isString()) {
- // accumulatorAll = this._validator(accumulatorAll, variant as BaseValueObject);
- // }
}
return accumulatorAll;
diff --git a/packages/engine-formula/src/functions/statistical/stdev-p/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/stdev-p/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a02d581628
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdev-p/__tests__/index.spec.ts
@@ -0,0 +1,116 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { StdevP } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test stdev.p function', () => {
+ const textFunction = new StdevP(FUNCTION_NAMES_STATISTICAL.STDEV_P);
+
+ describe('StdevP', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is zero', () => {
+ const var1 = new NumberValueObject(0);
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(0);
+ });
+ it('Var1 is null', () => {
+ const var1 = new NullValueObject(0);
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(0);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(34.82321961694231);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/stdev-p/index.ts b/packages/engine-formula/src/functions/statistical/stdev-p/index.ts
new file mode 100644
index 0000000000..c4bfc5b0d5
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdev-p/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class StdevP extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.std();
+ }
+}
diff --git a/packages/engine-formula/src/functions/statistical/stdev-s/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/stdev-s/__tests__/index.spec.ts
new file mode 100644
index 0000000000..559e868582
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdev-s/__tests__/index.spec.ts
@@ -0,0 +1,116 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { StdevS } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test stdev.s function', () => {
+ const textFunction = new StdevS(FUNCTION_NAMES_STATISTICAL.STDEV_S);
+
+ describe('Stdev.s', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.7071067811865476);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.7071067811865476);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.7071067811865476);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1.4142135623730951);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBeCloseTo(0.707106781, 7);
+ });
+ it('Var1 is zero', () => {
+ const var1 = new NumberValueObject(0);
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);
+ });
+ it('Var1 is null', () => {
+ const var1 = new NullValueObject(0);
+ const result = textFunction.calculate(var1);
+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(37.61337610351884);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/stdev-s/index.ts b/packages/engine-formula/src/functions/statistical/stdev-s/index.ts
new file mode 100644
index 0000000000..0be765038e
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdev-s/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class StdevS extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.std(1);
+ }
+}
diff --git a/packages/engine-formula/src/functions/statistical/stdeva/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/stdeva/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a8fa4bd37d
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdeva/__tests__/index.spec.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Stdeva } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test stdeva function', () => {
+ const textFunction = new Stdeva(FUNCTION_NAMES_STATISTICAL.STDEVA);
+
+ describe('Stdeva', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.7071067811865476);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.7071067811865476);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.7071067811865476);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1.4142135623730951);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBeCloseTo(0.707106781, 7);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(30.04647742173025);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/stdeva/index.ts b/packages/engine-formula/src/functions/statistical/stdeva/index.ts
new file mode 100644
index 0000000000..aa64a6223d
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdeva/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Stdeva extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants, false);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.std(1);
+ }
+}
diff --git a/packages/engine-formula/src/functions/statistical/stdevpa/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/stdevpa/__tests__/index.spec.ts
new file mode 100644
index 0000000000..734382f94b
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdevpa/__tests__/index.spec.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Stdevpa } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test stdevpa function', () => {
+ const textFunction = new Stdevpa(FUNCTION_NAMES_STATISTICAL.STDEVPA);
+
+ describe('Stdevpa', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(28.648192160232153);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/stdevpa/index.ts b/packages/engine-formula/src/functions/statistical/stdevpa/index.ts
new file mode 100644
index 0000000000..eaa1e34512
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/stdevpa/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Stdevpa extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants, false);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.std();
+ }
+}
diff --git a/packages/engine-formula/src/functions/statistical/var-p/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/var-p/__tests__/index.spec.ts
new file mode 100644
index 0000000000..3103c1c9f3
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/var-p/__tests__/index.spec.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { VarP } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test var.p function', () => {
+ const textFunction = new VarP(FUNCTION_NAMES_STATISTICAL.VAR_P);
+
+ describe('VarP', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1212.656624489796);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/var-p/index.ts b/packages/engine-formula/src/functions/statistical/var-p/index.ts
new file mode 100644
index 0000000000..716d01873b
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/var-p/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class VarP extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.var();
+ }
+}
diff --git a/packages/engine-formula/src/functions/statistical/var-s/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/var-s/__tests__/index.spec.ts
new file mode 100644
index 0000000000..6f9cde0875
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/var-s/__tests__/index.spec.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { VarS } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test var.s function', () => {
+ const textFunction = new VarS(FUNCTION_NAMES_STATISTICAL.VAR_S);
+
+ describe('Var.s', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1414.766061904762);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/var-s/index.ts b/packages/engine-formula/src/functions/statistical/var-s/index.ts
new file mode 100644
index 0000000000..f89c8da7c5
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/var-s/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class VarS extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.var(1);
+ }
+}
diff --git a/packages/engine-formula/src/functions/statistical/vara/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/vara/__tests__/index.spec.ts
new file mode 100644
index 0000000000..04439e203c
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/vara/__tests__/index.spec.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Vara } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test vara function', () => {
+ const textFunction = new Vara(FUNCTION_NAMES_STATISTICAL.VARA);
+
+ describe('Vara', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(2);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.5);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(902.7908054545456);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/vara/index.ts b/packages/engine-formula/src/functions/statistical/vara/index.ts
new file mode 100644
index 0000000000..e82e24872a
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/vara/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Vara extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants, false);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.var(1);
+ }
+}
diff --git a/packages/engine-formula/src/functions/statistical/varpa/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/varpa/__tests__/index.spec.ts
new file mode 100644
index 0000000000..17ba87d740
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/varpa/__tests__/index.spec.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';
+import { Varpa } from '..';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../..';
+
+describe('Test varpa function', () => {
+ const textFunction = new Varpa(FUNCTION_NAMES_STATISTICAL.VARPA);
+
+ describe('Varpa', () => {
+ it('Var1 is number, var2 is number', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NumberValueObject(2);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+ });
+ it('Var1 is number, var2 is string', () => {
+ const var1 = new NumberValueObject(1);
+ let var2 = new StringValueObject('test');
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ var2 = new StringValueObject('2');
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+ });
+ it('Var1 is number, var2 is boolean', () => {
+ const var1 = new NumberValueObject(2);
+
+ let var2 = new BooleanValueObject(true);
+ let result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+
+ var2 = new BooleanValueObject(false);
+ result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(1);
+ });
+ it('Var1 is number, var2 is null', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new NullValueObject(0);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(0.25);
+ });
+ it('Var1 is number, var2 is error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ErrorValueObject(ErrorType.NA);
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Var1 is number, var2 is array includes error', () => {
+ const var1 = new NumberValueObject(1);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [0, ErrorType.VALUE],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Var1 is number, var2 is array not includes error', () => {
+ const var1 = new NumberValueObject(2);
+ const var2 = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false, null],
+ [0, '100', '2.34', 'test', -3, null],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(var1, var2);
+ expect(result.getValue()).toBe(820.7189140495869);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/statistical/varpa/index.ts b/packages/engine-formula/src/functions/statistical/varpa/index.ts
new file mode 100644
index 0000000000..88ad519d31
--- /dev/null
+++ b/packages/engine-formula/src/functions/statistical/varpa/index.ts
@@ -0,0 +1,36 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+
+export class Varpa extends BaseFunction {
+ override calculate(...variants: BaseValueObject[]) {
+ if (variants.length === 0) {
+ return new ErrorValueObject(ErrorType.NA);
+ }
+
+ const flattenArray = this.flattenArray(variants, false);
+
+ if (flattenArray.isError()) {
+ return flattenArray;
+ }
+
+ return flattenArray.var();
+ }
+}
diff --git a/packages/engine-formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.ts
index 8bc4cf1e68..42a34b3028 100644
--- a/packages/engine-formula/src/models/formula-data.model.ts
+++ b/packages/engine-formula/src/models/formula-data.model.ts
@@ -315,6 +315,8 @@ export class FormulaDataModel extends Disposable {
cellData: new ObjectMatrix(sheetConfig.cellData),
rowCount: sheetConfig.rowCount,
columnCount: sheetConfig.columnCount,
+ rowData: sheetConfig.rowData,
+ columnData: sheetConfig.columnData,
};
sheetNameMap[sheet.getName()] = sheet.getSheetId();
}
diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.ts
index 272db4207c..bb8a4686f0 100644
--- a/packages/engine-formula/src/services/current-data.service.ts
+++ b/packages/engine-formula/src/services/current-data.service.ts
@@ -309,6 +309,8 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC
cellData: new ObjectMatrix(sheetConfig.cellData),
rowCount: sheetConfig.rowCount,
columnCount: sheetConfig.columnCount,
+ rowData: sheetConfig.rowData,
+ columnData: sheetConfig.columnData,
};
sheetNameMap[sheet.getName()] = sheet.getSheetId();
}
diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.ts
index 8b0c89c48b..11d4281581 100644
--- a/packages/engine-formula/src/services/runtime.service.ts
+++ b/packages/engine-formula/src/services/runtime.service.ts
@@ -645,7 +645,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime
};
}
// String "00"
- if (vo.isString() && isRealNum(v as string)) {
+ if (vo.isString() && isRealNum(v)) {
return {
v,
t: CellValueType.FORCE_STRING,
diff --git a/packages/network/src/index.ts b/packages/network/src/index.ts
index be72a00e82..bfedfa8d37 100644
--- a/packages/network/src/index.ts
+++ b/packages/network/src/index.ts
@@ -26,3 +26,4 @@ export {
type SocketBodyType,
WebSocketService,
} from './services/web-socket/web-socket.service';
+export { type IRequestParams } from './services/http/http.service';
diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
index d16455ee61..76f2419c6a 100644
--- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
+++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
@@ -15,7 +15,7 @@
*/
import type { ICommandInfo, IUnitRange } from '@univerjs/core';
-import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import { Disposable, ICommandService, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
import type {
IDirtyUnitFeatureMap,
IDirtyUnitSheetNameMap,
@@ -132,7 +132,7 @@ export class TriggerCalculationController extends Disposable {
const allDirtyRanges: IUnitRange[] = [];
const allDirtyNameMap: IDirtyUnitSheetNameMap = {};
const allDirtyUnitFeatureMap: IDirtyUnitFeatureMap = {};
- const numfmtItemMap: INumfmtItemMap = this._formulaDataModel.getNumfmtItemMap();
+ const numfmtItemMap: INumfmtItemMap = Tools.deepClone(this._formulaDataModel.getNumfmtItemMap());
for (const command of commands) {
const conversion = this._activeDirtyManagerService.get(command.id);
diff --git a/packages/sheets-formula/src/locale/function-list/compatibility/en-US.ts b/packages/sheets-formula/src/locale/function-list/compatibility/en-US.ts
index e2e2784cd7..3cece47587 100644
--- a/packages/sheets-formula/src/locale/function-list/compatibility/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/compatibility/en-US.ts
@@ -422,7 +422,7 @@ export default {
},
},
STDEV: {
- description: 'Estimates standard deviation based on a sample',
+ description: 'Estimates standard deviation based on a sample. The standard deviation is a measure of how widely values are dispersed from the average value (the mean).',
abstract: 'Estimates standard deviation based on a sample',
links: [
{
@@ -431,12 +431,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a sample of a population.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 255 corresponding to a sample of a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
},
},
STDEVP: {
- description: 'Calculates standard deviation based on the entire population',
+ description: 'Calculates standard deviation based on the entire population given as arguments.',
abstract: 'Calculates standard deviation based on the entire population',
links: [
{
@@ -445,8 +445,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a population.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 255 corresponding to a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
},
},
TDIST: {
@@ -492,7 +492,7 @@ export default {
},
},
VAR: {
- description: 'Estimates variance based on a sample',
+ description: 'Estimates variance based on a sample.',
abstract: 'Estimates variance based on a sample',
links: [
{
@@ -501,12 +501,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a sample of a population.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 255 corresponding to a sample of a population.' },
},
},
VARP: {
- description: 'Calculates variance based on the entire population',
+ description: 'Calculates variance based on the entire population.',
abstract: 'Calculates variance based on the entire population',
links: [
{
@@ -515,8 +515,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a population.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 255 corresponding to a population.' },
},
},
WEIBULL: {
diff --git a/packages/sheets-formula/src/locale/function-list/compatibility/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/compatibility/ja-JP.ts
index d63cd508cd..e13c96882c 100644
--- a/packages/sheets-formula/src/locale/function-list/compatibility/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/compatibility/ja-JP.ts
@@ -422,7 +422,7 @@ export default {
},
},
STDEV: {
- description: '引数を正規母集団の標本と見なし、標本に基づいて母集団の標準偏差の推定値を返します。',
+ description: '標本に基づいて標準偏差の推定値を計算します。 標準偏差とは、統計的な対象となる値がその平均からどれだけ広い範囲に分布しているかを計測したものです。',
abstract: '引数を正規母集団の標本と見なし、標本に基づいて母集団の標準偏差の推定値を返します。',
links: [
{
@@ -431,12 +431,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: '母集団の標本に対応する最初の数値引数を指定します。' },
+ number2: { name: 'number2', detail: '母集団のサンプルに対応する引数 2 から 255 の数値。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
},
},
STDEVP: {
- description: '引数を母集団全体と見なし、母集団の標準偏差を返します。',
+ description: '引数を母集団全体であると見なして、母集団の標準偏差を計算します。',
abstract: '引数を母集団全体と見なし、母集団の標準偏差を返します。',
links: [
{
@@ -445,8 +445,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: '母集団に対応する最初の数値引数を指定します。' },
+ number2: { name: '数値 2', detail: '母集団に対応する引数 2 ~ 255 を数える。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
},
},
TDIST: {
@@ -501,8 +501,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: '母集団の標本に対応する最初の数値引数を指定します。' },
+ number2: { name: '数値 2', detail: '母集団のサンプルに対応する引数 2 から 255 の数値。' },
},
},
VARP: {
@@ -515,8 +515,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: '母集団に対応する最初の数値引数を指定します。' },
+ number2: { name: '数値 2', detail: '母集団に対応する引数 2 ~ 255 を数える。' },
},
},
WEIBULL: {
diff --git a/packages/sheets-formula/src/locale/function-list/compatibility/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/compatibility/zh-CN.ts
index 7f08b03845..17eda91ea2 100644
--- a/packages/sheets-formula/src/locale/function-list/compatibility/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/compatibility/zh-CN.ts
@@ -422,7 +422,7 @@ export default {
},
},
STDEV: {
- description: '基于样本估算标准偏差',
+ description: '根据样本估计标准偏差。 标准偏差可以测量值在平均值(中值)附近分布的范围大小。',
abstract: '基于样本估算标准偏差',
links: [
{
@@ -431,12 +431,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体样本的第一个数值参数。' },
+ number2: { name: '数值 2', detail: '对应于总体样本的 2 到 255 个数值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
},
},
STDEVP: {
- description: '基于整个样本总体计算标准偏差',
+ description: '根据作为参数给定的整个总体计算标准偏差。',
abstract: '基于整个样本总体计算标准偏差',
links: [
{
@@ -445,8 +445,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体的第一个数值参数。' },
+ number2: { name: '数值 2', detail: '对应于总体的 2 到 255 个数值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
},
},
TDIST: {
@@ -492,7 +492,7 @@ export default {
},
},
VAR: {
- description: '基于样本估算方差',
+ description: '计算基于给定样本的方差。',
abstract: '基于样本估算方差',
links: [
{
@@ -501,12 +501,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体样本的第一个数值参数。' },
+ number2: { name: '数值 2', detail: '应于总体样本的 2 到 255 个数值参数。' },
},
},
VARP: {
- description: '计算基于样本总体的方差',
+ description: '计算基于样本总体的方差。',
abstract: '计算基于样本总体的方差',
links: [
{
@@ -515,8 +515,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体的第一个数值参数。' },
+ number2: { name: '数值 2', detail: '对应于总体的 2 到 255 个数值参数。' },
},
},
WEIBULL: {
diff --git a/packages/sheets-formula/src/locale/function-list/date/en-US.ts b/packages/sheets-formula/src/locale/function-list/date/en-US.ts
index d01386fd09..0e60a48e03 100644
--- a/packages/sheets-formula/src/locale/function-list/date/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/date/en-US.ts
@@ -68,7 +68,7 @@ export default {
},
],
functionParameter: {
- serialNumber: { name: 'Serial Number', detail: 'The date of the day you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008.' },
+ serialNumber: { name: 'serial_number', detail: 'The date of the day you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008.' },
},
},
DAYS: {
@@ -109,8 +109,8 @@ export default {
},
],
functionParameter: {
- startDate: { name: 'Start Date', detail: 'A date that represents the start date. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.' },
- months: { name: 'Months', detail: 'The number of months before or after start_date. A positive value for months yields a future date; a negative value yields a past date.' },
+ startDate: { name: 'start_date', detail: 'A date that represents the start date. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.' },
+ months: { name: 'months', detail: 'The number of months before or after start_date. A positive value for months yields a future date; a negative value yields a past date.' },
},
},
EOMONTH: {
@@ -179,7 +179,7 @@ export default {
},
],
functionParameter: {
- serialNumber: { name: 'Serial Number', detail: 'Required. The date of the month you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008.' },
+ serialNumber: { name: 'serial_number', detail: 'Required. The date of the month you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008.' },
},
},
NETWORKDAYS: {
@@ -344,7 +344,7 @@ export default {
},
],
functionParameter: {
- serialNumber: { name: 'Serial Number', detail: 'The date of the year you want to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.' },
+ serialNumber: { name: 'serial_number', detail: 'The date of the year you want to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.' },
},
},
YEARFRAC: {
diff --git a/packages/sheets-formula/src/locale/function-list/date/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/date/zh-CN.ts
index ae496e2c7b..b909fee338 100644
--- a/packages/sheets-formula/src/locale/function-list/date/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/date/zh-CN.ts
@@ -344,7 +344,7 @@ export default {
},
],
functionParameter: {
- serialNumber: { name: '日期序列号', detail: '要查找的年份的日期。 应使用 DATE 函数输入日期,或者将日期作为其他公式或函数的结果输入。 例如,使用函数 DATE(2008,5,23) 输入 2008 年 5 月 23 日。 如果日期以文本形式输入,则会出现问题。' },
+ serialNumber: { name: '日期序列号', detail: '要查找的年份的日期。 应使用 DATE 函数输入日期,或者将日期作为其他公式或函数的结果输入。 例如,使用函数 DATE(2008,5,23) 输入 2008 年 5 月 23 日。' },
},
},
YEARFRAC: {
diff --git a/packages/sheets-formula/src/locale/function-list/information/en-US.ts b/packages/sheets-formula/src/locale/function-list/information/en-US.ts
index 503f680c8b..759a53f39b 100644
--- a/packages/sheets-formula/src/locale/function-list/information/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/information/en-US.ts
@@ -67,7 +67,7 @@ export default {
},
],
functionParameter: {
- value: { name: 'Value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISERR: {
@@ -80,8 +80,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISERROR: {
@@ -94,8 +93,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISEVEN: {
@@ -136,8 +134,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISNA: {
@@ -150,8 +147,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISNONTEXT: {
@@ -164,8 +160,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISNUMBER: {
@@ -178,8 +173,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISODD: {
@@ -188,7 +182,7 @@ export default {
links: [
{
title: 'Instruction',
- url: 'https://support.microsoft.com/en-us/office/is-functions-0f2d7971-6019-40a0-a171-f2d869135665',
+ url: 'https://support.microsoft.com/en-us/office/isodd-function-1208a56d-4f10-4f44-a5fc-648cafd6c07a',
},
],
functionParameter: {
@@ -220,8 +214,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
ISTEXT: {
@@ -234,8 +227,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The value that you want tested. The value argument can be a blank (empty cell), error, logical value, text, number, or reference value, or a name referring to any of these.' },
},
},
N: {
diff --git a/packages/sheets-formula/src/locale/function-list/information/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/information/ja-JP.ts
index 57e1ec6f2e..777fe98511 100644
--- a/packages/sheets-formula/src/locale/function-list/information/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/information/ja-JP.ts
@@ -188,7 +188,7 @@ export default {
links: [
{
title: '指導',
- url: 'https://support.microsoft.com/ja-jp/office/is-%E9%96%A2%E6%95%B0-0f2d7971-6019-40a0-a171-f2d869135665',
+ url: 'https://support.microsoft.com/ja-jp/office/isodd-%E9%96%A2%E6%95%B0-1208a56d-4f10-4f44-a5fc-648cafd6c07a',
},
],
functionParameter: {
diff --git a/packages/sheets-formula/src/locale/function-list/information/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/information/zh-CN.ts
index df422e665b..938b793861 100644
--- a/packages/sheets-formula/src/locale/function-list/information/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/information/zh-CN.ts
@@ -80,8 +80,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
ISERROR: {
@@ -94,8 +93,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
ISEVEN: {
@@ -136,8 +134,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
ISNA: {
@@ -150,8 +147,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
ISNONTEXT: {
@@ -164,8 +160,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
ISNUMBER: {
@@ -178,8 +173,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
ISODD: {
@@ -188,7 +182,7 @@ export default {
links: [
{
title: '教学',
- url: 'https://support.microsoft.com/zh-cn/office/is-%E5%87%BD%E6%95%B0-0f2d7971-6019-40a0-a171-f2d869135665',
+ url: 'https://support.microsoft.com/zh-cn/office/isodd-%E5%87%BD%E6%95%B0-1208a56d-4f10-4f44-a5fc-648cafd6c07a',
},
],
functionParameter: {
@@ -220,8 +214,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
ISTEXT: {
@@ -234,8 +227,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: ' 指的是要测试的值。 参数 value 可以是空白(空单元格)、错误值、逻辑值、文本、数字、引用值,或者引用要测试的以上任意值的名称。' },
},
},
N: {
diff --git a/packages/sheets-formula/src/locale/function-list/logical/en-US.ts b/packages/sheets-formula/src/locale/function-list/logical/en-US.ts
index e6ce58fcbd..c3b371a401 100644
--- a/packages/sheets-formula/src/locale/function-list/logical/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/logical/en-US.ts
@@ -25,8 +25,8 @@ export default {
},
],
functionParameter: {
- logical1: { name: 'Logical 1', detail: 'The first condition that you want to test that can evaluate to either TRUE or FALSE.' },
- logical2: { name: 'Logical 2', detail: 'Additional conditions that you want to test that can evaluate to either TRUE or FALSE, up to a maximum of 255 conditions.' },
+ logical1: { name: 'logical1', detail: 'The first condition that you want to test that can evaluate to either TRUE or FALSE.' },
+ logical2: { name: 'logical2', detail: 'Additional conditions that you want to test that can evaluate to either TRUE or FALSE, up to a maximum of 255 conditions.' },
},
},
BYCOL: {
@@ -81,13 +81,13 @@ export default {
},
],
functionParameter: {
- logicalTest: { name: 'Logical test', detail: 'The condition you want to test.' },
+ logicalTest: { name: 'logical_test', detail: 'The condition you want to test.' },
valueIfTrue: {
- name: 'Value if true',
+ name: 'value_if_true',
detail: 'The value that you want returned if the result of logical_test is TRUE.',
},
valueIfFalse: {
- name: 'Value if false',
+ name: 'value_if_false',
detail: 'The value that you want returned if the result of logical_test is FALSE.',
},
},
@@ -102,8 +102,8 @@ export default {
},
],
functionParameter: {
- value: { name: 'Value', detail: 'The argument that is checked for an error.' },
- valueIfError: { name: 'Value if error', detail: 'The value to return if the formula evaluates to an error. The following error types are evaluated: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.' },
+ value: { name: 'value', detail: 'The argument that is checked for an error.' },
+ valueIfError: { name: 'value_if_error', detail: 'The value to return if the formula evaluates to an error. The following error types are evaluated: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!.' },
},
},
IFNA: {
diff --git a/packages/sheets-formula/src/locale/function-list/lookup/en-US.ts b/packages/sheets-formula/src/locale/function-list/lookup/en-US.ts
index 5cab391d4f..82e71bb551 100644
--- a/packages/sheets-formula/src/locale/function-list/lookup/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/lookup/en-US.ts
@@ -106,7 +106,7 @@ export default {
},
},
COLUMN: {
- description: 'Returns the column number of a reference',
+ description: 'Returns the column number of the given cell reference.',
abstract: 'Returns the column number of a reference',
links: [
{
@@ -115,12 +115,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: 'reference', detail: 'The cell or range of cells for which you want to return the column number.' },
},
},
COLUMNS: {
- description: 'Returns the number of columns in a reference',
+ description: 'Returns the number of columns in an array or reference.',
abstract: 'Returns the number of columns in a reference',
links: [
{
@@ -129,8 +128,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'An array or array formula, or a reference to a range of cells for which you want the number of columns.' },
},
},
DROP: {
@@ -274,7 +272,7 @@ export default {
},
},
INDEX: {
- description: 'Uses an index to choose a value from a reference or array',
+ description: 'Returns the reference of the cell at the intersection of a particular row and column. If the reference is made up of non-adjacent selections, you can pick the selection to look in.',
abstract: 'Uses an index to choose a value from a reference or array',
links: [
{
@@ -283,12 +281,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: 'reference', detail: 'A reference to one or more cell ranges.\nIf you are entering a non-adjacent range for the reference, enclose reference in parentheses.\nIf each area in reference contains only one row or column, the row_num or column_num argument, respectively, is optional. For example, for a single row reference, use INDEX(reference,,column_num).\nIf array has more than one row and more than one column, and only row_num or column_num is used, INDEX returns an array of the entire row or column in array.' },
+ rowNum: { name: 'row_num', detail: 'The number of the row in reference from which to return a reference.' },
+ columnNum: { name: 'column_num', detail: 'The number of the column in reference from which to return a reference.' },
+ areaNum: { name: 'area_num', detail: 'Selects a range in reference from which to return the intersection of row_num and column_num. The first area selected or entered is numbered 1, the second is 2, and so on. If area_num is omitted, INDEX uses area 1. The areas listed here must all be located on one sheet. If you specify areas that are not on the same sheet as each other, it will cause a #VALUE! error. If you need to use ranges that are located on different sheets from each other, it is recommended that you use the array form of the INDEX function, and use another function to calculate the range that makes up the array. For example, you could use the CHOOSE function to calculate which range will be used.' },
},
},
INDIRECT: {
- description: 'Returns a reference indicated by a text value',
+ description: 'Returns the reference specified by a text string. References are immediately evaluated to display their contents.',
abstract: 'Returns a reference indicated by a text value',
links: [
{
@@ -297,8 +297,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ refText: { name: 'ref_text', detail: 'A reference to a cell that contains an A1-style reference, an R1C1-style reference, a name defined as a reference, or a reference to a cell as a text string. If ref_text is not a valid cell reference, INDIRECT returns the #REF! error value.\nIf ref_text refers to a cell range outside the row limit of 1,048,576 or the column limit of 16,384 (XFD), INDIRECT returns a #REF! error.' },
+ a1: { name: 'a1', detail: 'A logical value that specifies what type of reference is contained in the cell ref_text.\nIf a1 is TRUE or omitted, ref_text is interpreted as an A1-style reference.\nIf a1 is FALSE, ref_text is interpreted as an R1C1-style reference.' },
},
},
LOOKUP: {
@@ -350,11 +350,11 @@ export default {
},
],
functionParameter: {
- reference: { name: 'Reference', detail: 'The reference from which you want to base the offset. Reference must refer to a cell or range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value.' },
- rows: { name: 'Rows', detail: 'The number of rows, up or down, that you want the upper-left cell to refer to. Using 5 as the rows argument specifies that the upper-left cell in the reference is five rows below reference. Rows can be positive (which means below the starting reference) or negative (which means above the starting reference).' },
- cols: { name: 'Columns', detail: 'The number of columns, to the left or right, that you want the upper-left cell of the result to refer to. Using 5 as the cols argument specifies that the upper-left cell in the reference is five columns to the right of reference. Cols can be positive (which means to the right of the starting reference) or negative (which means to the left of the starting reference).' },
- height: { name: 'Height', detail: 'The height, in number of rows, that you want the returned reference to be. Height must be a positive number.' },
- width: { name: 'Width', detail: 'The width, in number of columns, that you want the returned reference to be. Width must be a positive number.' },
+ reference: { name: 'reference', detail: 'The reference from which you want to base the offset. Reference must refer to a cell or range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value.' },
+ rows: { name: 'rows', detail: 'The number of rows, up or down, that you want the upper-left cell to refer to. Using 5 as the rows argument specifies that the upper-left cell in the reference is five rows below reference. Rows can be positive (which means below the starting reference) or negative (which means above the starting reference).' },
+ cols: { name: 'columns', detail: 'The number of columns, to the left or right, that you want the upper-left cell of the result to refer to. Using 5 as the cols argument specifies that the upper-left cell in the reference is five columns to the right of reference. Cols can be positive (which means to the right of the starting reference) or negative (which means to the left of the starting reference).' },
+ height: { name: 'height', detail: 'The height, in number of rows, that you want the returned reference to be. Height must be a positive number.' },
+ width: { name: 'width', detail: 'The width, in number of columns, that you want the returned reference to be. Width must be a positive number.' },
},
},
ROW: {
@@ -367,12 +367,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: 'reference', detail: 'The cell or range of cells for which you want the row number.' },
},
},
ROWS: {
- description: 'Returns the number of rows in a reference',
+ description: 'Returns the number of rows in an array or reference.',
abstract: 'Returns the number of rows in a reference',
links: [
{
@@ -381,8 +380,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'An array, an array formula, or a reference to a range of cells for which you want the number of rows.' },
},
},
RTD: {
diff --git a/packages/sheets-formula/src/locale/function-list/lookup/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/lookup/ja-JP.ts
index 3048a53439..510189cbd0 100644
--- a/packages/sheets-formula/src/locale/function-list/lookup/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/lookup/ja-JP.ts
@@ -95,7 +95,7 @@ export default {
},
},
COLUMN: {
- description: 'セル参照の列番号を返します。',
+ description: '指定された セル参照の列番号を返します。',
abstract: 'セル参照の列番号を返します。',
links: [
{
@@ -104,12 +104,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: '範囲', detail: '列番号を調べるセルまたは範囲を指定します。' },
},
},
COLUMNS: {
- description: 'セル参照の列数を返します。',
+ description: '配列またはセル参照の列数を返します。',
abstract: 'セル参照の列数を返します。',
links: [
{
@@ -118,8 +117,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: 'An array or array formula, or a reference to a range of cells for which you want the num列数を計算する配列、配列数式、またはセル範囲の参照を指定します。' },
},
},
DROP: {
@@ -263,7 +261,7 @@ export default {
},
},
INDEX: {
- description: 'セル参照または配列から、指定された位置の値を返します。',
+ description: '指定された行と列が交差する位置にあるセルの参照を返します。 隣接しない複数のセル範囲を指定した場合、その中から任意の領域を選択できます。',
abstract: 'セル参照または配列から、指定された位置の値を返します。',
links: [
{
@@ -272,12 +270,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: '参照', detail: '1 つまたは複数のセルの参照を指定します。\n隣接しない範囲を参照として入力する場合は、参照をかっこで囲みます。\n参照の中の各領域に行または列が 1 つしか含まれていない場合は、行番号または列番号の引数はそれぞれ省略することができます。 たとえば、範囲が 1 行のみである場合は、INDEX(範囲,列番号) と指定できます。\n配列が複数行および複数列で構成され、行番号または列番号のどちらか一方しか指定されていない場合、配列の中にある行または列全体の配列が返されます。' },
+ rowNum: { name: '行番号', detail: '範囲の中にあり、セル参照を返すセルの行位置を数値で返します。' },
+ columnNum: { name: '列番号', detail: '範囲の中にあり、セル参照を返すセルの列位置を数値で返します。' },
+ areaNum: { name: '領域番号', detail: '行番号と列番号の共通部分を返す参照の範囲を選択します。 最初に選択または入力された領域の領域番号が 1 となり、以下、2 番目の領域は 2 というように続きます。 領域番号を省略すると、INDEX は 1 の領域を使用します。 ここで表示される領域はすべて 1 つのシート上に置かれている必要があります。 他の領域と同じシート上に存在しない領域を指定した場合、#VALUE! エラーが発生します。 相互に異なるシート上に置かれている範囲を使用する必要がある場合は、INDEX 関数の配列形式を使用し、別の関数を使用して配列を形成する範囲を計算することをお勧めします。 たとえば、CHOOSE 関数を使用して、どの範囲が使用されるかを計算することができます。' },
},
},
INDIRECT: {
- description: '参照文字列によって指定されるセルに入力されている文字列を介して、間接的にセルを指定します。',
+ description: '指定される文字列への参照を返します。 セル参照はすぐに計算され、結果としてセルの内容が表示されます。',
abstract: '参照文字列によって指定されるセルに入力されている文字列を介して、間接的にセルを指定します。',
links: [
{
@@ -286,8 +286,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ refText: { name: '参照文字列', detail: ' A1 形式、R1C1 形式の参照、参照として定義されている名前が入力されているセルへの参照、または文字列としてのセルへの参照を指定します。 参照文字列に適切なセル参照を指定していない場合、エラー値 #REF! が返されます。\n参照文字列で行数の上限 1,048,576 または列数の上限 16,384 (XFD) 範囲外を参照している場合、 INDIRECT は、エラー値 #REF! を返します 。' },
+ a1: { name: '参照形式', detail: '参照文字列で指定されたセルに含まれるセル参照の種類を、論理値で指定します。\n参照形式に TRUE を指定するか省略すると、参照文字列には A1 形式のセル参照が入力されていると見なされます。\n参照形式に FALSE を指定すると、参照文字列には R1C1 形式のセル参照が入力されていると見なされます。' },
},
},
LOOKUP: {
@@ -347,7 +347,7 @@ export default {
},
},
ROW: {
- description: 'セル参照の行番号を返します。',
+ description: '引数として指定された配列の行番号を返します。',
abstract: 'セル参照の行番号を返します。',
links: [
{
@@ -356,12 +356,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: '範囲', detail: '行番号を調べるセルまたはセル範囲の参照を指定します。' },
},
},
ROWS: {
- description: 'セル参照の行数を返します。',
+ description: 'セル範囲または配列の行数を返します。',
abstract: 'セル参照の行数を返します。',
links: [
{
@@ -370,8 +369,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: '行数を計算する配列、配列数式、またはセル範囲の参照を指定します。' },
},
},
RTD: {
diff --git a/packages/sheets-formula/src/locale/function-list/lookup/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/lookup/zh-CN.ts
index 94221751b9..eb5bbf2d69 100644
--- a/packages/sheets-formula/src/locale/function-list/lookup/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/lookup/zh-CN.ts
@@ -96,7 +96,7 @@ export default {
},
},
COLUMN: {
- description: '返回引用的列号',
+ description: '返回给定单元格引用的列号。',
abstract: '返回引用的列号',
links: [
{
@@ -105,12 +105,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: '引用', detail: '要返回其列号的单元格或单元格范围。' },
},
},
COLUMNS: {
- description: '返回引用中包含的列数',
+ description: '返回数组或引用的列数。',
abstract: '返回引用中包含的列数',
links: [
{
@@ -119,8 +118,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '要计算列数的数组、数组公式或是对单元格区域的引用。' },
},
},
DROP: {
@@ -264,7 +262,7 @@ export default {
},
},
INDEX: {
- description: '使用索引从引用或数组中选择值',
+ description: '返回指定的行与列交叉处的单元格引用。 如果引用由不连续的选定区域组成,可以选择某一选定区域。',
abstract: '使用索引从引用或数组中选择值',
links: [
{
@@ -273,12 +271,14 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: '引用', detail: '对一个或多个单元格区域的引用。\n如果为引用输入一个不连续的区域,必须将其用括号括起来。\n如果引用中的每个区域均只包含一行(或一列),则 row_num(或 column_num)为可选参数。 例如,对于单行的引用,可以使用函数 INDEX(reference,,column_num)。\n如果数组有多行和多列,但只使用 row_num 或 column_num,函数 INDEX 返回数组中的整行或整列,且返回值也为数组。' },
+ rowNum: { name: '行号', detail: '引用中某行的行号,函数从该行返回一个引用。' },
+ columnNum: { name: '列号', detail: '引用中某列的列标,函数从该列返回一个引用。' },
+ areaNum: { name: '区域编号', detail: '选择要返回 row_num 和 column_num 的交叉点的引用区域。 选择或输入的第一个区域的编号为 1,第二个的编号为 2,依此类推。 如果省略 area_num,则 INDEX 使用区域 1。 此处列出的区域必须全部位于一张工作表。 如果指定的区域不位于同一个工作表,将导致 #VALUE!。 错误。 如果需要使用的范围彼此位于不同工作表,建议使用函数 INDEX 的数组形式,并使用其他函数来计算构成数组的范围。 例如,可以使用 CHOOSE 函数计算将使用的范围。' },
},
},
INDIRECT: {
- description: '返回由文本值指定的引用',
+ description: '返回由文本字符串指定的引用。 此函数立即对引用进行计算,并显示其内容。',
abstract: '返回由文本值指定的引用',
links: [
{
@@ -287,8 +287,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ refText: { name: '引用文本', detail: '对包含 A1 样式引用、R1C1 样式引用、定义为引用的名称或作为文本字符串引用的单元格的引用的引用。 如果ref_text不是有效的单元格引用,INDIRECT 将返回 #REF! 。\n如果ref_text引用的单元格区域超出了行限制 1,048,576 或列限制 16,384 (XFD) ,INDIRECT 将返回 #REF! 错误。' },
+ a1: { name: '引用类型', detail: '一个逻辑值,用于指定包含在单元格 ref_text 中的引用的类型。\n如果 a1 为 TRUE 或省略,ref_text 被解释为 A1-样式的引用。\n如果 a1 为 FALSE,则将 ref_text 解释为 R1C1 样式的引用。' },
},
},
LOOKUP: {
@@ -345,7 +345,7 @@ export default {
},
},
ROW: {
- description: '返回引用的行号',
+ description: '返回给定单元格引用的行号。',
abstract: '返回引用的行号',
links: [
{
@@ -354,12 +354,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ reference: { name: '引用', detail: '需要得到其行号的单元格或单元格区域。' },
},
},
ROWS: {
- description: '返回引用中的行数',
+ description: '返回数组或引用的行数。',
abstract: '返回引用中的行数',
links: [
{
@@ -368,8 +367,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '需要得到其行数的数组、数组公式或对单元格区域的引用。' },
},
},
RTD: {
diff --git a/packages/sheets-formula/src/locale/function-list/math/en-US.ts b/packages/sheets-formula/src/locale/function-list/math/en-US.ts
index 5ea81a78c4..94b47bff9c 100644
--- a/packages/sheets-formula/src/locale/function-list/math/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/math/en-US.ts
@@ -631,7 +631,7 @@ export default {
},
},
MOD: {
- description: 'Returns the remainder from division',
+ description: 'Returns the remainder after number is divided by divisor. The result has the same sign as divisor.',
abstract: 'Returns the remainder from division',
links: [
{
@@ -640,8 +640,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: 'number', detail: 'The number for which you want to find the remainder.' },
+ divisor: { name: 'divisor', detail: 'The number by which you want to divide number' },
},
},
MROUND: {
@@ -715,7 +715,7 @@ export default {
},
},
POWER: {
- description: 'Returns the result of a number raised to a power',
+ description: 'Returns the result of a number raised to a power.',
abstract: 'Returns the result of a number raised to a power',
links: [
{
@@ -724,12 +724,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: 'number', detail: 'The base number. It can be any real number.' },
+ power: { name: 'power', detail: 'The exponent to which the base number is raised.' },
},
},
PRODUCT: {
- description: 'Multiplies its arguments',
+ description: 'Multiplies all the numbers given as arguments and returns the product.',
abstract: 'Multiplies its arguments',
links: [
{
@@ -738,8 +738,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number or range that you want to multiply.' },
+ number2: { name: 'number2', detail: 'Additional numbers or ranges that you want to multiply, up to a maximum of 255 arguments.' },
},
},
QUOTIENT: {
@@ -995,7 +995,7 @@ export default {
},
},
SUBTOTAL: {
- description: 'Returns a subtotal in a list or database',
+ description: 'Returns a subtotal in a list or database.',
abstract: 'Returns a subtotal in a list or database',
links: [
{
@@ -1004,8 +1004,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ functionNum: { name: 'function_num', detail: 'The number 1-11 or 101-111 that specifies the function to use for the subtotal. 1-11 includes manually-hidden rows, while 101-111 excludes them; filtered-out cells are always excluded.' },
+ ref1: { name: 'ref1', detail: 'The first named range or reference for which you want the subtotal.' },
+ ref2: { name: 'ref2', detail: 'Named ranges or references 2 to 254 for which you want the subtotal.' },
},
},
SUM: {
@@ -1039,15 +1040,15 @@ export default {
],
functionParameter: {
range: {
- name: 'Range',
+ name: 'range',
detail: 'The range of cells that you want evaluated by criteria.',
},
criteria: {
- name: 'Criteria',
+ name: 'criteria',
detail: 'The criteria in the form of a number, expression, a cell reference, text, or a function that defines which cells will be added. Wildcard characters can be included - a question mark (?) to match any single character, an asterisk (*) to match any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) preceding the character.',
},
sumRange: {
- name: 'Sum Range',
+ name: 'sum_range',
detail: 'The actual cells to add, if you want to add cells other than those specified in the range argument. If the sum_range argument is omitted, Excel adds the cells that are specified in the range argument (the same cells to which the criteria is applied).',
},
},
@@ -1062,11 +1063,11 @@ export default {
},
],
functionParameter: {
- sumRange: { name: 'Sum Range', detail: 'The range of cells to sum.' },
- criteriaRange1: { name: 'Criteria Range 1', detail: 'The range that is tested using Criteria 1. Criteria Range 1 and Criteria 1 set up a search pair whereby a range is searched for specific criteria. Once items in the range are found, their corresponding values in Sum Range are added.' },
- criteria1: { name: 'Criteria 1', detail: 'The criteria that defines which cells in Criteria Range 1 will be added. For example, criteria can be entered as 32, ">32", B4, "apples", or "32".' },
- criteriaRange2: { name: 'Criteria Range 2', detail: 'Additional ranges. You can enter up to 127 range pairs.' },
- criteria2: { name: 'Criteria 2', detail: 'Additional associated criteria. You can enter up to 127 criteria pairs.' },
+ sumRange: { name: 'sum_range', detail: 'The range of cells to sum.' },
+ criteriaRange1: { name: 'criteria_range1 ', detail: 'The range that is tested using criteria1. criteria_range1 and criteria1 set up a search pair whereby a range is searched for specific criteria. Once items in the range are found, their corresponding values in sum_range are added.' },
+ criteria1: { name: 'criteria1', detail: 'The criteria that defines which cells in criteria_range1 will be added. For example, criteria can be entered as 32, ">32", B4, "apples", or "32".' },
+ criteriaRange2: { name: 'criteriaRange2', detail: 'Additional ranges. You can enter up to 127 range pairs.' },
+ criteria2: { name: 'criteria2', detail: 'Additional associated criteria. You can enter up to 127 criteria pairs.' },
},
},
SUMPRODUCT: {
diff --git a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts
index 0ad6ea3676..e57e33731e 100644
--- a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts
@@ -631,7 +631,7 @@ export default {
},
},
MOD: {
- description: '数値を除算したときの剰余を返します。',
+ description: '数値を除数で割ったときの剰余を返します。 戻り値は除数と同じ符号になります。',
abstract: '数値を除算したときの剰余を返します。',
links: [
{
@@ -640,8 +640,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: '数値', detail: '除算の分子となる数値を指定します。' },
+ divisor: { name: '除数', detail: '除算の分母となる数値を指定します。' },
},
},
MROUND: {
@@ -724,12 +724,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: 'number', detail: 'べき乗の底を指定します。 数値には任意の実数を指定することができます。' },
+ power: { name: 'power', detail: ' 数値を底とするべき乗の指数を指定します。' },
},
},
PRODUCT: {
- description: '引数リストの積を返します。',
+ description: 'は、引数として指定されたすべての数値を乗算し、製品を返します。',
abstract: '引数リストの積を返します。',
links: [
{
@@ -738,8 +738,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: ' 積を計算する最初の数値または範囲を指定します。' },
+ number2: { name: '数値 2', detail: '積を計算する 2 番目以降の数値または範囲を指定します (引数は 1 ~ 255 個まで指定できます)。' },
},
},
QUOTIENT: {
@@ -1004,8 +1004,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ functionNum: { name: '集計方法', detail: '番号 1 ~ 11 または 101 ~ 111 を集計に使用する関数として指定します。 1 ~ 11 には手動で非表示にした行が含まれるのに対して、101 ~ 111 ではそれらを除外します。つまり、フィルター処理されたセルは常に除外されます。' },
+ ref1: { name: '範囲 1', detail: '集計する最初の名前付き範囲または参照を指定します。' },
+ ref2: { name: '範囲 2', detail: '集計する名前付き範囲または参照を 2 ~ 254 個まで指定します。' },
},
},
SUM: {
diff --git a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts
index 9cd6ab7448..6d1de0091d 100644
--- a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts
@@ -630,7 +630,7 @@ export default {
},
},
MOD: {
- description: '返回除法的余数',
+ description: '返回两数相除的余数。 结果的符号与除数相同。',
abstract: '返回除法的余数',
links: [
{
@@ -639,8 +639,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: '数值', detail: '要计算余数的被除数' },
+ divisor: { name: '除数', detail: '除数' },
},
},
MROUND: {
@@ -714,7 +714,7 @@ export default {
},
},
POWER: {
- description: '返回数的乘幂',
+ description: '返回数字乘幂的结果。',
abstract: '返回数的乘幂',
links: [
{
@@ -723,12 +723,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: '基数', detail: ' 基数。 可为任意实数。' },
+ power: { name: '指数', detail: '基数乘幂运算的指数。' },
},
},
PRODUCT: {
- description: '将其参数相乘',
+ description: '将作为参数提供的所有数字相乘,并返回乘积。',
abstract: '将其参数相乘',
links: [
{
@@ -737,8 +737,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '要相乘的第一个数字或范围。' },
+ number2: { name: '数值 2', detail: '要相乘的其他数字或单元格区域,最多可以使用 255 个参数。' },
},
},
QUOTIENT: {
@@ -996,7 +996,7 @@ export default {
},
},
SUBTOTAL: {
- description: '返回列表或数据库中的分类汇总',
+ description: '返回列表或数据库中的分类汇总。',
abstract: '返回列表或数据库中的分类汇总',
links: [
{
@@ -1005,8 +1005,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ functionNum: { name: '函数编号', detail: '数字 1-11 或 101-111,用于指定要为分类汇总使用的函数。 如果使用 1-11,将包括手动隐藏的行,如果使用 101-111,则排除手动隐藏的行;始终排除已筛选掉的单元格。' },
+ ref1: { name: '引用1', detail: '要对其进行分类汇总计算的第一个命名区域或引用。' },
+ ref2: { name: '引用2', detail: '要对其进行分类汇总计算的第 2 个至第 254 个命名区域或引用。' },
},
},
SUM: {
diff --git a/packages/sheets-formula/src/locale/function-list/statistical/en-US.ts b/packages/sheets-formula/src/locale/function-list/statistical/en-US.ts
index 6929d90143..a32867ed3e 100644
--- a/packages/sheets-formula/src/locale/function-list/statistical/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/statistical/en-US.ts
@@ -1335,7 +1335,7 @@ export default {
},
},
STDEV_P: {
- description: 'Calculates standard deviation based on the entire population',
+ description: 'Calculates standard deviation based on the entire population given as arguments (ignores logical values and text).',
abstract: 'Calculates standard deviation based on the entire population',
links: [
{
@@ -1344,12 +1344,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a population.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 254 corresponding to a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
},
},
STDEV_S: {
- description: 'Estimates standard deviation based on a sample',
+ description: 'Estimates standard deviation based on a sample (ignores logical values and text in the sample).',
abstract: 'Estimates standard deviation based on a sample',
links: [
{
@@ -1358,12 +1358,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a sample of a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 254 corresponding to a sample of a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
},
},
STDEVA: {
- description: 'Estimates standard deviation based on a sample, including numbers, text, and logical values',
+ description: 'Estimates standard deviation based on a sample, including numbers, text, and logical values.',
abstract: 'Estimates standard deviation based on a sample, including numbers, text, and logical values',
links: [
{
@@ -1372,12 +1372,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: 'value1', detail: 'The first value argument corresponding to a sample of a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
+ value2: { name: 'value2', detail: 'Value arguments 2 to 254 corresponding to a sample of a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
},
},
STDEVPA: {
- description: 'Calculates standard deviation based on the entire population, including numbers, text, and logical values',
+ description: 'Calculates standard deviation based on the entire population given as arguments, including text and logical values.',
abstract: 'Calculates standard deviation based on the entire population, including numbers, text, and logical values',
links: [
{
@@ -1386,8 +1386,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: 'value1', detail: 'The first value argument corresponding to a population.' },
+ value2: { name: 'value2', detail: 'Value arguments 2 to 254 corresponding to a population. You can also use a single array or a reference to an array instead of arguments separated by commas.' },
},
},
STEYX: {
@@ -1517,7 +1517,7 @@ export default {
},
},
VAR_P: {
- description: 'Calculates variance based on the entire population',
+ description: 'Calculates variance based on the entire population (ignores logical values and text in the population).',
abstract: 'Calculates variance based on the entire population',
links: [
{
@@ -1526,12 +1526,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a population.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 254 corresponding to a population.' },
},
},
VAR_S: {
- description: 'Estimates variance based on a sample',
+ description: 'Estimates variance based on a sample (ignores logical values and text in the sample).',
abstract: 'Estimates variance based on a sample',
links: [
{
@@ -1540,8 +1540,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: 'number1', detail: 'The first number argument corresponding to a sample of a population.' },
+ number2: { name: 'number2', detail: 'Number arguments 2 to 254 corresponding to a sample of a population.' },
},
},
VARA: {
@@ -1554,8 +1554,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: 'value1', detail: 'The value number argument corresponding to a sample of a population.' },
+ value2: { name: 'value2', detail: 'Value arguments 2 to 254 corresponding to a sample of a population.' },
},
},
VARPA: {
@@ -1568,8 +1568,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: 'value1', detail: 'The first value argument corresponding to a population.' },
+ value2: { name: 'value2', detail: 'Value arguments 2 to 254 corresponding to a population.' },
},
},
WEIBULL_DIST: {
diff --git a/packages/sheets-formula/src/locale/function-list/statistical/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/statistical/ja-JP.ts
index 69d17b3362..69b03f7bb0 100644
--- a/packages/sheets-formula/src/locale/function-list/statistical/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/statistical/ja-JP.ts
@@ -1304,7 +1304,7 @@ export default {
},
},
STDEV_P: {
- description: '引数を母集団全体と見なし、母集団の標準偏差を返します。',
+ description: '引数を母集団全体であると見なして、母集団の標準偏差を返します (論理値と文字列は除く)。',
abstract: '引数を母集団全体と見なし、母集団の標準偏差を返します。',
links: [
{
@@ -1313,12 +1313,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: '母集団に対応する最初の数値引数を指定します。' },
+ number2: { name: '数値 2', detail: '母集団に対応する引数 2 から 254 までの数値。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
},
},
STDEV_S: {
- description: '引数を正規母集団の標本と見なし、標本に基づいて母集団の標準偏差の推定値を返します。',
+ description: '引数を標本と見なし、標本に基づいて母集団の標準偏差の推定値を返します (標本の論理値と文字列は無視)。',
abstract: '引数を正規母集団の標本と見なし、標本に基づいて母集団の標準偏差の推定値を返します。',
links: [
{
@@ -1327,8 +1327,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: '母集団の標本に対応する最初の数値引数を指定します。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
+ number2: { name: '数値 2', detail: '母集団のサンプルに対応する引数 2 ~ 254 を数値化します。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
},
},
STDEVA: {
@@ -1341,12 +1341,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '値 1', detail: '母集団の標本に対応する最初の値引数を指定します。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
+ value2: { name: '値 2', detail: '母集団のサンプルに対応する引数 2 ~ 254 を値化します。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
},
},
STDEVPA: {
- description: '数値、文字列、および論理値を含む引数を母集団全体と見なし、母集団の標準偏差を返します。',
+ description: '文字列や論理値を含む引数を母集団全体と見なして、母集団の標準偏差を計算します。',
abstract: '数値、文字列、および論理値を含む引数を母集団全体と見なし、母集団の標準偏差を返します。',
links: [
{
@@ -1355,8 +1355,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '値 1', detail: '母集団に対応する最初の値引数を指定します。' },
+ value2: { name: '値 2', detail: '母集団に対応する引数 2 から 254 までの値。 また、半角のカンマ (,) で区切られた引数の代わりに、単一配列や、配列への参照を指定することもできます。' },
},
},
STEYX: {
@@ -1486,7 +1486,7 @@ export default {
},
},
VAR_P: {
- description: '引数を母集団全体と見なし、母集団の分散 (標本分散) を返します。',
+ description: '引数を母集団全体と見なし、母集団の分散 (標本分散) を返します (母集団内の論理値と文字列は無視します)。',
abstract: '引数を母集団全体と見なし、母集団の分散 (標本分散) を返します。',
links: [
{
@@ -1495,12 +1495,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: '母集団に対応する最初の数値引数を指定します。' },
+ number2: { name: '数値 2', detail: '母集団に対応する数値引数 2 ~ 254。' },
},
},
VAR_S: {
- description: '標本に基づいて母集団の分散の推定値 (不偏分散) を返します。',
+ description: '引数を正規母集団の標本と見なし、標本に基づいて母集団の分散の推定値 (不偏分散) を返します (標本内の論理値と文字列は無視します)。',
abstract: '標本に基づいて母集団の分散の推定値 (不偏分散) を返します。',
links: [
{
@@ -1509,8 +1509,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数値 1', detail: '母集団の標本に対応する最初の数値引数を指定します。' },
+ number2: { name: '数値 2', detail: '母集団のサンプルに対応する引数 2 ~ 254 を数値化します。' },
},
},
VARA: {
@@ -1523,8 +1523,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '値 1', detail: '母集団の標本に対応する最初の値引数を指定します。' },
+ value2: { name: '値 2', detail: '母集団のサンプルに対応する引数 2 ~ 254 を値化します。' },
},
},
VARPA: {
@@ -1537,8 +1537,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '値 1', detail: '母集団に対応する最初の値引数を指定します。' },
+ value2: { name: '値 2', detail: '母集団に対応する値引数 2 ~ 254。' },
},
},
WEIBULL_DIST: {
diff --git a/packages/sheets-formula/src/locale/function-list/statistical/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/statistical/zh-CN.ts
index c5c6c6fb99..5e01988529 100644
--- a/packages/sheets-formula/src/locale/function-list/statistical/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/statistical/zh-CN.ts
@@ -1335,7 +1335,7 @@ export default {
},
},
STDEV_P: {
- description: '基于整个样本总体计算标准偏差',
+ description: '计算基于以参数形式给出的整个样本总体的标准偏差(忽略逻辑值和文本)。',
abstract: '基于整个样本总体计算标准偏差',
links: [
{
@@ -1344,12 +1344,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体的第一个数值参数。' },
+ number2: { name: '数值 2', detail: '对应于总体的 2 到 254 个数值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
},
},
STDEV_S: {
- description: '基于样本估算标准偏差',
+ description: '基于样本估算标准偏差(忽略样本中的逻辑值和文本)。',
abstract: '基于样本估算标准偏差',
links: [
{
@@ -1358,12 +1358,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体样本的第一个数值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
+ number2: { name: '数值 2', detail: '对应于总体样本的 2 到 254 个数值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
},
},
STDEVA: {
- description: '基于样本(包括数字、文本和逻辑值)估算标准偏差',
+ description: '基于样本(包括数字、文本和逻辑值)估算标准偏差。',
abstract: '基于样本(包括数字、文本和逻辑值)估算标准偏差',
links: [
{
@@ -1372,12 +1372,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '值 1', detail: '对应于总体样本的第一个值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
+ value2: { name: '值 2', detail: '对应于总体样本的 2 到 254 个值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
},
},
STDEVPA: {
- description: '基于样本总体(包括数字、文本和逻辑值)计算标准偏差',
+ description: '根据作为参数(包括文字和逻辑值)给定的整个总体计算标准偏差。',
abstract: '基于样本总体(包括数字、文本和逻辑值)计算标准偏差',
links: [
{
@@ -1386,8 +1386,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '值 1', detail: '对应于总体的第一个值参数。' },
+ value2: { name: '值 2', detail: '对应于总体的 2 到 254 个值参数。 也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },
},
},
STEYX: {
@@ -1517,7 +1517,7 @@ export default {
},
},
VAR_P: {
- description: '计算基于样本总体的方差',
+ description: '计算基于整个样本总体的方差(忽略样本总体中的逻辑值和文本)。',
abstract: '计算基于样本总体的方差',
links: [
{
@@ -1526,12 +1526,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体的第一个数值参数。' },
+ number2: { name: '数值 2', detail: '对应于总体的 2 到 254 个数值参数。' },
},
},
VAR_S: {
- description: '基于样本估算方差',
+ description: '估算基于样本的方差(忽略样本中的逻辑值和文本)。',
abstract: '基于样本估算方差',
links: [
{
@@ -1540,8 +1540,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number1: { name: '数值 1', detail: '对应于总体样本的第一个数值参数。' },
+ number2: { name: '数值 2', detail: '对应于总体样本的 2 到 254 个数值参数。' },
},
},
VARA: {
@@ -1554,8 +1554,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '值 1', detail: '对应于总体样本的第一个值参数。' },
+ value2: { name: '值 2', detail: '对应于总体样本的 2 到 254 个值参数' },
},
},
VARPA: {
@@ -1568,8 +1568,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value1: { name: '值 1', detail: '对应于总体的第一个值参数。' },
+ value2: { name: '值 2', detail: '对应于总体的 2 到 254 个值参数' },
},
},
WEIBULL_DIST: {
diff --git a/packages/sheets-formula/src/services/function-list/compatibility.ts b/packages/sheets-formula/src/services/function-list/compatibility.ts
index 6ac87df179..4bd824f80e 100644
--- a/packages/sheets-formula/src/services/function-list/compatibility.ts
+++ b/packages/sheets-formula/src/services/function-list/compatibility.ts
@@ -664,16 +664,16 @@ export const FUNCTION_LIST_COMPATIBILITY: IFunctionInfo[] = [
{
name: 'formula.functionList.STDEV.functionParameter.number1.name',
detail: 'formula.functionList.STDEV.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.STDEV.functionParameter.number2.name',
detail: 'formula.functionList.STDEV.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -686,16 +686,16 @@ export const FUNCTION_LIST_COMPATIBILITY: IFunctionInfo[] = [
{
name: 'formula.functionList.STDEVP.functionParameter.number1.name',
detail: 'formula.functionList.STDEVP.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.STDEVP.functionParameter.number2.name',
detail: 'formula.functionList.STDEVP.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -774,16 +774,16 @@ export const FUNCTION_LIST_COMPATIBILITY: IFunctionInfo[] = [
{
name: 'formula.functionList.VAR.functionParameter.number1.name',
detail: 'formula.functionList.VAR.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.VAR.functionParameter.number2.name',
detail: 'formula.functionList.VAR.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -796,16 +796,16 @@ export const FUNCTION_LIST_COMPATIBILITY: IFunctionInfo[] = [
{
name: 'formula.functionList.VARP.functionParameter.number1.name',
detail: 'formula.functionList.VARP.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.VARP.functionParameter.number2.name',
detail: 'formula.functionList.VARP.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
diff --git a/packages/sheets-formula/src/services/function-list/date.ts b/packages/sheets-formula/src/services/function-list/date.ts
index 879df0befa..7b23457a62 100644
--- a/packages/sheets-formula/src/services/function-list/date.ts
+++ b/packages/sheets-formula/src/services/function-list/date.ts
@@ -99,7 +99,7 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [
{
name: 'formula.functionList.DAY.functionParameter.serialNumber.name',
detail: 'formula.functionList.DAY.functionParameter.serialNumber.detail',
- example: 'A1:A20',
+ example: '"1969-7-20"',
require: 1,
repeat: 0,
},
@@ -268,7 +268,7 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [
{
name: 'formula.functionList.MONTH.functionParameter.serialNumber.name',
detail: 'formula.functionList.MONTH.functionParameter.serialNumber.detail',
- example: 'A1:A20',
+ example: '"1969-7-20"',
require: 1,
repeat: 0,
},
@@ -511,7 +511,7 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [
{
name: 'formula.functionList.YEAR.functionParameter.serialNumber.name',
detail: 'formula.functionList.YEAR.functionParameter.serialNumber.detail',
- example: 'A1:A20',
+ example: '"1969-7-20"',
require: 1,
repeat: 0,
},
diff --git a/packages/sheets-formula/src/services/function-list/information.ts b/packages/sheets-formula/src/services/function-list/information.ts
index bf66bca836..5de18eb0ea 100644
--- a/packages/sheets-formula/src/services/function-list/information.ts
+++ b/packages/sheets-formula/src/services/function-list/information.ts
@@ -92,7 +92,7 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
{
name: 'formula.functionList.ISBLANK.functionParameter.value.name',
detail: 'formula.functionList.ISBLANK.functionParameter.value.detail',
- example: 'A1:A20',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -105,16 +105,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISERR.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISERR.functionParameter.number1.name',
- detail: 'formula.functionList.ISERR.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISERR.functionParameter.number2.name',
- detail: 'formula.functionList.ISERR.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISERR.functionParameter.value.name',
+ detail: 'formula.functionList.ISERR.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -127,16 +120,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISERROR.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISERROR.functionParameter.number1.name',
- detail: 'formula.functionList.ISERROR.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISERROR.functionParameter.number2.name',
- detail: 'formula.functionList.ISERROR.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISERROR.functionParameter.value.name',
+ detail: 'formula.functionList.ISERROR.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -193,16 +179,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISLOGICAL.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISLOGICAL.functionParameter.number1.name',
- detail: 'formula.functionList.ISLOGICAL.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISLOGICAL.functionParameter.number2.name',
- detail: 'formula.functionList.ISLOGICAL.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISLOGICAL.functionParameter.value.name',
+ detail: 'formula.functionList.ISLOGICAL.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -215,16 +194,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISNA.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISNA.functionParameter.number1.name',
- detail: 'formula.functionList.ISNA.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISNA.functionParameter.number2.name',
- detail: 'formula.functionList.ISNA.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISNA.functionParameter.value.name',
+ detail: 'formula.functionList.ISNA.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -237,16 +209,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISNONTEXT.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISNONTEXT.functionParameter.number1.name',
- detail: 'formula.functionList.ISNONTEXT.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISNONTEXT.functionParameter.number2.name',
- detail: 'formula.functionList.ISNONTEXT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISNONTEXT.functionParameter.value.name',
+ detail: 'formula.functionList.ISNONTEXT.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -259,16 +224,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISNUMBER.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISNUMBER.functionParameter.number1.name',
- detail: 'formula.functionList.ISNUMBER.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISNUMBER.functionParameter.number2.name',
- detail: 'formula.functionList.ISNUMBER.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISNUMBER.functionParameter.value.name',
+ detail: 'formula.functionList.ISNUMBER.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -325,16 +283,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISREF.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISREF.functionParameter.number1.name',
- detail: 'formula.functionList.ISREF.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISREF.functionParameter.number2.name',
- detail: 'formula.functionList.ISREF.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISREF.functionParameter.value.name',
+ detail: 'formula.functionList.ISREF.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
@@ -347,16 +298,9 @@ export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [
abstract: 'formula.functionList.ISTEXT.abstract',
functionParameter: [
{
- name: 'formula.functionList.ISTEXT.functionParameter.number1.name',
- detail: 'formula.functionList.ISTEXT.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ISTEXT.functionParameter.number2.name',
- detail: 'formula.functionList.ISTEXT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.ISTEXT.functionParameter.value.name',
+ detail: 'formula.functionList.ISTEXT.functionParameter.value.detail',
+ example: 'A1',
require: 1,
repeat: 0,
},
diff --git a/packages/sheets-formula/src/services/function-list/logical.ts b/packages/sheets-formula/src/services/function-list/logical.ts
index 0af9f3637c..bd8b741799 100644
--- a/packages/sheets-formula/src/services/function-list/logical.ts
+++ b/packages/sheets-formula/src/services/function-list/logical.ts
@@ -26,14 +26,14 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
{
name: 'formula.functionList.AND.functionParameter.logical1.name',
detail: 'formula.functionList.AND.functionParameter.logical1.detail',
- example: 'A1:A20',
+ example: 'A1=1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.AND.functionParameter.logical2.name',
detail: 'formula.functionList.AND.functionParameter.logical2.detail',
- example: 'A1:A20',
+ example: 'A2=2',
require: 0,
repeat: 1,
},
@@ -114,21 +114,21 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
{
name: 'formula.functionList.IF.functionParameter.logicalTest.name',
detail: 'formula.functionList.IF.functionParameter.logicalTest.detail',
- example: 'A1>B2',
+ example: 'A2 = "foo"',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.IF.functionParameter.valueIfTrue.name',
detail: 'formula.functionList.IF.functionParameter.valueIfTrue.detail',
- example: 'A1:A20',
+ example: '"A2 is foo"',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.IF.functionParameter.valueIfFalse.name',
detail: 'formula.functionList.IF.functionParameter.valueIfFalse.detail',
- example: 'A1:A20',
+ example: '"A2 is not foo"',
require: 0,
repeat: 0,
},
diff --git a/packages/sheets-formula/src/services/function-list/lookup.ts b/packages/sheets-formula/src/services/function-list/lookup.ts
index 889bcce365..69be006d1a 100644
--- a/packages/sheets-formula/src/services/function-list/lookup.ts
+++ b/packages/sheets-formula/src/services/function-list/lookup.ts
@@ -54,7 +54,7 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
{
name: 'formula.functionList.ADDRESS.functionParameter.sheet_text.name',
detail: 'formula.functionList.ADDRESS.functionParameter.sheet_text.detail',
- example: 'Sheet2',
+ example: '"Sheet2"',
require: 0,
repeat: 0,
},
@@ -155,17 +155,10 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.COLUMN.abstract',
functionParameter: [
{
- name: 'formula.functionList.COLUMN.functionParameter.number1.name',
- detail: 'formula.functionList.COLUMN.functionParameter.number1.detail',
+ name: 'formula.functionList.COLUMN.functionParameter.reference.name',
+ detail: 'formula.functionList.COLUMN.functionParameter.reference.detail',
example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.COLUMN.functionParameter.number2.name',
- detail: 'formula.functionList.COLUMN.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
+ require: 0,
repeat: 0,
},
],
@@ -177,15 +170,8 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.COLUMNS.abstract',
functionParameter: [
{
- name: 'formula.functionList.COLUMNS.functionParameter.number1.name',
- detail: 'formula.functionList.COLUMNS.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.COLUMNS.functionParameter.number2.name',
- detail: 'formula.functionList.COLUMNS.functionParameter.number2.detail',
+ name: 'formula.functionList.COLUMNS.functionParameter.array.name',
+ detail: 'formula.functionList.COLUMNS.functionParameter.array.detail',
example: 'A1:A20',
require: 1,
repeat: 0,
@@ -411,19 +397,33 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.INDEX.abstract',
functionParameter: [
{
- name: 'formula.functionList.INDEX.functionParameter.number1.name',
- detail: 'formula.functionList.INDEX.functionParameter.number1.detail',
+ name: 'formula.functionList.INDEX.functionParameter.reference.name',
+ detail: 'formula.functionList.INDEX.functionParameter.reference.detail',
example: 'A1:A20',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.INDEX.functionParameter.number2.name',
- detail: 'formula.functionList.INDEX.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.INDEX.functionParameter.rowNum.name',
+ detail: 'formula.functionList.INDEX.functionParameter.rowNum.detail',
+ example: '1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.INDEX.functionParameter.columnNum.name',
+ detail: 'formula.functionList.INDEX.functionParameter.columnNum.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.INDEX.functionParameter.areaNum.name',
+ detail: 'formula.functionList.INDEX.functionParameter.areaNum.detail',
+ example: '2',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -433,17 +433,17 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.INDIRECT.abstract',
functionParameter: [
{
- name: 'formula.functionList.INDIRECT.functionParameter.number1.name',
- detail: 'formula.functionList.INDIRECT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.INDIRECT.functionParameter.refText.name',
+ detail: 'formula.functionList.INDIRECT.functionParameter.refText.detail',
+ example: '"A1"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.INDIRECT.functionParameter.number2.name',
- detail: 'formula.functionList.INDIRECT.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
+ name: 'formula.functionList.INDIRECT.functionParameter.a1.name',
+ detail: 'formula.functionList.INDIRECT.functionParameter.a1.detail',
+ example: 'TRUE',
+ require: 0,
repeat: 0,
},
],
@@ -556,17 +556,10 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.ROW.abstract',
functionParameter: [
{
- name: 'formula.functionList.ROW.functionParameter.number1.name',
- detail: 'formula.functionList.ROW.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ROW.functionParameter.number2.name',
- detail: 'formula.functionList.ROW.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
+ name: 'formula.functionList.ROW.functionParameter.reference.name',
+ detail: 'formula.functionList.ROW.functionParameter.reference.detail',
+ example: 'A1',
+ require: 0,
repeat: 0,
},
],
@@ -578,15 +571,8 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.ROWS.abstract',
functionParameter: [
{
- name: 'formula.functionList.ROWS.functionParameter.number1.name',
- detail: 'formula.functionList.ROWS.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.ROWS.functionParameter.number2.name',
- detail: 'formula.functionList.ROWS.functionParameter.number2.detail',
+ name: 'formula.functionList.ROWS.functionParameter.array.name',
+ detail: 'formula.functionList.ROWS.functionParameter.array.detail',
example: 'A1:A20',
require: 1,
repeat: 0,
diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.ts
index 34810423cd..9353a2954b 100644
--- a/packages/sheets-formula/src/services/function-list/math.ts
+++ b/packages/sheets-formula/src/services/function-list/math.ts
@@ -27,7 +27,7 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.ABS.functionParameter.number.name',
detail: 'formula.functionList.ABS.functionParameter.number.detail',
- example: 'A1:A20',
+ example: '-2',
require: 1,
repeat: 0,
},
@@ -42,7 +42,7 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.ACOS.functionParameter.number.name',
detail: 'formula.functionList.ACOS.functionParameter.number.detail',
- example: 'A1:A20',
+ example: '0',
require: 1,
repeat: 0,
},
@@ -57,7 +57,7 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.ACOSH.functionParameter.number.name',
detail: 'formula.functionList.ACOSH.functionParameter.number.detail',
- example: 'A1:A20',
+ example: '2',
require: 1,
repeat: 0,
},
@@ -72,7 +72,7 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.ACOT.functionParameter.number.name',
detail: 'formula.functionList.ACOT.functionParameter.number.detail',
- example: 'A1:A20',
+ example: '0',
require: 1,
repeat: 0,
},
@@ -965,16 +965,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
abstract: 'formula.functionList.MOD.abstract',
functionParameter: [
{
- name: 'formula.functionList.MOD.functionParameter.number1.name',
- detail: 'formula.functionList.MOD.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.MOD.functionParameter.number.name',
+ detail: 'formula.functionList.MOD.functionParameter.number.detail',
+ example: '3',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.MOD.functionParameter.number2.name',
- detail: 'formula.functionList.MOD.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.MOD.functionParameter.divisor.name',
+ detail: 'formula.functionList.MOD.functionParameter.divisor.detail',
+ example: '2',
require: 1,
repeat: 0,
},
@@ -1097,16 +1097,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
abstract: 'formula.functionList.POWER.abstract',
functionParameter: [
{
- name: 'formula.functionList.POWER.functionParameter.number1.name',
- detail: 'formula.functionList.POWER.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.POWER.functionParameter.number.name',
+ detail: 'formula.functionList.POWER.functionParameter.number.detail',
+ example: '5',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.POWER.functionParameter.number2.name',
- detail: 'formula.functionList.POWER.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.POWER.functionParameter.power.name',
+ detail: 'formula.functionList.POWER.functionParameter.power.detail',
+ example: '2',
require: 1,
repeat: 0,
},
@@ -1121,16 +1121,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.PRODUCT.functionParameter.number1.name',
detail: 'formula.functionList.PRODUCT.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: 'A1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.PRODUCT.functionParameter.number2.name',
detail: 'formula.functionList.PRODUCT.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: 'A2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -1537,19 +1537,26 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
abstract: 'formula.functionList.SUBTOTAL.abstract',
functionParameter: [
{
- name: 'formula.functionList.SUBTOTAL.functionParameter.number1.name',
- detail: 'formula.functionList.SUBTOTAL.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SUBTOTAL.functionParameter.functionNum.name',
+ detail: 'formula.functionList.SUBTOTAL.functionParameter.functionNum.detail',
+ example: '1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.SUBTOTAL.functionParameter.number2.name',
- detail: 'formula.functionList.SUBTOTAL.functionParameter.number2.detail',
+ name: 'formula.functionList.SUBTOTAL.functionParameter.ref1.name',
+ detail: 'formula.functionList.SUBTOTAL.functionParameter.ref1.detail',
example: 'A1:A20',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.SUBTOTAL.functionParameter.ref2.name',
+ detail: 'formula.functionList.SUBTOTAL.functionParameter.ref2.detail',
+ example: 'B1:B20',
+ require: 0,
+ repeat: 1,
+ },
],
},
{
@@ -1592,7 +1599,7 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.SUMIF.functionParameter.criteria.name',
detail: 'formula.functionList.SUMIF.functionParameter.criteria.detail',
- example: '>5',
+ example: '">5"',
require: 1,
repeat: 0,
},
@@ -1628,7 +1635,7 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.SUMIFS.functionParameter.criteria1.name',
detail: 'formula.functionList.SUMIFS.functionParameter.criteria1.detail',
- example: '>10',
+ example: '">10"',
require: 1,
repeat: 0,
},
@@ -1642,7 +1649,7 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
name: 'formula.functionList.SUMIFS.functionParameter.criteria2.name',
detail: 'formula.functionList.SUMIFS.functionParameter.criteria2.detail',
- example: '<100',
+ example: '"<100"',
require: 0,
repeat: 1,
},
diff --git a/packages/sheets-formula/src/services/function-list/statistical.ts b/packages/sheets-formula/src/services/function-list/statistical.ts
index 7738234928..dffeaa9ee8 100644
--- a/packages/sheets-formula/src/services/function-list/statistical.ts
+++ b/packages/sheets-formula/src/services/function-list/statistical.ts
@@ -2056,16 +2056,16 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
{
name: 'formula.functionList.STDEV_P.functionParameter.number1.name',
detail: 'formula.functionList.STDEV_P.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.STDEV_P.functionParameter.number2.name',
detail: 'formula.functionList.STDEV_P.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -2078,16 +2078,16 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
{
name: 'formula.functionList.STDEV_S.functionParameter.number1.name',
detail: 'formula.functionList.STDEV_S.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.STDEV_S.functionParameter.number2.name',
detail: 'formula.functionList.STDEV_S.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -2098,18 +2098,18 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.STDEVA.abstract',
functionParameter: [
{
- name: 'formula.functionList.STDEVA.functionParameter.number1.name',
- detail: 'formula.functionList.STDEVA.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.STDEVA.functionParameter.value1.name',
+ detail: 'formula.functionList.STDEVA.functionParameter.value1.detail',
+ example: '1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.STDEVA.functionParameter.number2.name',
- detail: 'formula.functionList.STDEVA.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ name: 'formula.functionList.STDEVA.functionParameter.value2.name',
+ detail: 'formula.functionList.STDEVA.functionParameter.value2.detail',
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -2120,18 +2120,18 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.STDEVPA.abstract',
functionParameter: [
{
- name: 'formula.functionList.STDEVPA.functionParameter.number1.name',
- detail: 'formula.functionList.STDEVPA.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.STDEVPA.functionParameter.value1.name',
+ detail: 'formula.functionList.STDEVPA.functionParameter.value1.detail',
+ example: '1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.STDEVPA.functionParameter.number2.name',
- detail: 'formula.functionList.STDEVPA.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ name: 'formula.functionList.STDEVPA.functionParameter.value2.name',
+ detail: 'formula.functionList.STDEVPA.functionParameter.value2.detail',
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -2342,16 +2342,16 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
{
name: 'formula.functionList.VAR_P.functionParameter.number1.name',
detail: 'formula.functionList.VAR_P.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.VAR_P.functionParameter.number2.name',
detail: 'formula.functionList.VAR_P.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -2364,16 +2364,16 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
{
name: 'formula.functionList.VAR_S.functionParameter.number1.name',
detail: 'formula.functionList.VAR_S.functionParameter.number1.detail',
- example: 'A1:A20',
+ example: '1',
require: 1,
repeat: 0,
},
{
name: 'formula.functionList.VAR_S.functionParameter.number2.name',
detail: 'formula.functionList.VAR_S.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -2384,18 +2384,18 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.VARA.abstract',
functionParameter: [
{
- name: 'formula.functionList.VARA.functionParameter.number1.name',
- detail: 'formula.functionList.VARA.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.VARA.functionParameter.value1.name',
+ detail: 'formula.functionList.VARA.functionParameter.value1.detail',
+ example: '1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.VARA.functionParameter.number2.name',
- detail: 'formula.functionList.VARA.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ name: 'formula.functionList.VARA.functionParameter.value2.name',
+ detail: 'formula.functionList.VARA.functionParameter.value2.detail',
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -2406,18 +2406,18 @@ export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.VARPA.abstract',
functionParameter: [
{
- name: 'formula.functionList.VARPA.functionParameter.number1.name',
- detail: 'formula.functionList.VARPA.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.VARPA.functionParameter.value1.name',
+ detail: 'formula.functionList.VARPA.functionParameter.value1.detail',
+ example: '1',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.VARPA.functionParameter.number2.name',
- detail: 'formula.functionList.VARPA.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ name: 'formula.functionList.VARPA.functionParameter.value2.name',
+ detail: 'formula.functionList.VARPA.functionParameter.value2.detail',
+ example: '2',
+ require: 0,
+ repeat: 1,
},
],
},
diff --git a/packages/sheets-ui/src/controllers/editor/editing.controller.ts b/packages/sheets-ui/src/controllers/editor/editing.controller.ts
index d8c2c20398..c5a78e831a 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.controller.ts
@@ -87,6 +87,8 @@ export class EditingController extends RxDisposable {
cellData: new ObjectMatrix(sheetConfig.cellData),
rowCount: sheetConfig.rowCount,
columnCount: sheetConfig.columnCount,
+ rowData: sheetConfig.rowData,
+ columnData: sheetConfig.columnData,
};
});
diff --git a/packages/sheets-ui/src/controllers/status-bar.controller.ts b/packages/sheets-ui/src/controllers/status-bar.controller.ts
index a92e9ee067..545dd46b4e 100644
--- a/packages/sheets-ui/src/controllers/status-bar.controller.ts
+++ b/packages/sheets-ui/src/controllers/status-bar.controller.ts
@@ -132,6 +132,8 @@ export class StatusBarController extends Disposable {
cellData: new ObjectMatrix(sheetConfig.cellData),
rowCount: sheetConfig.rowCount,
columnCount: sheetConfig.columnCount,
+ rowData: sheetConfig.rowData,
+ columnData: sheetConfig.columnData,
};
});
if (selections?.length) {
diff --git a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
index 94415c7772..9490eb85d7 100644
--- a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
@@ -139,6 +139,11 @@ function setNull(value: Nullable<ICellData>) {
return value;
}
+/**
+ * TODO@Dushusir: Excel can display numbers with up to about 15 digits of precision. When the user inputs more than 15 digits, interception is required, but there are unknown performance risks.
+
+ Intercept 15-digit number reference function truncateNumber
+ */
export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, boolean> = {
id: 'sheet.mutation.set-range-values',
type: CommandType.MUTATION,