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 some Text/Math/Lookup formulas (#2842)

wpxp123456778e371c53f4
diff --git a/packages/engine-formula/src/functions/lookup/areas/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/areas/__tests__/index.spec.ts
new file mode 100644
index 0000000000..b6154e1e60
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/areas/__tests__/index.spec.ts
@@ -0,0 +1,41 @@
+/**
+ * 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_LOOKUP } from '../../function-names';
+import { Areas } from '../index';
+import { StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { CellReferenceObject } from '../../../../engine/reference-object/cell-reference-object';
+
+describe('Test areas function', () => {
+ const testFunction = new Areas(FUNCTION_NAMES_LOOKUP.AREAS);
+
+ describe('Areas', () => {
+ it('Value is reference', async () => {
+ const reference = new CellReferenceObject('A1');
+ const result = testFunction.calculate(reference);
+ expect(result.getValue()).toBe(1);
+ });
+
+ it('Value is not reference', async () => {
+ const reference = StringValueObject.create('A1');
+ const result = testFunction.calculate(reference);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/areas/index.ts b/packages/engine-formula/src/functions/lookup/areas/index.ts
new file mode 100644
index 0000000000..34534df1a9
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/areas/index.ts
@@ -0,0 +1,37 @@
+/**
+ * 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 { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Areas extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 1;
+
+ override needsReferenceObject = true;
+
+ override calculate(reference: FunctionVariantType) {
+ if (reference.isReferenceObject()) {
+ return NumberValueObject.create(1);
+ }
+
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/choosecols/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/choosecols/__tests__/index.spec.ts
new file mode 100644
index 0000000000..3a22e2dd06
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/choosecols/__tests__/index.spec.ts
@@ -0,0 +1,90 @@
+/**
+ * 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 { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Choosecols } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test choosecols function', () => {
+ const testFunction = new Choosecols(FUNCTION_NAMES_LOOKUP.CHOOSECOLS);
+
+ describe('Choosecols', () => {
+ it('Value is normal', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const colNum1 = NumberValueObject.create(1);
+ const colNum2 = NumberValueObject.create(2);
+ const resultObject = testFunction.calculate(array, colNum1, colNum2);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2],
+ [2, 3],
+ ]);
+ });
+
+ it('ColNum value is zero or exceeds the number of columns in the array', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const colNum1 = NumberValueObject.create(0);
+ const resultObject = testFunction.calculate(array, colNum1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.VALUE);
+
+ const colNum2 = NumberValueObject.create(4);
+ const resultObject2 = testFunction.calculate(array, colNum2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Array value is error', async () => {
+ const array = ErrorValueObject.create(ErrorType.NAME);
+ const colNum1 = NumberValueObject.create(11);
+ const resultObject = testFunction.calculate(array, colNum1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('ColNum value is error or string or boolean or blank cell or multi-column array', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const colNum1 = ErrorValueObject.create(ErrorType.NAME);
+ const resultObject = testFunction.calculate(array, colNum1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+
+ const colNum2 = StringValueObject.create('test');
+ const resultObject2 = testFunction.calculate(array, colNum2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+
+ const colNum3 = BooleanValueObject.create(true);
+ const resultObject3 = testFunction.calculate(array, colNum3);
+ expect(getObjectValue(resultObject3)).toStrictEqual([
+ [1],
+ [2],
+ ]);
+
+ const colNum4 = BooleanValueObject.create(false);
+ const resultObject4 = testFunction.calculate(array, colNum4);
+ expect(getObjectValue(resultObject4)).toStrictEqual(ErrorType.VALUE);
+
+ const colNum5 = NullValueObject.create();
+ const resultObject5 = testFunction.calculate(array, colNum5);
+ expect(getObjectValue(resultObject5)).toStrictEqual(ErrorType.VALUE);
+
+ const colNum6 = ArrayValueObject.create('{1,2}');
+ const resultObject6 = testFunction.calculate(array, colNum6);
+ expect(getObjectValue(resultObject6)).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/choosecols/index.ts b/packages/engine-formula/src/functions/lookup/choosecols/index.ts
new file mode 100644
index 0000000000..fd18f1154d
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/choosecols/index.ts
@@ -0,0 +1,100 @@
+/**
+ * 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 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 Choosecols extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 255;
+
+ override calculate(array: BaseValueObject, ...variants: BaseValueObject[]) {
+ if (array.isError()) {
+ return array;
+ }
+
+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;
+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;
+
+ const result: BaseValueObject[][] = [];
+
+ for (let i = 0; i < variants.length; i++) {
+ let variantObject = variants[i];
+
+ if (variantObject.isArray()) {
+ const variantRowCount = (variantObject as ArrayValueObject).getRowCount();
+ const variantColumnCount = (variantObject as ArrayValueObject).getColumnCount();
+
+ if (variantRowCount > 1 || variantColumnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ variantObject = (variantObject as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ if (variantObject.isString()) {
+ variantObject = variantObject.convertToNumberObjectValue();
+ }
+
+ if (variantObject.isError()) {
+ return variantObject;
+ }
+
+ const variantValue = Math.trunc(+variantObject.getValue());
+
+ if (variantValue === 0 || Math.abs(variantValue) > arrayColumnCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ let searchColArray = array;
+
+ if (arrayColumnCount > 1) {
+ if (variantValue < 0) {
+ searchColArray = (array as ArrayValueObject).slice(undefined, [variantValue + arrayColumnCount, variantValue + 1 + arrayColumnCount]) as BaseValueObject;
+ } else {
+ searchColArray = (array as ArrayValueObject).slice(undefined, [variantValue - 1, variantValue]) as BaseValueObject;
+ }
+ }
+
+ for (let r = 0; r < arrayRowCount; r++) {
+ if (!result[r]) {
+ result[r] = [];
+ }
+
+ if (array.isArray()) {
+ result[r].push((searchColArray as ArrayValueObject).get(r, 0) as BaseValueObject);
+ } else {
+ result[r].push(array);
+ }
+ }
+ }
+
+ return ArrayValueObject.create({
+ calculateValueList: result,
+ rowCount: result.length,
+ columnCount: result[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/chooserows/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/chooserows/__tests__/index.spec.ts
new file mode 100644
index 0000000000..1a7c9c0b98
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/chooserows/__tests__/index.spec.ts
@@ -0,0 +1,89 @@
+/**
+ * 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 { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Chooserows } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test chooserows function', () => {
+ const testFunction = new Chooserows(FUNCTION_NAMES_LOOKUP.CHOOSEROWS);
+
+ describe('Chooserows', () => {
+ it('Value is normal', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const rowNum1 = NumberValueObject.create(1);
+ const rowNum2 = NumberValueObject.create(2);
+ const resultObject = testFunction.calculate(array, rowNum1, rowNum2);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, 3],
+ [2, 3, 4],
+ ]);
+ });
+
+ it('RowNum value is zero or exceeds the number of rows in the array', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const rowNum1 = NumberValueObject.create(0);
+ const resultObject = testFunction.calculate(array, rowNum1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.VALUE);
+
+ const rowNum2 = NumberValueObject.create(4);
+ const resultObject2 = testFunction.calculate(array, rowNum2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Array value is error', async () => {
+ const array = ErrorValueObject.create(ErrorType.NAME);
+ const rowNum1 = NumberValueObject.create(11);
+ const resultObject = testFunction.calculate(array, rowNum1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('RowNum value is error or string or boolean or blank cell or multi-row array', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const rowNum1 = ErrorValueObject.create(ErrorType.NAME);
+ const resultObject = testFunction.calculate(array, rowNum1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+
+ const rowNum2 = StringValueObject.create('test');
+ const resultObject2 = testFunction.calculate(array, rowNum2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+
+ const rowNum3 = BooleanValueObject.create(true);
+ const resultObject3 = testFunction.calculate(array, rowNum3);
+ expect(getObjectValue(resultObject3)).toStrictEqual([
+ [1, 2, 3],
+ ]);
+
+ const rowNum4 = BooleanValueObject.create(false);
+ const resultObject4 = testFunction.calculate(array, rowNum4);
+ expect(getObjectValue(resultObject4)).toStrictEqual(ErrorType.VALUE);
+
+ const rowNum5 = NullValueObject.create();
+ const resultObject5 = testFunction.calculate(array, rowNum5);
+ expect(getObjectValue(resultObject5)).toStrictEqual(ErrorType.VALUE);
+
+ const rowNum6 = ArrayValueObject.create('{1;2}');
+ const resultObject6 = testFunction.calculate(array, rowNum6);
+ expect(getObjectValue(resultObject6)).toStrictEqual(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/chooserows/index.ts b/packages/engine-formula/src/functions/lookup/chooserows/index.ts
new file mode 100644
index 0000000000..c2ed79eee7
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/chooserows/index.ts
@@ -0,0 +1,93 @@
+/**
+ * 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 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 Chooserows extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 255;
+
+ override calculate(array: BaseValueObject, ...variants: BaseValueObject[]) {
+ if (array.isError()) {
+ return array;
+ }
+
+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;
+
+ const result: BaseValueObject[][] = [];
+
+ for (let i = 0; i < variants.length; i++) {
+ let variantObject = variants[i];
+
+ if (variantObject.isArray()) {
+ const variantRowCount = (variantObject as ArrayValueObject).getRowCount();
+ const variantColumnCount = (variantObject as ArrayValueObject).getColumnCount();
+
+ if (variantRowCount > 1 || variantColumnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ variantObject = (variantObject as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ if (variantObject.isString()) {
+ variantObject = variantObject.convertToNumberObjectValue();
+ }
+
+ if (variantObject.isError()) {
+ return variantObject;
+ }
+
+ const variantValue = Math.trunc(+variantObject.getValue());
+
+ if (variantValue === 0 || Math.abs(variantValue) > arrayRowCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ let searchRowArray = array;
+
+ if (arrayRowCount > 1) {
+ if (variantValue < 0) {
+ searchRowArray = (array as ArrayValueObject).slice([variantValue + arrayRowCount, variantValue + 1 + arrayRowCount]) as BaseValueObject;
+ } else {
+ searchRowArray = (array as ArrayValueObject).slice([variantValue - 1, variantValue]) as BaseValueObject;
+ }
+ }
+
+ if (array.isArray()) {
+ result.push(searchRowArray.getArrayValue()[0] as BaseValueObject[]);
+ } else {
+ result.push([array]);
+ }
+ }
+
+ return ArrayValueObject.create({
+ calculateValueList: result,
+ rowCount: result.length,
+ columnCount: result[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/filter/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/filter/__tests__/index.spec.ts
new file mode 100644
index 0000000000..93c3c40451
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/filter/__tests__/index.spec.ts
@@ -0,0 +1,82 @@
+/**
+ * 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 { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Filter } from '../index';
+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test filter function', () => {
+ const testFunction = new Filter(FUNCTION_NAMES_LOOKUP.FILTER);
+
+ describe('Filter', () => {
+ it('Value is normal', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const include = ArrayValueObject.create('{true;false}');
+ const resultObject = testFunction.calculate(array, include);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, 3],
+ ]);
+ });
+
+ it('Include value is not normal', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const include = ArrayValueObject.create('{1,2;2,3}');
+ const resultObject = testFunction.calculate(array, include);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.VALUE);
+
+ const include2 = ArrayValueObject.create('{true;"test"}');
+ const resultObject2 = testFunction.calculate(array, include2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+
+ const include3 = ArrayValueObject.create('{true;true;true}');
+ const resultObject3 = testFunction.calculate(array, include3);
+ expect(getObjectValue(resultObject3)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('Value is error', async () => {
+ const array = ErrorValueObject.create(ErrorType.NAME);
+ const include = NumberValueObject.create(11);
+ const resultObject = testFunction.calculate(array, include);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+
+ const array2 = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const include2 = ErrorValueObject.create(ErrorType.NULL);
+ const resultObject2 = testFunction.calculate(array2, include2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.NULL);
+ });
+
+ it('IfEmpty value test', async () => {
+ const array = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const include = ArrayValueObject.create('{false;false}');
+ const resultObject = testFunction.calculate(array, include);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.CALC);
+
+ const ifEmpty2 = ArrayValueObject.create('{"empty1";"empty2";"empty3"}');
+ const resultObject2 = testFunction.calculate(array, include, ifEmpty2);
+ expect(getObjectValue(resultObject2)).toStrictEqual([
+ ['empty1'],
+ ['empty2'],
+ ['empty3'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/filter/index.ts b/packages/engine-formula/src/functions/lookup/filter/index.ts
new file mode 100644
index 0000000000..30c793632a
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/filter/index.ts
@@ -0,0 +1,160 @@
+/**
+ * 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 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 Filter extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 3;
+
+ override calculate(array: BaseValueObject, include: BaseValueObject, ifEmpty?: BaseValueObject) {
+ ifEmpty = ifEmpty ?? ErrorValueObject.create(ErrorType.CALC);
+
+ if (array.isError()) {
+ return array;
+ }
+
+ if (include.isError()) {
+ return include;
+ }
+
+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;
+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;
+
+ const includeRowCount = include.isArray() ? (include as ArrayValueObject).getRowCount() : 1;
+ const includeColumnCount = include.isArray() ? (include as ArrayValueObject).getColumnCount() : 1;
+
+ if (includeRowCount > 1 && includeColumnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if ((includeRowCount === 1 && includeColumnCount !== arrayColumnCount) || (includeColumnCount === 1 && includeRowCount !== arrayRowCount)) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const resultArray: BaseValueObject[][] = [];
+
+ if (arrayRowCount === 1 && arrayColumnCount === 1) {
+ if (array.isArray()) {
+ array = (array as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ if (include.isArray()) {
+ include = (include as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ if (include.isString()) {
+ include = include.convertToNumberObjectValue();
+ }
+
+ if (include.isError()) {
+ return include;
+ }
+
+ const includeValue = +include.getValue();
+
+ if (includeValue) {
+ return array;
+ }
+
+ return ifEmpty;
+ } else if (includeRowCount === 1) {
+ if (includeColumnCount !== arrayColumnCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ for (let c = 0; c < arrayColumnCount; c++) {
+ let includeObject = (include as ArrayValueObject).get(0, c) as BaseValueObject;
+
+ if (includeObject.isString()) {
+ includeObject = includeObject.convertToNumberObjectValue();
+ }
+
+ if (includeObject.isError()) {
+ return includeObject;
+ }
+
+ const includeValue = +includeObject.getValue();
+
+ if (!includeValue) {
+ continue;
+ }
+
+ for (let r = 0; r < arrayRowCount; r++) {
+ if (!resultArray[r]) {
+ resultArray[r] = [];
+ }
+
+ const arrayObject = (array as ArrayValueObject).get(r, c) as BaseValueObject;
+
+ resultArray[r].push(arrayObject);
+ }
+ }
+ } else if (includeColumnCount === 1) {
+ if (includeRowCount !== arrayRowCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ for (let r = 0; r < arrayRowCount; r++) {
+ let includeObject = (include as ArrayValueObject).get(r, 0) as BaseValueObject;
+
+ if (includeObject.isString()) {
+ includeObject = includeObject.convertToNumberObjectValue();
+ }
+
+ if (includeObject.isError()) {
+ return includeObject;
+ }
+
+ const includeValue = +includeObject.getValue();
+
+ if (!includeValue) {
+ continue;
+ }
+
+ const row = [];
+
+ for (let c = 0; c < arrayColumnCount; c++) {
+ const arrayObject = (array as ArrayValueObject).get(r, c) as BaseValueObject;
+
+ row.push(arrayObject);
+ }
+
+ resultArray.push(row);
+ }
+ }
+
+ if (resultArray.length === 0) {
+ return ifEmpty;
+ } else {
+ return ArrayValueObject.create({
+ calculateValueList: resultArray,
+ rowCount: resultArray.length,
+ columnCount: resultArray[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/function-map.ts b/packages/engine-formula/src/functions/lookup/function-map.ts
index b5107a36c7..295946f3df 100644
--- a/packages/engine-formula/src/functions/lookup/function-map.ts
+++ b/packages/engine-formula/src/functions/lookup/function-map.ts
@@ -14,37 +14,57 @@
* limitations under the License.
*/
+import { FUNCTION_NAMES_LOOKUP } from './function-names';
import { Address } from './address';
+import { Areas } from './areas';
+import { Choose } from './choose';
+import { Choosecols } from './choosecols';
+import { Chooserows } from './chooserows';
import { Column } from './column';
import { Columns } from './columns';
-import { FUNCTION_NAMES_LOOKUP } from './function-names';
+import { Filter } from './filter';
import { Hlookup } from './hlookup';
+import { Hstack } from './hstack';
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 { Sort } from './sort';
+import { Sortby } from './sortby';
+import { Transpose } from './transpose';
+import { Unique } from './unique';
import { Vlookup } from './vlookup';
+import { Vstack } from './vstack';
import { Xlookup } from './xlookup';
import { Xmatch } from './xmatch';
-import { Choose } from './choose';
import { Index } from './index';
export const functionLookup = [
[Address, FUNCTION_NAMES_LOOKUP.ADDRESS],
+ [Areas, FUNCTION_NAMES_LOOKUP.AREAS],
[Choose, FUNCTION_NAMES_LOOKUP.CHOOSE],
+ [Choosecols, FUNCTION_NAMES_LOOKUP.CHOOSECOLS],
+ [Chooserows, FUNCTION_NAMES_LOOKUP.CHOOSEROWS],
[Column, FUNCTION_NAMES_LOOKUP.COLUMN],
[Columns, FUNCTION_NAMES_LOOKUP.COLUMNS],
+ [Filter, FUNCTION_NAMES_LOOKUP.FILTER],
+ [Hlookup, FUNCTION_NAMES_LOOKUP.HLOOKUP],
+ [Hstack, FUNCTION_NAMES_LOOKUP.HSTACK],
[Index, FUNCTION_NAMES_LOOKUP.INDEX],
[Indirect, FUNCTION_NAMES_LOOKUP.INDIRECT],
+ [Lookup, FUNCTION_NAMES_LOOKUP.LOOKUP],
+ [Match, FUNCTION_NAMES_LOOKUP.MATCH],
[Offset, FUNCTION_NAMES_LOOKUP.OFFSET],
[Row, FUNCTION_NAMES_LOOKUP.ROW],
[Rows, FUNCTION_NAMES_LOOKUP.ROWS],
+ [Sort, FUNCTION_NAMES_LOOKUP.SORT],
+ [Sortby, FUNCTION_NAMES_LOOKUP.SORTBY],
+ [Transpose, FUNCTION_NAMES_LOOKUP.TRANSPOSE],
+ [Unique, FUNCTION_NAMES_LOOKUP.UNIQUE],
[Vlookup, FUNCTION_NAMES_LOOKUP.VLOOKUP],
- [Lookup, FUNCTION_NAMES_LOOKUP.LOOKUP],
- [Match, FUNCTION_NAMES_LOOKUP.MATCH],
- [Hlookup, FUNCTION_NAMES_LOOKUP.HLOOKUP],
+ [Vstack, FUNCTION_NAMES_LOOKUP.VSTACK],
[Xlookup, FUNCTION_NAMES_LOOKUP.XLOOKUP],
[Xmatch, FUNCTION_NAMES_LOOKUP.XMATCH],
];
diff --git a/packages/engine-formula/src/functions/lookup/hstack/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/hstack/__tests__/index.spec.ts
new file mode 100644
index 0000000000..117b2a8b2c
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/hstack/__tests__/index.spec.ts
@@ -0,0 +1,95 @@
+/**
+ * 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 { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Hstack } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test hstack function', () => {
+ const testFunction = new Hstack(FUNCTION_NAMES_LOOKUP.HSTACK);
+
+ describe('Hstack', () => {
+ it('Value is normal', async () => {
+ const array1 = StringValueObject.create('a');
+ const array2 = StringValueObject.create('b');
+ const array3 = StringValueObject.create('c');
+ const array4 = StringValueObject.create('d');
+ const resultObject = testFunction.calculate(array1, array2, array3, array4);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ ['a', 'b', 'c', 'd'],
+ ]);
+ });
+
+ it('Array variant rows less than max rows, fill #N/A', async () => {
+ const array1 = StringValueObject.create('a');
+ const array2 = StringValueObject.create('b');
+ const array3 = StringValueObject.create('c');
+ const array4 = StringValueObject.create('d');
+ const array5 = ArrayValueObject.create('{e;f}');
+ const resultObject = testFunction.calculate(array1, array2, array3, array4, array5);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ ['a', 'b', 'c', 'd', 'e'],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA, ErrorType.NA, 'f'],
+ ]);
+ });
+
+ it('Array value is error', async () => {
+ const array1 = ErrorValueObject.create(ErrorType.NAME);
+ const array2 = NumberValueObject.create(1);
+ const resultObject = testFunction.calculate(array1, array2);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Array value is blank cell', async () => {
+ const array1 = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const array2 = NullValueObject.create();
+ const resultObject = testFunction.calculate(array1, array2);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, 3, 0],
+ [2, 3, 4, ErrorType.NA],
+ ]);
+ });
+
+ it('Array value is boolean', async () => {
+ const array1 = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const array2 = BooleanValueObject.create(true);
+ const array3 = BooleanValueObject.create(false);
+ const resultObject = testFunction.calculate(array1, array2, array3);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, 3, true, false],
+ [2, 3, 4, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+
+ it('Array value is different number of rows', async () => {
+ const array1 = ArrayValueObject.create('{1,2}');
+ const array2 = ArrayValueObject.create('{"test";"a";"b"}');
+ const array3 = ArrayValueObject.create('{4,5;5,6}');
+ const resultObject = testFunction.calculate(array1, array2, array3);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, 'test', 4, 5],
+ [ErrorType.NA, ErrorType.NA, 'a', 5, 6],
+ [ErrorType.NA, ErrorType.NA, 'b', ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/hstack/index.ts b/packages/engine-formula/src/functions/lookup/hstack/index.ts
new file mode 100644
index 0000000000..123d7ce5c1
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/hstack/index.ts
@@ -0,0 +1,78 @@
+/**
+ * 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 { Nullable } from '@univerjs/core';
+import { ErrorType } from '../../../basics/error-type';
+import { ArrayValueObject } from '../../../engine/value-object/array-value-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 Hstack extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 255;
+
+ override calculate(...variants: BaseValueObject[]) {
+ const maxRowLength = Math.max(
+ ...variants.map((variantObject) => variantObject.isArray() ? (variantObject as ArrayValueObject).getRowCount() : 1)
+ );
+
+ const result: BaseValueObject[][] = [];
+
+ for (let i = 0; i < variants.length; i++) {
+ const variantObject = variants[i];
+
+ if (variantObject.isError()) {
+ return variantObject;
+ }
+
+ const rowCount = variantObject.isArray() ? (variantObject as ArrayValueObject).getRowCount() : 1;
+ const columnCount = variantObject.isArray() ? (variantObject as ArrayValueObject).getColumnCount() : 1;
+
+ for (let r = 0; r < maxRowLength; r++) {
+ if (!result[r]) {
+ result[r] = [];
+ }
+
+ for (let c = 0; c < columnCount; c++) {
+ let singleObject: Nullable<BaseValueObject> = variantObject;
+
+ if (variantObject.isArray()) {
+ singleObject = (variantObject as ArrayValueObject).get(r, c);
+ }
+
+ if (r > rowCount - 1 || !singleObject) {
+ result[r].push(ErrorValueObject.create(ErrorType.NA));
+ } else {
+ result[r].push(singleObject);
+ }
+ }
+ }
+ }
+
+ return ArrayValueObject.create({
+ calculateValueList: result,
+ rowCount: result.length,
+ columnCount: result[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/sort/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/sort/__tests__/index.spec.ts
new file mode 100644
index 0000000000..ff79fd48ac
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/sort/__tests__/index.spec.ts
@@ -0,0 +1,202 @@
+/**
+ * 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 { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Sort } from '../index';
+import { BooleanValueObject, NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+
+describe('Test sort function', () => {
+ const testFunction = new Sort(FUNCTION_NAMES_LOOKUP.SORT);
+
+ describe('Sort', () => {
+ it('Value is normal', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['Year', null],
+ [2, 1],
+ [null, 3],
+ [11, 4],
+ [true, 5],
+ ['abc', 67],
+ ['test', 8],
+ [ErrorType.NAME, 11],
+ [false, 2],
+ [2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortIndex = NumberValueObject.create(1);
+ const sortOrder = NumberValueObject.create(1);
+ const byCol = BooleanValueObject.create(false);
+ const resultObject = testFunction.calculate(array, sortIndex, sortOrder, byCol);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [2, 1],
+ [2, 222],
+ [11, 4],
+ ['abc', 67],
+ ['test', 8],
+ ['Year', 0],
+ [false, 2],
+ [true, 5],
+ [ErrorType.NAME, 11],
+ [0, 3],
+ ]);
+ });
+
+ it('SortIndex value test', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['Year', null],
+ [2, 1],
+ [null, 3],
+ [11, 4],
+ [true, 5],
+ ['abc', 67],
+ ['test', 8],
+ [ErrorType.NAME, 11],
+ [false, 2],
+ [2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortIndex = NumberValueObject.create(2);
+ const resultObject = testFunction.calculate(array, sortIndex);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [2, 1],
+ [false, 2],
+ [0, 3],
+ [11, 4],
+ [true, 5],
+ ['test', 8],
+ [ErrorType.NAME, 11],
+ ['abc', 67],
+ [2, 222],
+ ['Year', 0],
+ ]);
+
+ const sortIndex2 = NumberValueObject.create(0);
+ const resultObject2 = testFunction.calculate(array, sortIndex2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+
+ const sortIndex3 = NumberValueObject.create(3);
+ const resultObject3 = testFunction.calculate(array, sortIndex3);
+ expect(getObjectValue(resultObject3)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('SortOrder value test', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['Year', null],
+ [2, 1],
+ [null, 3],
+ [11, 4],
+ [true, 5],
+ ['abc', 67],
+ ['test', 8],
+ [ErrorType.NAME, 11],
+ [false, 2],
+ [2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortIndex = NumberValueObject.create(1);
+ const sortOrder = NumberValueObject.create(-1);
+ const resultObject = testFunction.calculate(array, sortIndex, sortOrder);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [ErrorType.NAME, 11],
+ [true, 5],
+ [false, 2],
+ ['Year', 0],
+ ['test', 8],
+ ['abc', 67],
+ [11, 4],
+ [2, 1],
+ [2, 222],
+ [0, 3],
+ ]);
+
+ const sortOrder2 = NumberValueObject.create(0);
+ const resultObject2 = testFunction.calculate(array, sortIndex, sortOrder2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('ByCol value test', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['Year', null],
+ [2, 1],
+ [null, 3],
+ [11, 4],
+ [true, 5],
+ ['abc', 67],
+ ['test', 8],
+ [ErrorType.NAME, 11],
+ [false, 2],
+ [2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortIndex = NumberValueObject.create(2);
+ const sortOrder = NumberValueObject.create(1);
+ const byCol = BooleanValueObject.create(true);
+ const resultObject = testFunction.calculate(array, sortIndex, sortOrder, byCol);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [0, 'Year'],
+ [1, 2],
+ [3, 0],
+ [4, 11],
+ [5, true],
+ [67, 'abc'],
+ [8, 'test'],
+ [11, ErrorType.NAME],
+ [2, false],
+ [222, 2],
+ ]);
+
+ const byCol2 = ArrayValueObject.create('{"test",1;0,#NAME?}');
+ const resultObject2 = testFunction.calculate(array, sortIndex, sortOrder, byCol2);
+ expect(getObjectValue(resultObject2)).toStrictEqual([
+ [ErrorType.VALUE, 0],
+ [2, ErrorType.NAME],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/sort/index.ts b/packages/engine-formula/src/functions/lookup/sort/index.ts
new file mode 100644
index 0000000000..b9a402fda9
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/sort/index.ts
@@ -0,0 +1,279 @@
+/**
+ * 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 { Nullable } from '@univerjs/core';
+import { ErrorType } from '../../../basics/error-type';
+import { getCompare } from '../../../engine/utils/compare';
+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';
+
+import { BaseFunction } from '../../base-function';
+
+export class Sort extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 4;
+
+ override calculate(array: BaseValueObject, sortIndex?: BaseValueObject, sortOrder?: BaseValueObject, byCol?: BaseValueObject) {
+ sortIndex = sortIndex ?? NumberValueObject.create(1);
+ sortOrder = sortOrder ?? NumberValueObject.create(1);
+ byCol = byCol ?? BooleanValueObject.create(false);
+
+ if (byCol.isArray()) {
+ const byColRowCount = (byCol as ArrayValueObject).getRowCount();
+ const byColColumnCount = (byCol as ArrayValueObject).getColumnCount();
+
+ if (byColRowCount === 1 && byColColumnCount === 1) {
+ const byColObject = (byCol as ArrayValueObject).get(0, 0) as BaseValueObject;
+
+ return this._handleSingleObject(array, sortIndex, sortOrder, byColObject);
+ }
+
+ return byCol.map((byColObject) => {
+ const result = this._handleSingleObject(array, sortIndex, sortOrder, byColObject);
+
+ return result.isArray() ? (result as ArrayValueObject).get(0, 0) as BaseValueObject : result;
+ });
+ }
+
+ return this._handleSingleObject(array, sortIndex, sortOrder, byCol);
+ }
+
+ private _handleSingleObject(array: BaseValueObject, sortIndex: BaseValueObject, sortOrder: BaseValueObject, byCol: BaseValueObject) {
+ if (array.isError()) {
+ return array;
+ }
+
+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;
+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;
+
+ if (sortIndex.isArray()) {
+ const rowCount = (sortIndex as ArrayValueObject).getRowCount();
+ const columnCount = (sortIndex as ArrayValueObject).getColumnCount();
+
+ if (rowCount > 1 || columnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ sortIndex = (sortIndex as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ if (sortIndex.isString()) {
+ sortIndex = sortIndex.convertToNumberObjectValue();
+ }
+
+ if (sortIndex.isError()) {
+ return sortIndex;
+ }
+
+ const sortIndexValue = Math.floor(+sortIndex.getValue());
+
+ if (sortIndexValue < 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (sortOrder.isArray()) {
+ const rowCount = (sortOrder as ArrayValueObject).getRowCount();
+ const columnCount = (sortOrder as ArrayValueObject).getColumnCount();
+
+ if (rowCount > 1 || columnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ sortOrder = (sortOrder as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ if (sortOrder.isString()) {
+ sortOrder = sortOrder.convertToNumberObjectValue();
+ }
+
+ if (sortOrder.isError()) {
+ return sortOrder;
+ }
+
+ const sortOrderValue = Math.floor(+sortOrder.getValue());
+
+ if (sortOrderValue !== -1 && sortOrderValue !== 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (byCol.isString()) {
+ byCol = byCol.convertToNumberObjectValue();
+ }
+
+ if (byCol.isError()) {
+ return byCol;
+ }
+
+ if (!array.isArray() || (arrayRowCount === 1 && arrayColumnCount === 1)) {
+ return array;
+ }
+
+ const byColValue = +byCol.getValue();
+
+ if (!byColValue) {
+ if (sortIndexValue > arrayColumnCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const arrayValue = array.getArrayValue();
+ arrayValue.sort(this._sort(sortIndexValue - 1, sortOrderValue));
+
+ return ArrayValueObject.create({
+ calculateValueList: arrayValue,
+ rowCount: arrayValue.length,
+ columnCount: arrayValue[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ } else {
+ if (sortIndexValue > arrayRowCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const arrayValue = (array as ArrayValueObject).transpose().getArrayValue();
+ arrayValue.sort(this._sort(sortIndexValue - 1, sortOrderValue));
+
+ const newArray = ArrayValueObject.create({
+ calculateValueList: arrayValue,
+ rowCount: arrayValue.length,
+ columnCount: arrayValue[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+
+ return newArray.transpose();
+ }
+ }
+
+ private _sort(sortIndex: number, sortOrder: 1 | -1 = 1) {
+ const compare = getCompare();
+
+ if (sortOrder === 1) {
+ return (a: Nullable<BaseValueObject>[], b: Nullable<BaseValueObject>[]) => {
+ const columnA = a[sortIndex];
+ const columnB = b[sortIndex];
+
+ if (columnA == null || columnA.isNull()) {
+ return 1;
+ }
+
+ if (columnB == null || columnB.isNull()) {
+ return -1;
+ }
+
+ if (columnA.isError() && columnB.isError()) {
+ return 0;
+ }
+
+ if (columnA.isError()) {
+ return 1;
+ }
+
+ if (columnB.isError()) {
+ return -1;
+ }
+
+ const columnAValue = (columnA as BaseValueObject).getValue();
+ const columnBValue = (columnB as BaseValueObject).getValue();
+
+ if (columnA.isBoolean() && columnAValue === true) {
+ return 1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === true) {
+ return -1;
+ }
+
+ if (columnA.isBoolean() && columnAValue === false) {
+ return 1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === false) {
+ return -1;
+ }
+
+ if (columnA.isNumber() && columnB.isNumber()) {
+ return (+columnAValue) - (+columnBValue);
+ }
+
+ return compare(
+ columnAValue as string,
+ columnBValue as string
+ );
+ };
+ } else {
+ return (a: Nullable<BaseValueObject>[], b: Nullable<BaseValueObject>[]) => {
+ const columnA = a[sortIndex];
+ const columnB = b[sortIndex];
+
+ if (columnA == null || columnA.isNull()) {
+ return 1;
+ }
+
+ if (columnB == null || columnB.isNull()) {
+ return -1;
+ }
+
+ if (columnA.isError() && columnB.isError()) {
+ return 0;
+ }
+
+ if (columnA.isError()) {
+ return -1;
+ }
+
+ if (columnB.isError()) {
+ return 1;
+ }
+
+ const columnAValue = (columnA as BaseValueObject).getValue();
+ const columnBValue = (columnB as BaseValueObject).getValue();
+
+ if (columnA.isBoolean() && columnAValue === true) {
+ return -1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === true) {
+ return 1;
+ }
+
+ if (columnA.isBoolean() && columnAValue === false) {
+ return -1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === false) {
+ return 1;
+ }
+
+ if (columnA.isNumber() && columnB.isNumber()) {
+ return (+columnBValue) - (+columnAValue);
+ }
+
+ return compare(
+ columnBValue as string,
+ columnAValue as string
+ );
+ };
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/sortby/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/sortby/__tests__/index.spec.ts
new file mode 100644
index 0000000000..349809cc66
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/sortby/__tests__/index.spec.ts
@@ -0,0 +1,384 @@
+/**
+ * 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 { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Sortby } from '../index';
+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test sortby function', () => {
+ const testFunction = new Sortby(FUNCTION_NAMES_LOOKUP.SORTBY);
+
+ describe('Sortby', () => {
+ it('Value is normal', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11, 'Year', null],
+ [13, 2, 1],
+ [15, null, 3],
+ [17, 11, 4],
+ [19, true, 5],
+ [21, 'abc', 67],
+ [23, 'test', 8],
+ [25, ErrorType.NAME, 11],
+ [27, false, 2],
+ [29, 2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byArray1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11],
+ [2],
+ [3],
+ [4],
+ [7],
+ [4],
+ [7],
+ [4],
+ [9],
+ [10],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder1 = NumberValueObject.create(1);
+ const resultObject = testFunction.calculate(array, byArray1, sortOrder1);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [13, 2, 1],
+ [15, 0, 3],
+ [17, 11, 4],
+ [21, 'abc', 67],
+ [25, ErrorType.NAME, 11],
+ [19, true, 5],
+ [23, 'test', 8],
+ [27, false, 2],
+ [29, 2, 222],
+ [11, 'Year', 0],
+ ]);
+ });
+
+ it('byArray value rows or columns different lengths', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11, 'Year', null],
+ [13, 2, 1],
+ [15, null, 3],
+ [17, 11, 4],
+ [19, true, 5],
+ [21, 'abc', 67],
+ [23, 'test', 8],
+ [25, ErrorType.NAME, 11],
+ [27, false, 2],
+ [29, 2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byArray1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11],
+ [2],
+ [3],
+ [4],
+ [7],
+ [4],
+ [7],
+ [4],
+ [9],
+ [10],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder1 = NumberValueObject.create(1);
+ const byArray2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11],
+ [2],
+ [3],
+ [4],
+ ]),
+ rowCount: 4,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder2 = NumberValueObject.create(1);
+ const resultObject = testFunction.calculate(array, byArray1, sortOrder1, byArray2, sortOrder2);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.VALUE);
+
+ const byArray3 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11, 2, 3],
+ ]),
+ rowCount: 1,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const resultObject2 = testFunction.calculate(array, byArray1, sortOrder1, byArray3, sortOrder2);
+ expect(getObjectValue(resultObject2)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('array is error', async () => {
+ const array = ErrorValueObject.create(ErrorType.NAME);
+ const byArray1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11],
+ [2],
+ [3],
+ [4],
+ [7],
+ [4],
+ [7],
+ [4],
+ [9],
+ [10],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder1 = NumberValueObject.create(1);
+ const resultObject = testFunction.calculate(array, byArray1, sortOrder1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('byArray and sortOrder must be paired', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11, 'Year', null],
+ [13, 2, 1],
+ [15, null, 3],
+ [17, 11, 4],
+ [19, true, 5],
+ [21, 'abc', 67],
+ [23, 'test', 8],
+ [25, ErrorType.NAME, 11],
+ [27, false, 2],
+ [29, 2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byArray1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11],
+ [2],
+ [3],
+ [4],
+ [7],
+ [4],
+ [7],
+ [4],
+ [9],
+ [10],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder1 = NumberValueObject.create(1);
+ const resultObject = testFunction.calculate(array, byArray1, sortOrder1, byArray1);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.VALUE);
+ });
+
+ it('byArray1 value has same value and byArray2 value same location can sort', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11, 'Year', null],
+ [13, 2, 1],
+ [15, null, 3],
+ [17, 11, 4],
+ [19, true, 5],
+ [21, 'abc', 67],
+ [23, 'test', 8],
+ [25, ErrorType.NAME, 11],
+ [27, false, 2],
+ [29, 2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byArray1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11],
+ [2],
+ [3],
+ [4],
+ [7],
+ [4],
+ [7],
+ [4],
+ [9],
+ [10],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder1 = NumberValueObject.create(-1);
+ const byArray2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [2],
+ [1],
+ [1],
+ [1],
+ [2],
+ [111],
+ [3],
+ [2],
+ [1],
+ [4],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder2 = NumberValueObject.create(-1);
+ const resultObject = testFunction.calculate(array, byArray1, sortOrder1, byArray2, sortOrder2);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [11, 'Year', 0],
+ [29, 2, 222],
+ [27, false, 2],
+ [23, 'test', 8],
+ [19, true, 5],
+ [21, 'abc', 67],
+ [25, ErrorType.NAME, 11],
+ [17, 11, 4],
+ [15, 0, 3],
+ [13, 2, 1],
+ ]);
+ });
+
+ it('sortOrder value is array', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11, 'Year', null],
+ [13, 2, 1],
+ [15, null, 3],
+ [17, 11, 4],
+ [19, true, 5],
+ [21, 'abc', 67],
+ [23, 'test', 8],
+ [25, ErrorType.NAME, 11],
+ [27, false, 2],
+ [29, 2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byArray1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [11],
+ [2],
+ [3],
+ [4],
+ [7],
+ [4],
+ [7],
+ [4],
+ [9],
+ [10],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder1 = NumberValueObject.create(-1);
+ const byArray2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [2],
+ [1],
+ [1],
+ [1],
+ [2],
+ [111],
+ [3],
+ [2],
+ [1],
+ [4],
+ ]),
+ rowCount: 10,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const sortOrder2 = ArrayValueObject.create('{0,0,-1;-1,0,0}');
+ const resultObject = testFunction.calculate(array, byArray1, sortOrder1, byArray2, sortOrder2);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [ErrorType.VALUE, ErrorType.VALUE, 11],
+ [11, ErrorType.VALUE, ErrorType.VALUE],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/sortby/index.ts b/packages/engine-formula/src/functions/lookup/sortby/index.ts
new file mode 100644
index 0000000000..e035e2bbc7
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/sortby/index.ts
@@ -0,0 +1,382 @@
+/**
+ * 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 { Nullable } from '@univerjs/core';
+import { ErrorType } from '../../../basics/error-type';
+import { getCompare } from '../../../engine/utils/compare';
+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+
+import { BooleanValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';
+
+import { BaseFunction } from '../../base-function';
+import { calculateMaxDimensions } from '../../../engine/utils/value-object';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+
+export class Sortby extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 255;
+
+ override calculate(array: BaseValueObject, ...variants: BaseValueObject[]) {
+ // if has byArray1 no sortOrder, sortOrder default 1. but has multiple byArray, sortOrder length must be equal to byArray length
+ if (variants.length === 1) {
+ variants.push(NumberValueObject.create(1));
+ }
+
+ const variantsError = this._getVariantsError(array, ...variants);
+
+ const { maxRowLength, maxColumnLength } = calculateMaxDimensions(variants);
+
+ if (variantsError.isError()) {
+ const expandArray = expandArrayValueObject(maxRowLength, maxColumnLength, variantsError);
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (expandArray as ArrayValueObject).get(0, 0) as ErrorValueObject;
+ }
+
+ return expandArray;
+ }
+
+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;
+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;
+
+ const byArray1RowCount = variants[0].isArray() ? (variants[0] as ArrayValueObject).getRowCount() : 1;
+ const byArray1ColumnCount = variants[0].isArray() ? (variants[0] as ArrayValueObject).getColumnCount() : 1;
+
+ variants = variants.map((variant, index) => {
+ if (index % 2 === 0) {
+ return variant;
+ }
+
+ const variantArray = expandArrayValueObject(maxRowLength, maxColumnLength, variant, ErrorValueObject.create(ErrorType.NA));
+
+ return variantArray;
+ });
+
+ const resultArray: BaseValueObject[][] = [];
+
+ for (let r = 0; r < maxRowLength; r++) {
+ resultArray[r] = [] as BaseValueObject[];
+
+ for (let c = 0; c < maxColumnLength; c++) {
+ const byArrays = [];
+ const sortOrders = [];
+
+ let isError: boolean = false;
+
+ for (let i = 0; i < variants.length; i++) {
+ if (i % 2 === 1) {
+ continue;
+ }
+
+ const byArray = variants[i];
+
+ let sortOrder = (variants[i + 1] as ArrayValueObject).get(r, c) as BaseValueObject;
+
+ if (sortOrder.isString()) {
+ sortOrder = sortOrder.convertToNumberObjectValue();
+ }
+
+ if (sortOrder.isError()) {
+ resultArray[r].push(sortOrder);
+ isError = true;
+ break;
+ }
+
+ const sortOrderValue = Math.floor(+sortOrder.getValue());
+
+ if (sortOrderValue !== -1 && sortOrderValue !== 1) {
+ resultArray[r].push(ErrorValueObject.create(ErrorType.VALUE));
+ isError = true;
+ break;
+ }
+
+ sortOrders.push(sortOrderValue);
+
+ if (byArray.isArray()) {
+ let byArrayValue = byArray.getArrayValue();
+
+ if (byArray1ColumnCount === 1) {
+ byArrayValue = this._transposeArray(byArrayValue);
+ }
+
+ byArrays.push(byArrayValue[0]);
+ } else {
+ byArrays.push([byArray]);
+ }
+ }
+
+ if (isError) {
+ continue;
+ }
+
+ if (!array.isArray() || (arrayRowCount === 1 && arrayColumnCount === 1)) {
+ resultArray[r].push(array);
+ continue;
+ }
+
+ let arrayValue = array.getArrayValue();
+
+ if (!(byArray1RowCount === 1 && byArray1ColumnCount === 1)) {
+ if (byArray1RowCount === 1) {
+ arrayValue = arrayValue.concat(byArrays);
+ arrayValue = this._transposeArray(arrayValue);
+ arrayValue.sort(this._sort(arrayRowCount, sortOrders as Array<1 | -1>));
+ arrayValue = this._transposeArray(arrayValue).slice(0, arrayRowCount);
+ } else if (byArray1ColumnCount === 1) {
+ arrayValue = this._transposeArray(arrayValue);
+ arrayValue = arrayValue.concat(byArrays);
+ arrayValue = this._transposeArray(arrayValue);
+ arrayValue.sort(this._sort(arrayColumnCount, sortOrders as Array<1 | -1>));
+ arrayValue = arrayValue.map((row) => row.slice(0, arrayColumnCount));
+ }
+ }
+
+ const result = ArrayValueObject.create({
+ calculateValueList: arrayValue,
+ rowCount: arrayValue.length,
+ columnCount: arrayValue[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+
+ if (maxRowLength > 1 || maxColumnLength > 1) {
+ resultArray[r].push(result.get(0, 0) as BaseValueObject);
+ continue;
+ }
+
+ resultArray[r].push(result);
+ }
+ }
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return resultArray[0][0] as ArrayValueObject;
+ }
+
+ return ArrayValueObject.create({
+ calculateValueList: resultArray,
+ rowCount: resultArray.length,
+ columnCount: resultArray[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ }
+
+ private _getVariantsError(array: BaseValueObject, ...variants: BaseValueObject[]): ErrorValueObject | BooleanValueObject {
+ if (array.isError()) {
+ return array as ErrorValueObject;
+ }
+
+ for (let i = 0; i < variants.length; i++) {
+ const variant = variants[i];
+
+ if (variant.isError()) {
+ return variant as ErrorValueObject;
+ }
+ }
+
+ // byArray and sortOrder must be paired
+ if (variants.length < 2 || variants.length % 2 !== 0) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;
+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;
+
+ const byArray1RowCount = variants[0].isArray() ? (variants[0] as ArrayValueObject).getRowCount() : 1;
+ const byArray1ColumnCount = variants[0].isArray() ? (variants[0] as ArrayValueObject).getColumnCount() : 1;
+
+ if (byArray1RowCount > 1 || byArray1ColumnCount > 1) {
+ if (byArray1RowCount > 1 && byArray1ColumnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (byArray1RowCount === 1 && byArray1ColumnCount !== arrayColumnCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (byArray1ColumnCount === 1 && byArray1RowCount !== arrayRowCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+ }
+
+ for (let i = 2; i < variants.length; i++) {
+ if (i % 2 === 1) {
+ continue;
+ }
+
+ const byArrayRowCount = variants[i].isArray() ? (variants[i] as ArrayValueObject).getRowCount() : 1;
+ const byArrayColumnCount = variants[i].isArray() ? (variants[i] as ArrayValueObject).getColumnCount() : 1;
+
+ if (byArrayRowCount !== byArray1RowCount || byArrayColumnCount !== byArray1ColumnCount) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+ }
+
+ return BooleanValueObject.create(true);
+ }
+
+ private _transposeArray(array: Nullable<BaseValueObject>[][]) {
+ // Create a new 2D array as the transposed matrix
+ const rows = array.length;
+ const cols = array[0].length;
+ const transposedArray: Nullable<BaseValueObject>[][] = [];
+
+ // Traverse the columns of the original two-dimensional array
+ for (let col = 0; col < cols; col++) {
+ // Create new row
+ transposedArray[col] = [] as BaseValueObject[];
+
+ // Traverse the rows of the original two-dimensional array
+ for (let row = 0; row < rows; row++) {
+ // Assign elements to new rows
+ transposedArray[col][row] = array[row][col];
+ }
+ }
+
+ return transposedArray;
+ }
+
+ private _sort(sortIndex: number, sortOrders: Array<1 | -1>) {
+ const compare = getCompare();
+
+ return (a: Nullable<BaseValueObject>[], b: Nullable<BaseValueObject>[]) => {
+ let columnA = a[sortIndex] as BaseValueObject;
+ let columnB = b[sortIndex] as BaseValueObject;
+ let result = this._compare(columnA, columnB, sortOrders[0], compare);
+
+ if (result === 0 && sortOrders.length > 1) {
+ for (let i = 1; i < sortOrders.length; i++) {
+ columnA = a[sortIndex + i] as BaseValueObject;
+ columnB = b[sortIndex + i] as BaseValueObject;
+ result = this._compare(columnA, columnB, sortOrders[i], compare);
+
+ if (result !== 0) {
+ return result;
+ }
+ }
+ }
+
+ return result;
+ };
+ }
+
+ private _compare(columnA: BaseValueObject, columnB: BaseValueObject, sortOrder: 1 | -1, compare: Function) {
+ if (sortOrder === 1) {
+ if (columnA == null || columnA.isNull()) {
+ return 1;
+ }
+
+ if (columnB == null || columnB.isNull()) {
+ return -1;
+ }
+
+ if (columnA.isError() && columnB.isError()) {
+ return 0;
+ }
+
+ if (columnA.isError()) {
+ return 1;
+ }
+
+ if (columnB.isError()) {
+ return -1;
+ }
+
+ const columnAValue = (columnA as BaseValueObject).getValue();
+ const columnBValue = (columnB as BaseValueObject).getValue();
+
+ if (columnA.isBoolean() && columnAValue === true) {
+ return 1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === true) {
+ return -1;
+ }
+
+ if (columnA.isBoolean() && columnAValue === false) {
+ return 1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === false) {
+ return -1;
+ }
+
+ if (columnA.isNumber() && columnB.isNumber()) {
+ return (+columnAValue) - (+columnBValue);
+ }
+
+ return compare(
+ columnAValue as string,
+ columnBValue as string
+ );
+ } else {
+ if (columnA == null || columnA.isNull()) {
+ return 1;
+ }
+
+ if (columnB == null || columnB.isNull()) {
+ return -1;
+ }
+
+ if (columnA.isError() && columnB.isError()) {
+ return 0;
+ }
+
+ if (columnA.isError()) {
+ return -1;
+ }
+
+ if (columnB.isError()) {
+ return 1;
+ }
+
+ const columnAValue = (columnA as BaseValueObject).getValue();
+ const columnBValue = (columnB as BaseValueObject).getValue();
+
+ if (columnA.isBoolean() && columnAValue === true) {
+ return -1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === true) {
+ return 1;
+ }
+
+ if (columnA.isBoolean() && columnAValue === false) {
+ return -1;
+ }
+
+ if (columnB.isBoolean() && columnBValue === false) {
+ return 1;
+ }
+
+ if (columnA.isNumber() && columnB.isNumber()) {
+ return (+columnBValue) - (+columnAValue);
+ }
+
+ return compare(
+ columnBValue as string,
+ columnAValue as string
+ );
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/transpose/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/transpose/__tests__/index.spec.ts
new file mode 100644
index 0000000000..231f4d6eaa
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/transpose/__tests__/index.spec.ts
@@ -0,0 +1,64 @@
+/**
+ * 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 { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Transpose } from '../index';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test transpose function', () => {
+ const testFunction = new Transpose(FUNCTION_NAMES_LOOKUP.TRANSPOSE);
+
+ describe('Transpose', () => {
+ it('Array value is normal', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['Year', null],
+ [2, 1],
+ [null, 3],
+ [11, 4],
+ [true, 5],
+ ['abc', 67],
+ ['test', 8],
+ [ErrorType.NAME, 11],
+ [false, 2],
+ [2, 222],
+ ]),
+ rowCount: 10,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const resultObject = testFunction.calculate(array);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ ['Year', 2, 0, 11, true, 'abc', 'test', ErrorType.NAME, false, 2],
+ [0, 1, 3, 4, 5, 67, 8, 11, 2, 222],
+ ]);
+ });
+
+ it('Array value is error', async () => {
+ const array = ErrorValueObject.create(ErrorType.NAME);
+ const resultObject = testFunction.calculate(array);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/transpose/index.ts b/packages/engine-formula/src/functions/lookup/transpose/index.ts
new file mode 100644
index 0000000000..68f2c82c75
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/transpose/index.ts
@@ -0,0 +1,45 @@
+/**
+ * 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 { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+
+import { BaseFunction } from '../../base-function';
+
+export class Transpose extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 1;
+
+ override calculate(array: BaseValueObject) {
+ if (array.isError()) {
+ return array;
+ }
+
+ if (array.isArray()) {
+ const rowCount = (array as ArrayValueObject).getRowCount();
+ const columnCount = (array as ArrayValueObject).getColumnCount();
+
+ if (rowCount === 1 && columnCount === 1) {
+ return (array as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return (array as ArrayValueObject).transpose();
+ }
+
+ return array;
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/unique/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/unique/__tests__/index.spec.ts
new file mode 100644
index 0000000000..96b853501d
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/unique/__tests__/index.spec.ts
@@ -0,0 +1,164 @@
+/**
+ * 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 { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Unique } from '../index';
+import { BooleanValueObject, NullValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test unique function', () => {
+ const testFunction = new Unique(FUNCTION_NAMES_LOOKUP.UNIQUE);
+
+ describe('Unique', () => {
+ it('Value is normal', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [2, 2],
+ [2, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const resultObject = testFunction.calculate(array);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [2, 2],
+ ]);
+ });
+
+ it('ByCol value test', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [2, 2],
+ [2, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byCol = BooleanValueObject.create(true);
+ const resultObject = testFunction.calculate(array, byCol);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [2],
+ [2],
+ ]);
+
+ const byCol2 = NullValueObject.create();
+ const resultObject2 = testFunction.calculate(array, byCol2);
+ expect(getObjectValue(resultObject2)).toStrictEqual([
+ [2, 2],
+ ]);
+
+ const byCol3 = StringValueObject.create('test');
+ const resultObject3 = testFunction.calculate(array, byCol3);
+ expect(getObjectValue(resultObject3)).toStrictEqual(ErrorType.VALUE);
+
+ const byCol4 = ErrorValueObject.create(ErrorType.NAME);
+ const resultObject4 = testFunction.calculate(array, byCol4);
+ expect(getObjectValue(resultObject4)).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('ExactlyOnce value test', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [2, 2],
+ [2, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byCol = BooleanValueObject.create(false);
+ const exactlyOnce = BooleanValueObject.create(true);
+ const resultObject = testFunction.calculate(array, byCol, exactlyOnce);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.CALC);
+
+ const exactlyOnce2 = NullValueObject.create();
+ const resultObject2 = testFunction.calculate(array, byCol, exactlyOnce2);
+ expect(getObjectValue(resultObject2)).toStrictEqual([
+ [2, 2],
+ ]);
+
+ const exactlyOnce3 = StringValueObject.create('test');
+ const resultObject3 = testFunction.calculate(array, byCol, exactlyOnce3);
+ expect(getObjectValue(resultObject3)).toStrictEqual(ErrorType.VALUE);
+
+ const exactlyOnce4 = ErrorValueObject.create(ErrorType.NAME);
+ const resultObject4 = testFunction.calculate(array, byCol, exactlyOnce4);
+ expect(getObjectValue(resultObject4)).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('ByCol and exactlyOnce Value is array', async () => {
+ const array = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [2, 2],
+ [2, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const byCol = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['test', 1],
+ [null, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const exactlyOnce = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, 0, null],
+ [1, 'test', null],
+ [null, null, null],
+ ]),
+ rowCount: 3,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const resultObject = testFunction.calculate(array, byCol, exactlyOnce);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [ErrorType.VALUE, 2, ErrorType.NA],
+ [ErrorType.CALC, ErrorType.VALUE, ErrorType.NA],
+ [ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/unique/index.ts b/packages/engine-formula/src/functions/lookup/unique/index.ts
new file mode 100644
index 0000000000..d27ce62a5b
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/unique/index.ts
@@ -0,0 +1,228 @@
+/**
+ * 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, type Nullable } from '@univerjs/core';
+import { ErrorType } from '../../../basics/error-type';
+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+
+import { BaseFunction } from '../../base-function';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+
+interface ObjectMapType {
+ r: number;
+ valueObject: BaseValueObject;
+}
+
+export class Unique extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 3;
+
+ override calculate(array: BaseValueObject, byCol?: BaseValueObject, exactlyOnce?: BaseValueObject) {
+ byCol = byCol ?? BooleanValueObject.create(false);
+ exactlyOnce = exactlyOnce ?? BooleanValueObject.create(false);
+
+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;
+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;
+
+ const maxRowLength = Math.max(
+ byCol.isArray() ? (byCol as ArrayValueObject).getRowCount() : 1,
+ exactlyOnce.isArray() ? (exactlyOnce as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ byCol.isArray() ? (byCol as ArrayValueObject).getColumnCount() : 1,
+ exactlyOnce.isArray() ? (exactlyOnce as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const byColArray = expandArrayValueObject(maxRowLength, maxColumnLength, byCol, ErrorValueObject.create(ErrorType.NA));
+ const exactlyOnceArray = expandArrayValueObject(maxRowLength, maxColumnLength, exactlyOnce, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = byColArray.map((byColObject, rowIndex, columnIndex) => {
+ let exactlyOnceObject = exactlyOnceArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ if (array.isError()) {
+ return array;
+ }
+
+ if (byColObject.isString()) {
+ byColObject = byColObject.convertToNumberObjectValue();
+ }
+
+ if (byColObject.isError()) {
+ return byColObject;
+ }
+
+ if (exactlyOnceObject.isString()) {
+ exactlyOnceObject = exactlyOnceObject.convertToNumberObjectValue();
+ }
+
+ if (exactlyOnceObject.isError()) {
+ return exactlyOnceObject;
+ }
+
+ const byColValue = +byColObject.getValue();
+ const exactlyOnceValue = +exactlyOnceObject.getValue();
+
+ let result: Nullable<BaseValueObject>;
+
+ if ((!byColValue && arrayRowCount === 1) || (byColValue && arrayColumnCount === 1)) {
+ result = array;
+ } else {
+ let arrayValue = array.getArrayValue();
+ let arrayRows = arrayRowCount;
+ let arrayColumns = arrayColumnCount;
+
+ if (byColValue) {
+ arrayValue = this._transposeArray(arrayValue);
+ arrayRows = arrayColumnCount;
+ arrayColumns = arrayRowCount;
+ }
+
+ let repeatRows: Array<Array<number>> = [];
+
+ for (let c = 0; c < arrayColumns; c++) {
+ if (c === 0) {
+ const objects: Array<ObjectMapType> = new Array(arrayRows).fill(null).map((item, index) => {
+ return {
+ r: index,
+ valueObject: arrayValue[index][c] as BaseValueObject,
+ };
+ });
+
+ repeatRows = this._getRepeatRows(objects);
+ } else {
+ if (repeatRows.length === 0) {
+ break;
+ }
+
+ let newRepeatRows: Array<Array<number>> = [];
+
+ repeatRows.forEach((item) => {
+ const objects = item.map((r) => {
+ return {
+ r,
+ valueObject: arrayValue[r][c] as BaseValueObject,
+ };
+ });
+
+ const _repeatRows = this._getRepeatRows(objects);
+
+ newRepeatRows = newRepeatRows.concat(_repeatRows);
+ });
+
+ repeatRows = newRepeatRows;
+ }
+ }
+
+ if (repeatRows.length > 0) {
+ const spliceRows: number[] = [];
+
+ repeatRows.forEach((rows) => {
+ rows.forEach((r, index) => {
+ if (index !== 0 || exactlyOnceValue) {
+ spliceRows.push(r);
+ }
+ });
+ });
+
+ arrayValue = arrayValue.filter((row, rowIndex) => !spliceRows.includes(rowIndex));
+ }
+
+ if (arrayValue.length === 0) {
+ return ErrorValueObject.create(ErrorType.CALC);
+ }
+
+ if (byColValue) {
+ arrayValue = this._transposeArray(arrayValue);
+ }
+
+ result = ArrayValueObject.create({
+ calculateValueList: arrayValue,
+ rowCount: arrayValue.length,
+ columnCount: arrayValue[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ }
+
+ if ((maxRowLength > 1 || maxColumnLength > 1) && result?.isArray()) {
+ return (result as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return result;
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+
+ private _getRepeatRows(objects: Array<ObjectMapType>): Array<Array<number>> {
+ const valueMap = new Map();
+
+ objects.forEach((item) => {
+ const r = item.r;
+ const valueObject = item.valueObject;
+
+ let value: Nullable<string | number | boolean> = valueObject.getValue();
+
+ if (valueObject.isNull()) {
+ value = null;
+ } else if (valueObject.isString() && isRealNum(value as number)) {
+ value = +value;
+ }
+
+ if (!valueMap.has(value)) {
+ valueMap.set(value, [r]);
+ } else {
+ const valueMapItem = valueMap.get(value);
+ valueMapItem.push(r);
+ valueMap.set(value, valueMapItem);
+ }
+ });
+
+ return Array.from(valueMap.values()).filter((item) => item.length > 1);
+ }
+
+ private _transposeArray(array: Nullable<BaseValueObject>[][]) {
+ // Create a new 2D array as the transposed matrix
+ const rows = array.length;
+ const cols = array[0].length;
+ const transposedArray: Nullable<BaseValueObject>[][] = [];
+
+ // Traverse the columns of the original two-dimensional array
+ for (let col = 0; col < cols; col++) {
+ // Create new row
+ transposedArray[col] = [] as BaseValueObject[];
+
+ // Traverse the rows of the original two-dimensional array
+ for (let row = 0; row < rows; row++) {
+ // Assign elements to new rows
+ transposedArray[col][row] = array[row][col];
+ }
+ }
+
+ return transposedArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/lookup/vstack/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/vstack/__tests__/index.spec.ts
new file mode 100644
index 0000000000..373e2e11be
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/vstack/__tests__/index.spec.ts
@@ -0,0 +1,107 @@
+/**
+ * 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 { ArrayValueObject } from '../../../../engine/value-object/array-value-object';
+import { FUNCTION_NAMES_LOOKUP } from '../../function-names';
+import { Vstack } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { getObjectValue } from '../../../__tests__/create-function-test-bed';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test vstack function', () => {
+ const testFunction = new Vstack(FUNCTION_NAMES_LOOKUP.VSTACK);
+
+ describe('Vstack', () => {
+ it('Value is normal', async () => {
+ const array1 = StringValueObject.create('a');
+ const array2 = StringValueObject.create('b');
+ const array3 = StringValueObject.create('c');
+ const array4 = StringValueObject.create('d');
+ const resultObject = testFunction.calculate(array1, array2, array3, array4);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ ['a'],
+ ['b'],
+ ['c'],
+ ['d'],
+ ]);
+ });
+
+ it('Array variant columns less than max columns, fill #N/A', async () => {
+ const array1 = StringValueObject.create('a');
+ const array2 = StringValueObject.create('b');
+ const array3 = StringValueObject.create('c');
+ const array4 = StringValueObject.create('d');
+ const array5 = ArrayValueObject.create('{e,f}');
+ const resultObject = testFunction.calculate(array1, array2, array3, array4, array5);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ ['a', ErrorType.NA],
+ ['b', ErrorType.NA],
+ ['c', ErrorType.NA],
+ ['d', ErrorType.NA],
+ ['e', 'f'],
+ ]);
+ });
+
+ it('Array value is error', async () => {
+ const array1 = ErrorValueObject.create(ErrorType.NAME);
+ const array2 = NumberValueObject.create(1);
+ const resultObject = testFunction.calculate(array1, array2);
+ expect(getObjectValue(resultObject)).toStrictEqual(ErrorType.NAME);
+ });
+
+ it('Array value is blank cell', async () => {
+ const array1 = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const array2 = NullValueObject.create();
+ const resultObject = testFunction.calculate(array1, array2);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, 3],
+ [2, 3, 4],
+ [0, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+
+ it('Array value is boolean', async () => {
+ const array1 = ArrayValueObject.create('{1,2,3;2,3,4}');
+ const array2 = BooleanValueObject.create(true);
+ const array3 = BooleanValueObject.create(false);
+ const resultObject = testFunction.calculate(array1, array2, array3);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, 3],
+ [2, 3, 4],
+ [true, ErrorType.NA, ErrorType.NA],
+ [false, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+
+ it('Array value is different number of rows', async () => {
+ const array1 = ArrayValueObject.create('{1,2}');
+ const array2 = ArrayValueObject.create('{"test";"a";"b"}');
+ const array3 = ArrayValueObject.create('{4,5,6;5,6,7}');
+ const resultObject = testFunction.calculate(array1, array2, array3);
+ expect(getObjectValue(resultObject)).toStrictEqual([
+ [1, 2, ErrorType.NA],
+ ['test', ErrorType.NA, ErrorType.NA],
+ ['a', ErrorType.NA, ErrorType.NA],
+ ['b', ErrorType.NA, ErrorType.NA],
+ [4, 5, 6],
+ [5, 6, 7],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/lookup/vstack/index.ts b/packages/engine-formula/src/functions/lookup/vstack/index.ts
new file mode 100644
index 0000000000..55d8f3db0e
--- /dev/null
+++ b/packages/engine-formula/src/functions/lookup/vstack/index.ts
@@ -0,0 +1,78 @@
+/**
+ * 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 { Nullable } from '@univerjs/core';
+import { ErrorType } from '../../../basics/error-type';
+import { ArrayValueObject } from '../../../engine/value-object/array-value-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 Vstack extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 255;
+
+ override calculate(...variants: BaseValueObject[]) {
+ const maxColumnLength = Math.max(
+ ...variants.map((variantObject) => variantObject.isArray() ? (variantObject as ArrayValueObject).getColumnCount() : 1)
+ );
+
+ const result: BaseValueObject[][] = [];
+
+ for (let i = 0; i < variants.length; i++) {
+ const variantObject = variants[i];
+
+ if (variantObject.isError()) {
+ return variantObject;
+ }
+
+ const rowCount = variantObject.isArray() ? (variantObject as ArrayValueObject).getRowCount() : 1;
+ const columnCount = variantObject.isArray() ? (variantObject as ArrayValueObject).getColumnCount() : 1;
+
+ for (let r = 0; r < rowCount; r++) {
+ const row: BaseValueObject[] = [];
+
+ for (let c = 0; c < maxColumnLength; c++) {
+ let singleObject: Nullable<BaseValueObject> = variantObject;
+
+ if (variantObject.isArray()) {
+ singleObject = (variantObject as ArrayValueObject).get(r, c);
+ }
+
+ if (c > columnCount - 1 || !singleObject) {
+ row.push(ErrorValueObject.create(ErrorType.NA));
+ } else {
+ row.push(singleObject);
+ }
+ }
+
+ result.push(row);
+ }
+ }
+
+ return ArrayValueObject.create({
+ calculateValueList: result,
+ rowCount: result.length,
+ columnCount: result[0].length || 0,
+ unitId: this.unitId as string,
+ sheetId: this.subUnitId as string,
+ row: this.row,
+ column: this.column,
+ });
+ }
+}
diff --git a/packages/engine-formula/src/functions/math/function-map.ts b/packages/engine-formula/src/functions/math/function-map.ts
index 61d280da0e..ee5ddaa554 100644
--- a/packages/engine-formula/src/functions/math/function-map.ts
+++ b/packages/engine-formula/src/functions/math/function-map.ts
@@ -75,6 +75,7 @@ import { Sumxmy2 } from './sumxmy2';
import { Sumproduct } from './sumproduct';
import { Tan } from './tan';
import { Tanh } from './tanh';
+import { Trunc } from './trunc';
export const functionMath = [
[Abs, FUNCTION_NAMES_MATH.ABS],
@@ -137,4 +138,5 @@ export const functionMath = [
[Sumproduct, FUNCTION_NAMES_MATH.SUMPRODUCT],
[Tan, FUNCTION_NAMES_MATH.TAN],
[Tanh, FUNCTION_NAMES_MATH.TANH],
+ [Trunc, FUNCTION_NAMES_MATH.TRUNC],
];
diff --git a/packages/engine-formula/src/functions/math/trunc/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/trunc/__tests__/index.spec.ts
new file mode 100644
index 0000000000..b35ee9deb6
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/trunc/__tests__/index.spec.ts
@@ -0,0 +1,114 @@
+/**
+ * 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 { Trunc } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test trunc function', () => {
+ const testFunction = new Trunc(FUNCTION_NAMES_MATH.TRUNC);
+
+ describe('Trunc', () => {
+ it('Value is normal number', () => {
+ const number = NumberValueObject.create(2.15);
+ const result = testFunction.calculate(number);
+ expect(result.getValue()).toBe(2);
+ });
+
+ it('Value is normal number 2', () => {
+ const number = NumberValueObject.create(2.149);
+ const numDigits = NumberValueObject.create(2);
+ const result = testFunction.calculate(number, numDigits);
+ expect(result.getValue()).toBe(2.14);
+ });
+
+ it('Value is number valid', () => {
+ const number = NumberValueObject.create(-1.475);
+ const numDigits = NumberValueObject.create(2);
+ const result = testFunction.calculate(number, numDigits);
+ expect(result.getValue()).toBe(-1.47);
+ });
+
+ it('Value is number string', () => {
+ const number = StringValueObject.create('21.5');
+ const numDigits = StringValueObject.create('-1');
+ const result = testFunction.calculate(number, numDigits);
+ expect(result.getValue()).toBe(20);
+ });
+
+ it('Value is normal string', () => {
+ const number = StringValueObject.create('test');
+ const numDigits = NumberValueObject.create(1);
+ const result = testFunction.calculate(number, numDigits);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Value is boolean', () => {
+ const number = NumberValueObject.create(2.15);
+ const numDigits = BooleanValueObject.create(true);
+ const result = testFunction.calculate(number, numDigits);
+ expect(result.getValue()).toBe(2.1);
+ });
+
+ it('Value is blank cell', () => {
+ const number = NumberValueObject.create(2.15);
+ const numDigits = NullValueObject.create();
+ const result = testFunction.calculate(number, numDigits);
+ expect(result.getValue()).toBe(2);
+ });
+
+ it('Value is error', () => {
+ const number = ErrorValueObject.create(ErrorType.NAME);
+ const numDigits = NumberValueObject.create(1);
+ const result = testFunction.calculate(number, numDigits);
+ expect(result.getValue()).toBe(ErrorType.NAME);
+ });
+
+ it('Value is array and array', () => {
+ const number = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [2.15, 2.149, -1.575, '21.5', 626.3, 1.98, '-50.55'],
+ ]),
+ rowCount: 1,
+ columnCount: 7,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const numDigits = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1, true, 2, false, -1, -2.5, -3, null, ' '],
+ ]),
+ rowCount: 1,
+ columnCount: 9,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(number, numDigits);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [2.1, 2.1, -1.57, 21, 620, 0, 0, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/math/trunc/index.ts b/packages/engine-formula/src/functions/math/trunc/index.ts
new file mode 100644
index 0000000000..57384d89bc
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/trunc/index.ts
@@ -0,0 +1,81 @@
+/**
+ * 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';
+import { baseEpsilon, multiply } from '../../../engine/utils/math-kit';
+
+export class Trunc extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 2;
+
+ override calculate(number: BaseValueObject, numDigits?: BaseValueObject) {
+ numDigits = numDigits ?? NumberValueObject.create(0);
+
+ const maxRowLength = Math.max(
+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,
+ numDigits.isArray() ? (numDigits as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,
+ numDigits.isArray() ? (numDigits as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));
+ const numDigitsArray = expandArrayValueObject(maxRowLength, maxColumnLength, numDigits, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {
+ let numDigitsObject = numDigitsArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ if (numberObject.isString()) {
+ numberObject = numberObject.convertToNumberObjectValue();
+ }
+
+ if (numberObject.isError()) {
+ return numberObject;
+ }
+
+ if (numDigitsObject.isString()) {
+ numDigitsObject = numDigitsObject.convertToNumberObjectValue();
+ }
+
+ if (numDigitsObject.isError()) {
+ return numDigitsObject;
+ }
+
+ const numberValue = +numberObject.getValue();
+ const numDigitsValue = +numDigitsObject.getValue();
+
+ const factor = 10 ** Math.trunc(numDigitsValue);
+ const epsilon = baseEpsilon(numberValue, factor);
+ const result = Math.trunc(multiply(numberValue, factor) + epsilon) / factor;
+
+ return NumberValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as NumberValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/text/function-map.ts b/packages/engine-formula/src/functions/text/function-map.ts
index 3cb8699c8c..9bf2eca2a4 100644
--- a/packages/engine-formula/src/functions/text/function-map.ts
+++ b/packages/engine-formula/src/functions/text/function-map.ts
@@ -14,19 +14,27 @@
* limitations under the License.
*/
-import { Concatenate } from './concatenate';
import { FUNCTION_NAMES_TEXT } from './function-names';
+import { Concat } from './concat';
+import { Concatenate } from './concatenate';
import { Len } from './len';
import { Lenb } from './lenb';
-import { Text } from './text';
import { Lower } from './lower';
-import { Concat } from './concat';
+import { Rept } from './rept';
+import { Text } from './text';
+import { Textafter } from './textafter';
+import { Textbefore } from './textbefore';
+import { Textsplit } from './textsplit';
export const functionText = [
[Concat, FUNCTION_NAMES_TEXT.CONCAT],
[Concatenate, FUNCTION_NAMES_TEXT.CONCATENATE],
[Len, FUNCTION_NAMES_TEXT.LEN],
[Lenb, FUNCTION_NAMES_TEXT.LENB],
- [Text, FUNCTION_NAMES_TEXT.TEXT],
[Lower, FUNCTION_NAMES_TEXT.LOWER],
+ [Rept, FUNCTION_NAMES_TEXT.REPT],
+ [Text, FUNCTION_NAMES_TEXT.TEXT],
+ [Textafter, FUNCTION_NAMES_TEXT.TEXTAFTER],
+ [Textbefore, FUNCTION_NAMES_TEXT.TEXTBEFORE],
+ [Textsplit, FUNCTION_NAMES_TEXT.TEXTSPLIT],
];
diff --git a/packages/engine-formula/src/functions/text/rept/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/rept/__test__/index.spec.ts
new file mode 100644
index 0000000000..ec093fc95c
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/rept/__test__/index.spec.ts
@@ -0,0 +1,100 @@
+/**
+ * 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_TEXT } from '../../function-names';
+import { Rept } from '../index';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } 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 rept function', () => {
+ const testFunction = new Rept(FUNCTION_NAMES_TEXT.REPT);
+
+ describe('Rept', () => {
+ it('Value is normal', () => {
+ const text = StringValueObject.create('*-');
+ const numberTimes = NumberValueObject.create(3);
+ const result = testFunction.calculate(text, numberTimes);
+ expect(result.getValue()).toBe('*-*-*-');
+ });
+
+ it('Value is number', () => {
+ const text = NumberValueObject.create(1);
+ const numberTimes = NumberValueObject.create(3);
+ const result = testFunction.calculate(text, numberTimes);
+ expect(result.getValue()).toBe('111');
+ });
+
+ it('Value is boolean', () => {
+ const text = BooleanValueObject.create(true);
+ const numberTimes = BooleanValueObject.create(true);
+ const result = testFunction.calculate(text, numberTimes);
+ expect(result.getValue()).toBe('TRUE');
+
+ const numberTimes2 = BooleanValueObject.create(false);
+ const result2 = testFunction.calculate(text, numberTimes2);
+ expect(result2.getValue()).toBe('');
+ });
+
+ it('Value is blank cell', () => {
+ const text = StringValueObject.create('abc');
+ const numberTimes = NullValueObject.create();
+ const result = testFunction.calculate(text, numberTimes);
+ expect(result.getValue()).toBe('');
+ });
+
+ it('Value is array', () => {
+ const text = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, true, false, null, 'test'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const numberTimes = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2],
+ [true],
+ [false],
+ [null],
+ ['test'],
+ [-1],
+ ]),
+ rowCount: 6,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = testFunction.calculate(text, numberTimes);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['11', 'TRUETRUE', 'FALSEFALSE', '', 'testtest'],
+ ['1', 'TRUE', 'FALSE', '', 'test'],
+ ['', '', '', '', ''],
+ ['', '', '', '', ''],
+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE],
+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/text/rept/index.ts b/packages/engine-formula/src/functions/text/rept/index.ts
new file mode 100644
index 0000000000..cabe703537
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/rept/index.ts
@@ -0,0 +1,98 @@
+/**
+ * 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 { StringValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Rept extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 2;
+
+ override calculate(text: BaseValueObject, numberTimes: BaseValueObject) {
+ if (text.isError()) {
+ return text;
+ }
+
+ if (numberTimes.isError()) {
+ return numberTimes;
+ }
+
+ // get max row length
+ const maxRowLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,
+ numberTimes.isArray() ? (numberTimes as ArrayValueObject).getRowCount() : 1
+ );
+
+ // get max column length
+ const maxColumnLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,
+ numberTimes.isArray() ? (numberTimes as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create(ErrorType.NA));
+ const numberTimesArray = expandArrayValueObject(maxRowLength, maxColumnLength, numberTimes, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = textArray.map((textObject, rowIndex, columnIndex) => {
+ let numberTimesObject = numberTimesArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ if (textObject.isError()) {
+ return textObject;
+ }
+
+ let textValue = textObject.getValue();
+
+ if (textObject.isNull()) {
+ textValue = '';
+ }
+
+ if (textObject.isBoolean()) {
+ textValue = textValue ? 'TRUE' : 'FALSE';
+ }
+
+ textValue += '';
+
+ if (numberTimesObject.isString()) {
+ numberTimesObject = numberTimesObject.convertToNumberObjectValue();
+ }
+
+ if (numberTimesObject.isError()) {
+ return numberTimesObject;
+ }
+
+ const stringMaxLength = 32767;
+ const numberTimesValue = Math.floor(+numberTimesObject.getValue());
+
+ if (numberTimesValue < 0 || numberTimesValue > stringMaxLength / (textValue as string).length) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ const result = (textValue as string).repeat(numberTimesValue);
+
+ return StringValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/text/textafter/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/textafter/__test__/index.spec.ts
new file mode 100644
index 0000000000..42160e3e94
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/textafter/__test__/index.spec.ts
@@ -0,0 +1,149 @@
+/**
+ * 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_TEXT } from '../../function-names';
+import { Textafter } from '../index';
+import { NumberValueObject, StringValueObject } 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 textafter function', () => {
+ const testFunction = new Textafter(FUNCTION_NAMES_TEXT.TEXTAFTER);
+
+ describe('Textafter', () => {
+ it('value is normal', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('T');
+ const result = testFunction.calculate(text, delimiter);
+ expect(result.getValue()).toBe('RUETRUEFALSE');
+ });
+
+ it('delimiter value is empty string', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('');
+ const instanceNum = NumberValueObject.create(1);
+ const result = testFunction.calculate(text, delimiter, instanceNum);
+ expect(result.getValue()).toBe('***TRUETRUEFALSE');
+
+ const instanceNum2 = NumberValueObject.create(-1);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum2);
+ expect(result2.getValue()).toBe('');
+ });
+
+ it('instanceNum value test', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('T');
+ const instanceNum = NumberValueObject.create(1);
+ const result = testFunction.calculate(text, delimiter, instanceNum);
+ expect(result.getValue()).toBe('RUETRUEFALSE');
+
+ const instanceNum2 = NumberValueObject.create(2);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum2);
+ expect(result2.getValue()).toBe('RUEFALSE');
+
+ const instanceNum3 = NumberValueObject.create(3);
+ const result3 = testFunction.calculate(text, delimiter, instanceNum3);
+ expect(result3.getValue()).toBe(ErrorType.NA);
+
+ const instanceNum4 = NumberValueObject.create(17);
+ const result4 = testFunction.calculate(text, delimiter, instanceNum4);
+ expect(result4.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('matchMode value 0 or 1', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(1);
+ const matchMode = NumberValueObject.create(-1);
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ const matchMode2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum, matchMode2);
+ expect(result2.getValue()).toBe(ErrorType.NA);
+
+ const matchMode3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(text, delimiter, instanceNum, matchMode3);
+ expect(result3.getValue()).toBe('RUETRUEFALSE');
+ });
+
+ it('matchEnd value 0 or 1', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(3);
+ const matchMode = NumberValueObject.create(1);
+ const matchEnd = NumberValueObject.create(0);
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd);
+ expect(result.getValue()).toBe(ErrorType.NA);
+
+ const matchEnd2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd2);
+ expect(result2.getValue()).toBe('');
+
+ const instanceNum3 = NumberValueObject.create(-3);
+ const result3 = testFunction.calculate(text, delimiter, instanceNum3, matchMode, matchEnd2);
+ expect(result3.getValue()).toBe('***TRUETRUEFALSE');
+ });
+
+ it('ifNotFound value test', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(3);
+ const matchMode = NumberValueObject.create(1);
+ const matchEnd = NumberValueObject.create(0);
+ const ifNotFound = StringValueObject.create('not found');
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd, ifNotFound);
+ expect(result.getValue()).toBe('not found');
+ });
+
+ it('Value is array', () => {
+ const text = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, true, false, null, '***TRUETRUEFALSE'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(1);
+ const matchMode = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [0],
+ [1],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ }); ;
+ const matchEnd = NumberValueObject.create(0);
+ const ifNotFound = StringValueObject.create('not found');
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd, ifNotFound);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['not found', 'not found', 'not found', ErrorType.VALUE, 'not found'],
+ ['not found', 'RUE', 'not found', ErrorType.VALUE, 'RUETRUEFALSE'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/text/textafter/index.ts b/packages/engine-formula/src/functions/text/textafter/index.ts
new file mode 100644
index 0000000000..9a0933c8f4
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/textafter/index.ts
@@ -0,0 +1,231 @@
+/**
+ * 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, StringValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Textafter extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 6;
+
+ override calculate(text: BaseValueObject, delimiter: BaseValueObject, instanceNum?: BaseValueObject, matchMode?: BaseValueObject, matchEnd?: BaseValueObject, ifNotFound?: BaseValueObject) {
+ let instanceNumIsNull = false; // special handle
+ const onlyThreeVariant = !matchMode;
+
+ instanceNum = instanceNum ?? NumberValueObject.create(1);
+ matchMode = matchMode ?? NumberValueObject.create(0);
+ matchEnd = matchEnd ?? NumberValueObject.create(0);
+ ifNotFound = ifNotFound ?? ErrorValueObject.create(ErrorType.NA);
+
+ if (instanceNum.isNull()) {
+ instanceNumIsNull = true;
+ instanceNum = NumberValueObject.create(1);
+ }
+
+ if (delimiter.isArray()) {
+ delimiter = (delimiter as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ // get max row length
+ const maxRowLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,
+ instanceNum.isArray() ? (instanceNum as ArrayValueObject).getRowCount() : 1,
+ matchMode.isArray() ? (matchMode as ArrayValueObject).getRowCount() : 1,
+ matchEnd.isArray() ? (matchEnd as ArrayValueObject).getRowCount() : 1,
+ ifNotFound.isArray() ? (ifNotFound as ArrayValueObject).getRowCount() : 1
+ );
+
+ // get max column length
+ const maxColumnLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,
+ instanceNum.isArray() ? (instanceNum as ArrayValueObject).getColumnCount() : 1,
+ matchMode.isArray() ? (matchMode as ArrayValueObject).getColumnCount() : 1,
+ matchEnd.isArray() ? (matchEnd as ArrayValueObject).getColumnCount() : 1,
+ ifNotFound.isArray() ? (ifNotFound as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create(ErrorType.NA));
+ const instanceNumArray = expandArrayValueObject(maxRowLength, maxColumnLength, instanceNum, ErrorValueObject.create(ErrorType.NA));
+ const matchModeArray = expandArrayValueObject(maxRowLength, maxColumnLength, matchMode, ErrorValueObject.create(ErrorType.NA));
+ const matchEndArray = expandArrayValueObject(maxRowLength, maxColumnLength, matchEnd, ErrorValueObject.create(ErrorType.NA));
+ const ifNotFoundArray = expandArrayValueObject(maxRowLength, maxColumnLength, ifNotFound, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = textArray.map((textObject, rowIndex, columnIndex) => {
+ let instanceNumObject = instanceNumArray.get(rowIndex, columnIndex) as BaseValueObject;
+ let matchModeObject = matchModeArray.get(rowIndex, columnIndex) as BaseValueObject;
+ let matchEndObject = matchEndArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const ifNotFoundObject = ifNotFoundArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ // variant error order (text > instanceNum > matchMode > matchEnd > delimiter)
+ if (textObject.isError()) {
+ return textObject;
+ }
+
+ if (instanceNumObject.isError()) {
+ return instanceNumObject;
+ }
+
+ if (matchModeObject.isError()) {
+ return matchModeObject;
+ }
+
+ if (matchEndObject.isError()) {
+ return matchEndObject;
+ }
+
+ if (delimiter.isError()) {
+ return delimiter;
+ }
+
+ let textValue = textObject.getValue() as string;
+
+ if (textObject.isNull()) {
+ textValue = '';
+ }
+
+ if (textObject.isBoolean()) {
+ textValue = textValue ? 'TRUE' : 'FALSE';
+ }
+
+ textValue += '';
+
+ let delimiterValue = delimiter.getValue() as string;
+
+ if (delimiter.isNull()) {
+ delimiterValue = '';
+ }
+
+ if (delimiter.isBoolean()) {
+ delimiterValue = delimiterValue ? 'TRUE' : 'FALSE';
+ }
+
+ delimiterValue += '';
+
+ if (instanceNumObject.isString()) {
+ instanceNumObject = instanceNumObject.convertToNumberObjectValue();
+
+ if (instanceNumObject.isError()) {
+ return instanceNumObject;
+ }
+ }
+
+ const instanceNumValue = Math.floor(+instanceNumObject.getValue());
+
+ // if instance_num = 0 returns a #VALUE! error
+ if (instanceNumValue === 0) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (matchModeObject.isString()) {
+ matchModeObject = matchModeObject.convertToNumberObjectValue();
+
+ if (matchModeObject.isError()) {
+ return matchModeObject;
+ }
+ }
+
+ const matchModeValue = Math.floor(+matchModeObject.getValue());
+
+ if (matchModeValue < 0 || matchModeValue > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (matchEndObject.isString()) {
+ matchEndObject = matchEndObject.convertToNumberObjectValue();
+
+ if (matchEndObject.isError()) {
+ return matchEndObject;
+ }
+ }
+
+ const matchEndValue = Math.floor(+matchEndObject.getValue());
+
+ if (matchEndValue < 0 || matchEndValue > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ // When searching with an empty delimiter value, TEXTAFTER matches immediately.
+ // It returns the entire text when searching from the front (if instance_num is positive) and empty text when searching from the end (if instance_num is negative).
+ if (delimiterValue === '') {
+ if (instanceNumValue > 0) {
+ return StringValueObject.create(textValue);
+ } else {
+ return StringValueObject.create('');
+ }
+ }
+
+ // if instance_num is greater than the length of text returns a #VALUE! error
+ if (!instanceNumIsNull && Math.abs(instanceNumValue) > textValue.length) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (delimiterValue.length > textValue.length) {
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ const matchNum = textValue.match(new RegExp(delimiterValue, `g${!matchModeValue ? '' : 'i'}`));
+
+ // only three variant and if instance_num is greater than the number of occurrences of delimiter. returns a #N/A error
+ if (matchNum && matchNum.length < Math.abs(instanceNumValue) && onlyThreeVariant) {
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ if (!matchNum || matchNum.length < Math.abs(instanceNumValue)) {
+ if (matchEndValue) {
+ if (instanceNumValue > 0) {
+ return StringValueObject.create('');
+ } else {
+ return StringValueObject.create(textValue);
+ }
+ }
+
+ return ifNotFoundObject;
+ }
+
+ let substrText = !matchModeValue ? textValue : textValue.toLocaleLowerCase();
+ delimiterValue = !matchModeValue ? delimiterValue : delimiterValue.toLocaleLowerCase();
+
+ let resultIndex = 0;
+
+ for (let i = 0; i < Math.abs(instanceNumValue); i++) {
+ if (instanceNumValue < 0) {
+ const index = substrText.lastIndexOf(delimiterValue);
+ resultIndex = index;
+ substrText = substrText.substr(0, index);
+ } else {
+ const index = substrText.indexOf(delimiterValue);
+ resultIndex += (index + i * delimiterValue.length);
+ substrText = substrText.substr(index + delimiterValue.length);
+ }
+ }
+
+ const result = textValue.substr(resultIndex + delimiterValue.length);
+
+ return StringValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as StringValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/text/textbefore/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/textbefore/__test__/index.spec.ts
new file mode 100644
index 0000000000..dcb8818e74
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/textbefore/__test__/index.spec.ts
@@ -0,0 +1,149 @@
+/**
+ * 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_TEXT } from '../../function-names';
+import { Textbefore } from '../index';
+import { NumberValueObject, StringValueObject } 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 textbefore function', () => {
+ const testFunction = new Textbefore(FUNCTION_NAMES_TEXT.TEXTBEFORE);
+
+ describe('Textbefore', () => {
+ it('value is normal', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('T');
+ const result = testFunction.calculate(text, delimiter);
+ expect(result.getValue()).toBe('***');
+ });
+
+ it('delimiter value is empty string', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('');
+ const instanceNum = NumberValueObject.create(1);
+ const result = testFunction.calculate(text, delimiter, instanceNum);
+ expect(result.getValue()).toBe('');
+
+ const instanceNum2 = NumberValueObject.create(-1);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum2);
+ expect(result2.getValue()).toBe('***TRUETRUEFALSE');
+ });
+
+ it('instanceNum value test', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('T');
+ const instanceNum = NumberValueObject.create(1);
+ const result = testFunction.calculate(text, delimiter, instanceNum);
+ expect(result.getValue()).toBe('***');
+
+ const instanceNum2 = NumberValueObject.create(2);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum2);
+ expect(result2.getValue()).toBe('***TRUE');
+
+ const instanceNum3 = NumberValueObject.create(3);
+ const result3 = testFunction.calculate(text, delimiter, instanceNum3);
+ expect(result3.getValue()).toBe(ErrorType.NA);
+
+ const instanceNum4 = NumberValueObject.create(17);
+ const result4 = testFunction.calculate(text, delimiter, instanceNum4);
+ expect(result4.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('matchMode value 0 or 1', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(1);
+ const matchMode = NumberValueObject.create(-1);
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ const matchMode2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum, matchMode2);
+ expect(result2.getValue()).toBe(ErrorType.NA);
+
+ const matchMode3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(text, delimiter, instanceNum, matchMode3);
+ expect(result3.getValue()).toBe('***');
+ });
+
+ it('matchEnd value 0 or 1', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(3);
+ const matchMode = NumberValueObject.create(1);
+ const matchEnd = NumberValueObject.create(0);
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd);
+ expect(result.getValue()).toBe(ErrorType.NA);
+
+ const matchEnd2 = NumberValueObject.create(1);
+ const result2 = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd2);
+ expect(result2.getValue()).toBe('***TRUETRUEFALSE');
+
+ const instanceNum3 = NumberValueObject.create(-3);
+ const result3 = testFunction.calculate(text, delimiter, instanceNum3, matchMode, matchEnd2);
+ expect(result3.getValue()).toBe('');
+ });
+
+ it('ifNotFound value test', () => {
+ const text = StringValueObject.create('***TRUETRUEFALSE');
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(3);
+ const matchMode = NumberValueObject.create(1);
+ const matchEnd = NumberValueObject.create(0);
+ const ifNotFound = StringValueObject.create('not found');
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd, ifNotFound);
+ expect(result.getValue()).toBe('not found');
+ });
+
+ it('Value is array', () => {
+ const text = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, true, false, null, '***TRUETRUEFALSE'],
+ ]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const delimiter = StringValueObject.create('t');
+ const instanceNum = NumberValueObject.create(1);
+ const matchMode = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [0],
+ [1],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ }); ;
+ const matchEnd = NumberValueObject.create(0);
+ const ifNotFound = StringValueObject.create('not found');
+ const result = testFunction.calculate(text, delimiter, instanceNum, matchMode, matchEnd, ifNotFound);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['not found', 'not found', 'not found', ErrorType.VALUE, 'not found'],
+ ['not found', '', 'not found', ErrorType.VALUE, '***'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/text/textbefore/index.ts b/packages/engine-formula/src/functions/text/textbefore/index.ts
new file mode 100644
index 0000000000..1bfbe17810
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/textbefore/index.ts
@@ -0,0 +1,231 @@
+/**
+ * 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, StringValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Textbefore extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 6;
+
+ override calculate(text: BaseValueObject, delimiter: BaseValueObject, instanceNum?: BaseValueObject, matchMode?: BaseValueObject, matchEnd?: BaseValueObject, ifNotFound?: BaseValueObject) {
+ let instanceNumIsNull = false; // special handle
+ const onlyThreeVariant = !matchMode;
+
+ instanceNum = instanceNum ?? NumberValueObject.create(1);
+ matchMode = matchMode ?? NumberValueObject.create(0);
+ matchEnd = matchEnd ?? NumberValueObject.create(0);
+ ifNotFound = ifNotFound ?? ErrorValueObject.create(ErrorType.NA);
+
+ if (instanceNum.isNull()) {
+ instanceNumIsNull = true;
+ instanceNum = NumberValueObject.create(1);
+ }
+
+ if (delimiter.isArray()) {
+ delimiter = (delimiter as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+
+ // get max row length
+ const maxRowLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,
+ instanceNum.isArray() ? (instanceNum as ArrayValueObject).getRowCount() : 1,
+ matchMode.isArray() ? (matchMode as ArrayValueObject).getRowCount() : 1,
+ matchEnd.isArray() ? (matchEnd as ArrayValueObject).getRowCount() : 1,
+ ifNotFound.isArray() ? (ifNotFound as ArrayValueObject).getRowCount() : 1
+ );
+
+ // get max column length
+ const maxColumnLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,
+ instanceNum.isArray() ? (instanceNum as ArrayValueObject).getColumnCount() : 1,
+ matchMode.isArray() ? (matchMode as ArrayValueObject).getColumnCount() : 1,
+ matchEnd.isArray() ? (matchEnd as ArrayValueObject).getColumnCount() : 1,
+ ifNotFound.isArray() ? (ifNotFound as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create(ErrorType.NA));
+ const instanceNumArray = expandArrayValueObject(maxRowLength, maxColumnLength, instanceNum, ErrorValueObject.create(ErrorType.NA));
+ const matchModeArray = expandArrayValueObject(maxRowLength, maxColumnLength, matchMode, ErrorValueObject.create(ErrorType.NA));
+ const matchEndArray = expandArrayValueObject(maxRowLength, maxColumnLength, matchEnd, ErrorValueObject.create(ErrorType.NA));
+ const ifNotFoundArray = expandArrayValueObject(maxRowLength, maxColumnLength, ifNotFound, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = textArray.map((textObject, rowIndex, columnIndex) => {
+ let instanceNumObject = instanceNumArray.get(rowIndex, columnIndex) as BaseValueObject;
+ let matchModeObject = matchModeArray.get(rowIndex, columnIndex) as BaseValueObject;
+ let matchEndObject = matchEndArray.get(rowIndex, columnIndex) as BaseValueObject;
+ const ifNotFoundObject = ifNotFoundArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ // variant error order (text > instanceNum > matchMode > matchEnd > delimiter)
+ if (textObject.isError()) {
+ return textObject;
+ }
+
+ if (instanceNumObject.isError()) {
+ return instanceNumObject;
+ }
+
+ if (matchModeObject.isError()) {
+ return matchModeObject;
+ }
+
+ if (matchEndObject.isError()) {
+ return matchEndObject;
+ }
+
+ if (delimiter.isError()) {
+ return delimiter;
+ }
+
+ let textValue = textObject.getValue() as string;
+
+ if (textObject.isNull()) {
+ textValue = '';
+ }
+
+ if (textObject.isBoolean()) {
+ textValue = textValue ? 'TRUE' : 'FALSE';
+ }
+
+ textValue += '';
+
+ let delimiterValue = delimiter.getValue() as string;
+
+ if (delimiter.isNull()) {
+ delimiterValue = '';
+ }
+
+ if (delimiter.isBoolean()) {
+ delimiterValue = delimiterValue ? 'TRUE' : 'FALSE';
+ }
+
+ delimiterValue += '';
+
+ if (instanceNumObject.isString()) {
+ instanceNumObject = instanceNumObject.convertToNumberObjectValue();
+
+ if (instanceNumObject.isError()) {
+ return instanceNumObject;
+ }
+ }
+
+ const instanceNumValue = Math.floor(+instanceNumObject.getValue());
+
+ // if instance_num = 0 returns a #VALUE! error
+ if (instanceNumValue === 0) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (matchModeObject.isString()) {
+ matchModeObject = matchModeObject.convertToNumberObjectValue();
+
+ if (matchModeObject.isError()) {
+ return matchModeObject;
+ }
+ }
+
+ const matchModeValue = Math.floor(+matchModeObject.getValue());
+
+ if (matchModeValue < 0 || matchModeValue > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (matchEndObject.isString()) {
+ matchEndObject = matchEndObject.convertToNumberObjectValue();
+
+ if (matchEndObject.isError()) {
+ return matchEndObject;
+ }
+ }
+
+ const matchEndValue = Math.floor(+matchEndObject.getValue());
+
+ if (matchEndValue < 0 || matchEndValue > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ // When searching with an empty delimiter value, TEXTBEFORE matches immediately.
+ // It returns empty text when searching from the front (if instance_num is positive) and the entire text when searching from the end (if instance_num is negative).
+ if (delimiterValue === '') {
+ if (instanceNumValue > 0) {
+ return StringValueObject.create('');
+ } else {
+ return StringValueObject.create(textValue);
+ }
+ }
+
+ // if instance_num is greater than the length of text returns a #VALUE! error
+ if (!instanceNumIsNull && Math.abs(instanceNumValue) > textValue.length) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (delimiterValue.length > textValue.length) {
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ const matchNum = textValue.match(new RegExp(delimiterValue, `g${!matchModeValue ? '' : 'i'}`));
+
+ // only three variant and if instance_num is greater than the number of occurrences of delimiter. returns a #N/A error
+ if (matchNum && matchNum.length < Math.abs(instanceNumValue) && onlyThreeVariant) {
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ if (!matchNum || matchNum.length < Math.abs(instanceNumValue)) {
+ if (matchEndValue) {
+ if (instanceNumValue > 0) {
+ return StringValueObject.create(textValue);
+ } else {
+ return StringValueObject.create('');
+ }
+ }
+
+ return ifNotFoundObject;
+ }
+
+ let substrText = !matchModeValue ? textValue : textValue.toLocaleLowerCase();
+ delimiterValue = !matchModeValue ? delimiterValue : delimiterValue.toLocaleLowerCase();
+
+ let resultIndex = 0;
+
+ for (let i = 0; i < Math.abs(instanceNumValue); i++) {
+ if (instanceNumValue < 0) {
+ const index = substrText.lastIndexOf(delimiterValue);
+ resultIndex = index;
+ substrText = substrText.substr(0, index);
+ } else {
+ const index = substrText.indexOf(delimiterValue);
+ resultIndex += (index + i * delimiterValue.length);
+ substrText = substrText.substr(index + delimiterValue.length);
+ }
+ }
+
+ const result = textValue.substr(0, resultIndex);
+
+ return StringValueObject.create(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as StringValueObject;
+ }
+
+ return resultArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/text/textsplit/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/textsplit/__test__/index.spec.ts
new file mode 100644
index 0000000000..7be3a718bb
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/textsplit/__test__/index.spec.ts
@@ -0,0 +1,154 @@
+/**
+ * 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_TEXT } from '../../function-names';
+import { Textsplit } from '../index';
+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+
+describe('Test textsplit function', () => {
+ const testFunction = new Textsplit(FUNCTION_NAMES_TEXT.TEXTSPLIT);
+
+ describe('Textsplit', () => {
+ it('value is normal', () => {
+ const text = StringValueObject.create('Dakota Lennon Sanchez');
+ const colDelimiter = StringValueObject.create(' ');
+ const result = testFunction.calculate(text, colDelimiter);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['Dakota', 'Lennon', 'Sanchez'],
+ ]);
+
+ const text2 = StringValueObject.create('1,2,3;4,5,6');
+ const colDelimiter2 = StringValueObject.create(',');
+ const rowDelimiter2 = StringValueObject.create(';');
+ const result2 = testFunction.calculate(text2, colDelimiter2, rowDelimiter2);
+ expect(transformToValue(result2.getArrayValue())).toStrictEqual([
+ [1, 2, 3],
+ [4, 5, 6],
+ ]);
+ });
+
+ it('delimiter value is empty string', () => {
+ const text = StringValueObject.create('To be or not to be');
+ const colDelimiter = StringValueObject.create('');
+ const result = testFunction.calculate(text, colDelimiter);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ const colDelimiter2 = StringValueObject.create(' ');
+ const rowDelimiter2 = StringValueObject.create('');
+ const result2 = testFunction.calculate(text, colDelimiter2, rowDelimiter2);
+ expect(result2.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('ignoreEmpty value is true', () => {
+ const text = StringValueObject.create('Do. Or do not. There is no try. -Anonymous');
+ const colDelimiter = StringValueObject.create(' ');
+ const rowDelimiter = StringValueObject.create('.');
+ const ignoreEmpty = BooleanValueObject.create(true);
+ const result = testFunction.calculate(text, colDelimiter, rowDelimiter, ignoreEmpty);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['Do', ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ['Or', 'do', 'not', ErrorType.NA],
+ ['There', 'is', 'no', 'try'],
+ ['-Anonymous', ErrorType.NA, ErrorType.NA, ErrorType.NA],
+ ]);
+ });
+
+ it('matchMode value 0 or 1', () => {
+ const text = StringValueObject.create('Do. Or do not. There is no try. -Anonymous');
+ const colDelimiter = ArrayValueObject.create('{"o","t"}');
+ const rowDelimiter = StringValueObject.create(' ');
+ const ignoreEmpty = BooleanValueObject.create(true);
+ const matchMode = NumberValueObject.create(-1);
+ const result = testFunction.calculate(text, colDelimiter, rowDelimiter, ignoreEmpty, matchMode);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+
+ const matchMode2 = NumberValueObject.create(0);
+ const result2 = testFunction.calculate(text, colDelimiter, rowDelimiter, ignoreEmpty, matchMode2);
+ expect(transformToValue(result2.getArrayValue())).toStrictEqual([
+ ['D', '.', ErrorType.NA],
+ ['Or', ErrorType.NA, ErrorType.NA],
+ ['d', ErrorType.NA, ErrorType.NA],
+ ['n', '.', ErrorType.NA],
+ ['There', ErrorType.NA, ErrorType.NA],
+ ['is', ErrorType.NA, ErrorType.NA],
+ ['n', ErrorType.NA, ErrorType.NA],
+ ['ry.', ErrorType.NA, ErrorType.NA],
+ ['-An', 'nym', 'us'],
+ ]);
+
+ const matchMode3 = NumberValueObject.create(1);
+ const result3 = testFunction.calculate(text, colDelimiter, rowDelimiter, ignoreEmpty, matchMode3);
+ expect(transformToValue(result3.getArrayValue())).toStrictEqual([
+ ['D', '.', ErrorType.NA],
+ ['r', ErrorType.NA, ErrorType.NA],
+ ['d', ErrorType.NA, ErrorType.NA],
+ ['n', '.', ErrorType.NA],
+ ['here', ErrorType.NA, ErrorType.NA],
+ ['is', ErrorType.NA, ErrorType.NA],
+ ['n', ErrorType.NA, ErrorType.NA],
+ ['ry.', ErrorType.NA, ErrorType.NA],
+ ['-An', 'nym', 'us'],
+ ]);
+ });
+
+ it('padWith value test', () => {
+ const text = StringValueObject.create('Do. Or do not. There is no try. -Anonymous');
+ const colDelimiter = ArrayValueObject.create('{"o","t"}');
+ const rowDelimiter = StringValueObject.create(' ');
+ const ignoreEmpty = BooleanValueObject.create(true);
+ const matchMode = NumberValueObject.create(0);
+ const padWith = ErrorValueObject.create(ErrorType.NULL);
+ const result = testFunction.calculate(text, colDelimiter, rowDelimiter, ignoreEmpty, matchMode, padWith);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['D', '.', ErrorType.NULL],
+ ['Or', ErrorType.NULL, ErrorType.NULL],
+ ['d', ErrorType.NULL, ErrorType.NULL],
+ ['n', '.', ErrorType.NULL],
+ ['There', ErrorType.NULL, ErrorType.NULL],
+ ['is', ErrorType.NULL, ErrorType.NULL],
+ ['n', ErrorType.NULL, ErrorType.NULL],
+ ['ry.', ErrorType.NULL, ErrorType.NULL],
+ ['-An', 'nym', 'us'],
+ ]);
+ });
+
+ it('Value is array', () => {
+ const text = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ ['Dakota Lennon Sanchez 0'],
+ ['To be or not to be'],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const colDelimiter = StringValueObject.create(' ');
+ const result = testFunction.calculate(text, colDelimiter);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['Dakota'],
+ ['To'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/text/textsplit/index.ts b/packages/engine-formula/src/functions/text/textsplit/index.ts
new file mode 100644
index 0000000000..cff22d327c
--- /dev/null
+++ b/packages/engine-formula/src/functions/text/textsplit/index.ts
@@ -0,0 +1,259 @@
+/**
+ * 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 { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Textsplit extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 6;
+
+ override calculate(text: BaseValueObject, colDelimiter: BaseValueObject, rowDelimiter?: BaseValueObject, ignoreEmpty?: BaseValueObject, matchMode?: BaseValueObject, padWith?: BaseValueObject) {
+ rowDelimiter = rowDelimiter ?? StringValueObject.create('\\s');
+ ignoreEmpty = ignoreEmpty ?? NumberValueObject.create(0);
+ matchMode = matchMode ?? NumberValueObject.create(0);
+ padWith = padWith ?? StringValueObject.create(ErrorType.NA);
+
+ const colDelimiterValue: string[] = [];
+
+ if (colDelimiter.isArray()) {
+ (colDelimiter as ArrayValueObject).iterator((colDelimiterObject) => {
+ if (colDelimiterObject?.isError()) {
+ colDelimiter = colDelimiterObject;
+ return false;
+ }
+
+ if (colDelimiterObject?.isNull()) {
+ colDelimiter = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ const delimiterValue = this._getRegExpStringValue(colDelimiterObject as BaseValueObject);
+
+ if (delimiterValue === '') {
+ colDelimiter = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ colDelimiterValue.push(delimiterValue);
+ });
+ } else {
+ const delimiterValue = this._getRegExpStringValue(colDelimiter);
+
+ if (delimiterValue === '') {
+ colDelimiter = ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ colDelimiterValue.push(delimiterValue);
+ }
+
+ const rowDelimiterValue: string[] = [];
+
+ if (rowDelimiter.isArray()) {
+ (rowDelimiter as ArrayValueObject).iterator((rowDelimiterObject) => {
+ if (rowDelimiterObject?.isError()) {
+ rowDelimiter = rowDelimiterObject;
+ return false;
+ }
+
+ if (rowDelimiterObject?.isNull()) {
+ rowDelimiter = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ const delimiterValue = this._getRegExpStringValue(rowDelimiterObject as BaseValueObject);
+
+ if (delimiterValue === '') {
+ rowDelimiter = ErrorValueObject.create(ErrorType.VALUE);
+ return false;
+ }
+
+ rowDelimiterValue.push(delimiterValue);
+ });
+ } else {
+ const delimiterValue = this._getRegExpStringValue(rowDelimiter);
+
+ if (delimiterValue === '') {
+ rowDelimiter = ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ rowDelimiterValue.push(delimiterValue);
+ }
+
+ let padWithRowCount = 1;
+ let padWithColumnCount = 1;
+
+ if (padWith.isArray()) {
+ padWithRowCount = (padWith as ArrayValueObject).getRowCount();
+ padWithColumnCount = (padWith as ArrayValueObject).getColumnCount();
+
+ if (padWithRowCount === 1 && padWithColumnCount === 1) {
+ padWith = (padWith as ArrayValueObject).get(0, 0) as BaseValueObject;
+ }
+ }
+
+ // get max row length
+ const maxRowLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,
+ ignoreEmpty.isArray() ? (ignoreEmpty as ArrayValueObject).getRowCount() : 1,
+ matchMode.isArray() ? (matchMode as ArrayValueObject).getRowCount() : 1
+ );
+
+ // get max column length
+ const maxColumnLength = Math.max(
+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,
+ ignoreEmpty.isArray() ? (ignoreEmpty as ArrayValueObject).getColumnCount() : 1,
+ matchMode.isArray() ? (matchMode as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create(ErrorType.NA));
+ const ignoreEmptyArray = expandArrayValueObject(maxRowLength, maxColumnLength, ignoreEmpty, ErrorValueObject.create(ErrorType.NA));
+ const matchModeArray = expandArrayValueObject(maxRowLength, maxColumnLength, matchMode, ErrorValueObject.create(ErrorType.NA));
+
+ const resultArray = textArray.map((textObject, rowIndex, columnIndex) => {
+ let ignoreEmptyObject = ignoreEmptyArray.get(rowIndex, columnIndex) as BaseValueObject;
+ let matchModeObject = matchModeArray.get(rowIndex, columnIndex) as BaseValueObject;
+
+ if (textObject.isError()) {
+ return textObject;
+ }
+
+ if (colDelimiter.isError()) {
+ return colDelimiter;
+ }
+
+ if ((rowDelimiter as BaseValueObject).isError()) {
+ return rowDelimiter as ErrorValueObject;
+ }
+
+ if (ignoreEmptyObject.isError()) {
+ return ignoreEmptyObject;
+ }
+
+ if (matchModeObject.isError()) {
+ return matchModeObject;
+ }
+
+ if (textObject.isNull()) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ if (padWithRowCount > 1 || padWithColumnCount > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ let textValue = textObject.getValue() as string;
+
+ if (textObject.isBoolean()) {
+ textValue = textValue ? 'TRUE' : 'FALSE';
+ }
+
+ textValue += '';
+
+ if (ignoreEmptyObject.isString()) {
+ ignoreEmptyObject = ignoreEmptyObject.convertToNumberObjectValue();
+
+ if (ignoreEmptyObject.isError()) {
+ return ignoreEmptyObject;
+ }
+ }
+
+ const ignoreEmptyValue = Math.floor(+ignoreEmptyObject.getValue());
+
+ if (matchModeObject.isString()) {
+ matchModeObject = matchModeObject.convertToNumberObjectValue();
+
+ if (matchModeObject.isError()) {
+ return matchModeObject;
+ }
+ }
+
+ const matchModeValue = Math.floor(+matchModeObject.getValue());
+
+ if (matchModeValue < 0 || matchModeValue > 1) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ let padWithValue = padWith.getValue() as string;
+
+ if (padWith.isBoolean()) {
+ padWithValue = padWithValue ? 'TRUE' : 'FALSE';
+ }
+
+ padWithValue += '';
+
+ const rowDelimiterRegExp = new RegExp(rowDelimiterValue.join('|'), `g${!matchModeValue ? '' : 'i'}`);
+ const colDelimiterRegExp = new RegExp(colDelimiterValue.join('|'), `g${!matchModeValue ? '' : 'i'}`);
+
+ const resultRows = textValue.split(rowDelimiterRegExp);
+
+ let resultColsMaxCount = 1;
+
+ let result = resultRows.map((row) => {
+ let cols = row.split(colDelimiterRegExp);
+
+ if (ignoreEmptyValue) {
+ cols = cols.filter((col) => col !== '');
+ }
+
+ resultColsMaxCount = Math.max(resultColsMaxCount, cols.length);
+
+ return cols;
+ });
+
+ result = result.map((row) => {
+ if (row.length < resultColsMaxCount) {
+ row = row.concat(new Array(resultColsMaxCount - row.length).fill(padWithValue));
+ }
+
+ return row;
+ });
+
+ return ArrayValueObject.createByArray(result);
+ });
+
+ if (maxRowLength === 1 && maxColumnLength === 1) {
+ return (resultArray as ArrayValueObject).get(0, 0) as ArrayValueObject;
+ } else {
+ return resultArray.map((item) => (item as ArrayValueObject).get(0, 0) as BaseValueObject);
+ }
+ }
+
+ private _getRegExpStringValue(valueObject: BaseValueObject): string {
+ let value = valueObject.getValue() as string;
+
+ if (valueObject.isNull()) {
+ value = '\\s';
+ }
+
+ if (valueObject.isBoolean()) {
+ value = value ? 'TRUE' : 'FALSE';
+ }
+
+ value += '';
+
+ return this._escapeRegExp(value);
+ }
+
+ private _escapeRegExp(string: string): string {
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+ }
+}
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 302a5efa19..4d115820d3 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
@@ -88,8 +88,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'The array containing the columns to be returned in the new array.' },
+ colNum1: { name: 'col_num1', detail: 'The first column to be returned.' },
+ colNum2: { name: 'col_num2', detail: 'Additional columns to be returned.' },
},
},
CHOOSEROWS: {
@@ -102,8 +103,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'The array containing the rows to be returned in the new array.' },
+ rowNum1: { name: 'row_num1', detail: 'The first row number to be returned.' },
+ rowNum2: { name: 'row_num2', detail: 'Additional row numbers to be returned.' },
},
},
COLUMN: {
@@ -170,8 +172,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'The range or array to filter.' },
+ include: { name: 'include', detail: 'An array of Boolean values ​​where TRUE indicates that a row or column is to be retained.' },
+ ifEmpty: { name: 'if_empty', detail: 'If no items are reserved, return.' },
},
},
FORMULATEXT: {
@@ -240,8 +243,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: 'array', detail: 'The arrays to append.' },
+ array2: { name: 'array', detail: 'The arrays to append.' },
},
},
HYPERLINK: {
@@ -408,8 +411,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'The range or array to be sorted.' },
+ sortIndex: { name: 'sort_index', detail: 'A number indicating the sort order (by row or by column).' },
+ sortOrder: { name: 'sort_order', detail: 'A number representing the desired sort order; 1 for ascending (default), -1 for descending.' },
+ byCol: { name: 'by_col', detail: 'Logical value indicating the desired sort direction; FALSE sorts by rows (default), TRUE sorts by columns.' },
},
},
SORTBY: {
@@ -422,8 +427,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'The range or array to be sorted.' },
+ byArray1: { name: 'by_array1', detail: 'The range or array to sort based on.' },
+ sortOrder1: { name: 'sort_order1', detail: 'A number representing the desired sort order; 1 for ascending (default), -1 for descending.' },
+ byArray2: { name: 'by_array2', detail: 'The range or array to sort based on.' },
+ sortOrder2: { name: 'sort_order2', detail: 'A number representing the desired sort order; 1 for ascending (default), -1 for descending.' },
},
},
TAKE: {
@@ -478,8 +486,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'A range of cells or an array in a worksheet.' },
},
},
UNIQUE: {
@@ -492,8 +499,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: 'array', detail: 'The range or array from which unique rows or columns are returned.' },
+ byCol: { name: 'by_col', detail: 'Is a logical value: compares rows to each other and returns unique values ​​= FALSE, or is omitted; compares columns to each other and returns unique values ​​= TRUE.' },
+ exactlyOnce: { name: 'exactly_once', detail: 'Is a logical value: returns rows or columns from the array that appear only once = TRUE; returns all distinct rows or columns from the array = FALSE, or has been omitted.' },
},
},
VLOOKUP: {
@@ -534,8 +542,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: 'array', detail: 'The arrays to append.' },
+ array2: { name: 'array', detail: 'The arrays to append.' },
},
},
WRAPCOLS: {
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 5ab22fb4cc..6368adce1e 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
@@ -77,8 +77,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: '新しい配列で返される列を含む配列。' },
+ colNum1: { name: '列番号1', detail: '返される最初の列。' },
+ colNum2: { name: '列番号2', detail: '返される追加の列。' },
},
},
CHOOSEROWS: {
@@ -91,8 +92,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: '新しい配列で返される行を含む配列。' },
+ rowNum1: { name: '行番号1', detail: '返される最初の行番号。' },
+ rowNum2: { name: '行番号2', detail: '返される追加の行番号。' },
},
},
COLUMN: {
@@ -159,8 +161,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: 'フィルターする範囲または配列。' },
+ include: { name: 'ブール配列', detail: 'ブール値の配列。TRUE は保持する行または列を示します。' },
+ ifEmpty: { name: '空の値を返す', detail: 'アイテムが保持されていない場合に返されます。' },
},
},
FORMULATEXT: {
@@ -229,8 +232,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: '配列', detail: '追加する配列。' },
+ array2: { name: '配列', detail: '追加する配列。' },
},
},
HYPERLINK: {
@@ -397,8 +400,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: '並べ替える範囲または配列。' },
+ sortIndex: { name: 'ソートインデックス', detail: '(行または列) による順序を表す数値。' },
+ sortOrder: { name: '並べ替え順序', detail: '希望の並べ替え順序を表す数値。連続 (デフォルト) の場合は 1、降順の場合は -1。' },
+ byCol: { name: '仕分け方向', detail: '希望するソート方向を示す論理値。行でソートする場合は FALSE (デフォルト)、列でソートする場合は TRUE。' },
},
},
SORTBY: {
@@ -411,8 +416,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: '並べ替える範囲または配列。' },
+ byArray1: { name: '配列の並べ替え1', detail: '並べ替えに基づいて並べ替える範囲または配列。' },
+ sortOrder1: { name: '並べ替え順序1', detail: '希望の並べ替え順序を表す数値。連続 (デフォルト) の場合は 1、降順の場合は -1。' },
+ byArray2: { name: '配列の並べ替え2', detail: '並べ替えに基づいて並べ替える範囲または配列。' },
+ sortOrder2: { name: '並べ替え順序2', detail: '希望の並べ替え順序を表す数値。連続 (デフォルト) の場合は 1、降順の場合は -1。' },
},
},
TAKE: {
@@ -467,8 +475,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: 'ワークシート内のセルの範囲または配列。' },
},
},
UNIQUE: {
@@ -481,8 +488,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '配列', detail: '一意の行または列が返される範囲または配列を返します。' },
+ byCol: { name: '列ごと', detail: '論理値です。行を相互に比較して一意の値 = FALSE を返します。省略されます。列を相互に比較して一意の値 = TRUE を返します。' },
+ exactlyOnce: { name: '1回だけ', detail: '論理値です。配列から 1 回だけ出現する行または列を返します = TRUE; 配列からすべての個別の行または列を返します = FALSE、または省略されます。' },
},
},
VLOOKUP: {
@@ -523,8 +531,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: '配列', detail: '追加する配列。' },
+ array2: { name: '配列', detail: '追加する配列。' },
},
},
WRAPCOLS: {
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 b2896b58cf..559690709a 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
@@ -78,8 +78,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '包含要在新数组中返回的列的数组。' },
+ colNum1: { name: '列号1', detail: '要返回的第一列。' },
+ colNum2: { name: '列号2', detail: '要返回的其他列。' },
},
},
CHOOSEROWS: {
@@ -92,8 +93,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '包含要在新数组中返回的行的数组。' },
+ rowNum1: { name: '行号1', detail: '要返回的第一行号。' },
+ rowNum2: { name: '行号2', detail: '要返回的其他行号。' },
},
},
COLUMN: {
@@ -160,8 +162,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '要筛选的区域或数组。' },
+ include: { name: '布尔值数组', detail: '布尔值数组,其中 TRUE 表示要保留的一行或一列。' },
+ ifEmpty: { name: '空值返回', detail: '如果未保留任何项,则返回。' },
},
},
FORMULATEXT: {
@@ -230,8 +233,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: '数组', detail: '要追加的数组。' },
+ array2: { name: '数组', detail: '要追加的数组。' },
},
},
HYPERLINK: {
@@ -395,8 +398,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '要排序的范围或数组。' },
+ sortIndex: { name: '排序索引', detail: '表示排序依据(按行或按列)的数字。' },
+ sortOrder: { name: '排序顺序', detail: '表示所需排序顺序的数字;1表示顺序(默认),-1表示降序。' },
+ byCol: { name: '排序方向', detail: '表示所需排序方向的逻辑值;FALSE指按行排序(默认),TRUE指按列排序。' },
},
},
SORTBY: {
@@ -409,8 +414,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '要排序的范围或数组。' },
+ byArray1: { name: '排序数组1', detail: '要基于其进行排序的范围或数组。' },
+ sortOrder1: { name: '排序顺序1', detail: '表示所需排序顺序的数字;1表示顺序(默认),-1表示降序。' },
+ byArray2: { name: '排序数组2', detail: '要基于其进行排序的范围或数组。' },
+ sortOrder2: { name: '排序顺序2', detail: '表示所需排序顺序的数字;1表示顺序(默认),-1表示降序。' },
},
},
TAKE: {
@@ -465,8 +473,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '工作表中的单元格区域或数组。' },
},
},
UNIQUE: {
@@ -479,8 +486,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '数组', detail: '从中返回唯一行或列的范围或数组。' },
+ byCol: { name: '依据列', detail: '是一个逻辑值:将行彼此比较并返回唯一值 = FALSE,或已省略;将列彼此比较并返回唯一值 = TRUE。' },
+ exactlyOnce: { name: '仅一次', detail: '是一个逻辑值:从数组中返回只出现一次的行或列 = TRUE;从数组中返回所有不同的行或列 = FALSE,或已省略。' },
},
},
VLOOKUP: {
@@ -522,8 +530,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: '数组', detail: '要追加的数组。' },
+ array2: { name: '数组', detail: '要追加的数组。' },
},
},
WRAPCOLS: {
diff --git a/packages/sheets-formula/src/locale/function-list/lookup/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/lookup/zh-TW.ts
index d16154b26e..c8cd669866 100644
--- a/packages/sheets-formula/src/locale/function-list/lookup/zh-TW.ts
+++ b/packages/sheets-formula/src/locale/function-list/lookup/zh-TW.ts
@@ -78,8 +78,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '陣列', detail: '包含要在新陣列中傳回之欄的陣列。' },
+ colNum1: { name: '欄數1', detail: '要返回的第一欄。' },
+ colNum2: { name: '欄數2', detail: '要返回的其他欄。' },
},
},
CHOOSEROWS: {
@@ -92,8 +93,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '陣列', detail: '包含要在新陣列中傳回之欄的陣列。' },
+ rowNum1: { name: '列數1', detail: '要返回的第一列數。' },
+ rowNum2: { name: '列數2', detail: '要返回的其他列數。' },
},
},
COLUMN: {
@@ -160,8 +162,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '陣列', detail: '要篩選的區域或陣列。' },
+ include: { name: '布林值數組', detail: '布林值數組,其中 TRUE 表示要保留的一行或一列。' },
+ ifEmpty: { name: '空值返回', detail: '如果未保留任何項,則傳回。' },
},
},
FORMULATEXT: {
@@ -230,8 +233,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: '陣列', detail: '要附加的陣列。' },
+ array2: { name: '陣列', detail: '要附加的陣列。' },
},
},
HYPERLINK: {
@@ -395,8 +398,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '陣列', detail: '要排序的範圍或陣列。' },
+ sortIndex: { name: '排序索引', detail: '表示排序依據(按行或按列)的數字。' },
+ sortOrder: { name: '排序順序', detail: '表示所需排序順序的數字;1表示順序(預設),-1表示降序。' },
+ byCol: { name: '排序方向', detail: '表示所需排序方向的邏輯值;FALSE指依行排序(預設),TRUE指依列排序。' },
},
},
SORTBY: {
@@ -409,8 +414,11 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '陣列', detail: '要排序的範圍或陣列。' },
+ byArray1: { name: '排序數組1', detail: '若要基於其進行排序的範圍或陣列。' },
+ sortOrder1: { name: '排序順序1', detail: '表示所需排序順序的數字;1表示順序(預設),-1表示降序。' },
+ byArray2: { name: '排序數組2', detail: '若要基於其進行排序的範圍或陣列。' },
+ sortOrder2: { name: '排序順序2', detail: '表示所需排序順序的數字;1表示順序(預設),-1表示降序。' },
},
},
TAKE: {
@@ -465,8 +473,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '陣列', detail: '工作表中的儲存格區域或陣列。' },
},
},
UNIQUE: {
@@ -479,8 +486,9 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array: { name: '陣列', detail: '從中傳回唯一行或列的範圍或陣列。' },
+ byCol: { name: '依據列', detail: '是一個邏輯值:將行彼此比較並傳回唯一值 = FALSE,或已省略;將列彼此比較並傳回唯一值 = TRUE。' },
+ exactlyOnce: { name: '僅一次', detail: '是邏輯值:從陣列傳回只出現一次的行或列 = TRUE;從陣列傳回所有不同的行或列 = FALSE,或已省略。' },
},
},
VLOOKUP: {
@@ -522,8 +530,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ array1: { name: '陣列', detail: '要附加的陣列。' },
+ array2: { name: '陣列', detail: '要附加的陣列。' },
},
},
WRAPCOLS: {
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 24d9782df1..4a68089e96 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
@@ -1154,8 +1154,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: 'number', detail: 'The number you want to truncate.' },
+ numDigits: { name: 'num_digits', detail: 'A number specifying the precision of the truncation. The default value for num_digits is 0 (zero).' },
},
},
};
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 71e60621af..c158f0fdb3 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
@@ -1145,8 +1145,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: '数値', detail: '小数部を切り捨てる数値を指定します。' },
+ numDigits: { name: '桁数', detail: '切り捨てを行った後の桁数を指定します。桁数の既定値は 0 (ゼロ) です。' },
},
},
};
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 f2e9d7656c..59467e724d 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
@@ -1155,8 +1155,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: '数值', detail: '需要截尾取整的数字。' },
+ numDigits: { name: '位数', detail: '用于指定取整精度的数字。num_digits 的默认值为 0(零)。' },
},
},
};
diff --git a/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts
index 19f4e34deb..abf95a17de 100644
--- a/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts
+++ b/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts
@@ -1167,8 +1167,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ number: { name: '數值', detail: '這是要取至整數的數字。' },
+ numDigits: { name: '位數', detail: '這是指定要捨去之精確位數的數字。其預設值為 0 (零)。' },
},
},
};
diff --git a/packages/sheets-formula/src/locale/function-list/text/en-US.ts b/packages/sheets-formula/src/locale/function-list/text/en-US.ts
index 986d1ba5c7..bfde48939a 100644
--- a/packages/sheets-formula/src/locale/function-list/text/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/text/en-US.ts
@@ -389,8 +389,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: 'text', detail: 'The text you want to repeat.' },
+ numberTimes: { name: 'numberTimes', detail: 'A positive number specifying the number of times to repeat text.' },
},
},
RIGHT: {
@@ -501,8 +501,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: 'text', detail: 'The text you are searching within. Wildcard characters not allowed.' },
+ delimiter: { name: 'delimiter', detail: 'The text that marks the point after which you want to extract.' },
+ instanceNum: { name: 'instance_num', detail: 'The instance of the delimiter after which you want to extract the text.' },
+ matchMode: { name: 'match_mode', detail: 'Determines whether the text search is case-sensitive. The default is case-sensitive.' },
+ matchEnd: { name: 'match_end', detail: 'Treats the end of text as a delimiter. By default, the text is an exact match.' },
+ ifNotFound: { name: 'if_not_found', detail: 'Value returned if no match is found. By default, #N/A is returned.' },
},
},
TEXTBEFORE: {
@@ -515,8 +519,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: 'text', detail: 'The text you are searching within. Wildcard characters not allowed.' },
+ delimiter: { name: 'delimiter', detail: 'The text that marks the point after which you want to extract.' },
+ instanceNum: { name: 'instance_num', detail: 'The instance of the delimiter after which you want to extract the text.' },
+ matchMode: { name: 'match_mode', detail: 'Determines whether the text search is case-sensitive. The default is case-sensitive.' },
+ matchEnd: { name: 'match_end', detail: 'Treats the end of text as a delimiter. By default, the text is an exact match.' },
+ ifNotFound: { name: 'if_not_found', detail: 'Value returned if no match is found. By default, #N/A is returned.' },
},
},
TEXTJOIN: {
@@ -543,8 +551,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: 'text', detail: 'The text to split.' },
+ colDelimiter: { name: 'col_delimiter', detail: 'The character or string by which to split the column.' },
+ rowDelimiter: { name: 'row_delimiter', detail: 'The character or string on which to split the line.' },
+ ignoreEmpty: { name: 'ignore_empty', detail: 'Whether to ignore empty cells. The default is FALSE.' },
+ matchMode: { name: 'match_mode', detail: 'Searches for a delimiter match in the text. By default, a case-sensitive match is done.' },
+ padWith: { name: 'pad_with', detail: 'The value to use for padding. By default, #N/A is used.' },
},
},
TRIM: {
diff --git a/packages/sheets-formula/src/locale/function-list/text/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/text/ja-JP.ts
index 90620f07e1..4cbe16d7ed 100644
--- a/packages/sheets-formula/src/locale/function-list/text/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/text/ja-JP.ts
@@ -390,8 +390,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字列', detail: '繰り返す文字列を指定します。' },
+ numberTimes: { name: '繰り返し回数', detail: '文字列を繰り返す回数を、正の数値で指定します。' },
},
},
RIGHT: {
@@ -502,8 +502,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字', detail: '検索対象のテキスト。ワイルドカード文字は使用できません。' },
+ delimiter: { name: 'デリミタ', detail: '抽出した後のポイントをマークするテキスト。' },
+ instanceNum: { name: 'インスタンス番号', detail: 'テキストを抽出する区切り記号のインスタンス。' },
+ matchMode: { name: 'マッチモード', detail: 'テキスト検索で大文字と小文字を区別するかどうかを指定します。既定では大文字と小文字が区別されます。' },
+ matchEnd: { name: 'マッチ終了', detail: 'テキストの末尾を区切り記号として扱います。既定では、テキストは完全一致です。' },
+ ifNotFound: { name: '比類のない価値', detail: '一致するものが見つからない場合に返される値。既定では、#N/A が返されます。' },
},
},
TEXTBEFORE: {
@@ -516,8 +520,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字', detail: '検索対象のテキスト。ワイルドカード文字は使用できません。' },
+ delimiter: { name: 'デリミタ', detail: '抽出した後のポイントをマークするテキスト。' },
+ instanceNum: { name: 'インスタンス番号', detail: 'テキストを抽出する区切り記号のインスタンス。' },
+ matchMode: { name: 'マッチモード', detail: 'テキスト検索で大文字と小文字を区別するかどうかを指定します。既定では大文字と小文字が区別されます。' },
+ matchEnd: { name: 'マッチ終了', detail: 'テキストの末尾を区切り記号として扱います。既定では、テキストは完全一致です。' },
+ ifNotFound: { name: '比類のない価値', detail: '一致するものが見つからない場合に返される値。既定では、#N/A が返されます。' },
},
},
TEXTJOIN: {
@@ -544,8 +552,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字', detail: '分割するテキスト。' },
+ colDelimiter: { name: '列デリミタ', detail: '列を分割する文字または文字列。' },
+ rowDelimiter: { name: '行デリミタ', detail: '行を分割する文字または文字列。' },
+ ignoreEmpty: { name: '空のセルを無視する', detail: '空のセルを無視するかどうか。デフォルトはFALSEです。' },
+ matchMode: { name: 'マッチモード', detail: 'テキスト内の区切り文字の一致を検索します。デフォルトでは、大文字と小文字が区別された照合が行われます。' },
+ padWith: { name: '塗りつぶし値', detail: 'パディングに使用する値。デフォルトでは、#N/A が使用されます。' },
},
},
TRIM: {
diff --git a/packages/sheets-formula/src/locale/function-list/text/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/text/zh-CN.ts
index e7f4da31c4..ca862f715b 100644
--- a/packages/sheets-formula/src/locale/function-list/text/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/text/zh-CN.ts
@@ -389,8 +389,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文本', detail: '需要重复显示的文本。' },
+ numberTimes: { name: '重复次数', detail: '用于指定文本重复次数的正数。' },
},
},
RIGHT: {
@@ -501,8 +501,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文本', detail: '你要在其中搜索的文本。不允许使用通配符。' },
+ delimiter: { name: '分隔符', detail: '标记要在其中提取的点的文本。' },
+ instanceNum: { name: '实例编号', detail: '要在其中提取文本的分隔符的实例。' },
+ matchMode: { name: '匹配模式', detail: '确定文本搜索是否区分大小写。 默认为区分大小写。' },
+ matchEnd: { name: '末尾匹配', detail: '将文本结尾视为分隔符。默认情况下,文本完全匹配。' },
+ ifNotFound: { name: '未匹配到的值', detail: '未找到匹配项时返回的值。默认情况下,返回 #N/A。' },
},
},
TEXTBEFORE: {
@@ -515,8 +519,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文本', detail: '你要在其中搜索的文本。不允许使用通配符。' },
+ delimiter: { name: '分隔符', detail: '标记要在其中提取的点的文本。' },
+ instanceNum: { name: '实例编号', detail: '要在其中提取文本的分隔符的实例。' },
+ matchMode: { name: '匹配模式', detail: '确定文本搜索是否区分大小写。 默认为区分大小写。' },
+ matchEnd: { name: '末尾匹配', detail: '将文本结尾视为分隔符。默认情况下,文本完全匹配。' },
+ ifNotFound: { name: '未匹配到的值', detail: '未找到匹配项时返回的值。默认情况下,返回 #N/A。' },
},
},
TEXTJOIN: {
@@ -543,8 +551,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文本', detail: '要拆分的文本。' },
+ colDelimiter: { name: '列分隔符', detail: '要拆分列依据的字符或字符串。' },
+ rowDelimiter: { name: '行分隔符', detail: '要拆分行依据的字符或字符串。' },
+ ignoreEmpty: { name: '忽略空单元格', detail: '是否忽略空单元格。默认为 FALSE。' },
+ matchMode: { name: '匹配模式', detail: '搜索文本中的分隔符匹配。默认情况下,会进行区分大小写的匹配。' },
+ padWith: { name: '填充值', detail: '用于填充的值。默认情况下,使用 #N/A。' },
},
},
TRIM: {
diff --git a/packages/sheets-formula/src/locale/function-list/text/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/text/zh-TW.ts
index 35cec533f0..124405d88c 100644
--- a/packages/sheets-formula/src/locale/function-list/text/zh-TW.ts
+++ b/packages/sheets-formula/src/locale/function-list/text/zh-TW.ts
@@ -388,8 +388,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字', detail: '這是要重複的文字。' },
+ numberTimes: { name: '重複次數', detail: '這是指定文字重複次數的正數。' },
},
},
RIGHT: {
@@ -500,8 +500,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字', detail: '您在此搜尋的文字。不允許萬用字元。' },
+ delimiter: { name: '分隔符號', detail: '標記要擷取之點之後的文字。' },
+ instanceNum: { name: '實例編號', detail: '要解壓縮文字的分隔符號實例。' },
+ matchMode: { name: '匹配模式', detail: '判斷文字搜尋是否區分大小寫。預設值會區分大小寫。' },
+ matchEnd: { name: '結尾匹配', detail: '將文字結尾視為分隔符號。根據預設,文字是完全相符項目。' },
+ ifNotFound: { name: '未匹配到的值', detail: '找不到相符項目時傳回的值。根據預設,會傳回 #N/A。' },
},
},
TEXTBEFORE: {
@@ -514,8 +518,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字', detail: '您在此搜尋的文字。不允許萬用字元。' },
+ delimiter: { name: '分隔符號', detail: '標記要擷取之點之後的文字。' },
+ instanceNum: { name: '實例編號', detail: '要解壓縮文字的分隔符號實例。' },
+ matchMode: { name: '匹配模式', detail: '判斷文字搜尋是否區分大小寫。預設值會區分大小寫。' },
+ matchEnd: { name: '結尾匹配', detail: '將文字結尾視為分隔符號。根據預設,文字是完全相符項目。' },
+ ifNotFound: { name: '未匹配到的值', detail: '找不到相符項目時傳回的值。根據預設,會傳回 #N/A。' },
},
},
TEXTJOIN: {
@@ -542,8 +550,12 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ text: { name: '文字', detail: '要拆分的文字。' },
+ colDelimiter: { name: '列分隔符', detail: '若要拆分列依據的字元或字串。' },
+ rowDelimiter: { name: '行分隔符', detail: '若要拆分行依據的字元或字串。' },
+ ignoreEmpty: { name: '忽略空單元格', detail: '是否忽略空單元格。預設為 FALSE。' },
+ matchMode: { name: '匹配模式', detail: '搜尋文字中的分隔符號匹配。預設情況下,會進行區分大小寫的匹配。' },
+ padWith: { name: '填充值', detail: '用於填充的值。預設情況下,使用 #N/A。' },
},
},
TRIM: {
diff --git a/packages/sheets-formula/src/services/function-list/lookup.ts b/packages/sheets-formula/src/services/function-list/lookup.ts
index 695bb6ffc7..0a6a4137da 100644
--- a/packages/sheets-formula/src/services/function-list/lookup.ts
+++ b/packages/sheets-formula/src/services/function-list/lookup.ts
@@ -118,19 +118,26 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.CHOOSECOLS.abstract',
functionParameter: [
{
- name: 'formula.functionList.CHOOSECOLS.functionParameter.number1.name',
- detail: 'formula.functionList.CHOOSECOLS.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CHOOSECOLS.functionParameter.array.name',
+ detail: 'formula.functionList.CHOOSECOLS.functionParameter.array.detail',
+ example: '{1,2,3;2,3,4}',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.CHOOSECOLS.functionParameter.number2.name',
- detail: 'formula.functionList.CHOOSECOLS.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CHOOSECOLS.functionParameter.colNum1.name',
+ detail: 'formula.functionList.CHOOSECOLS.functionParameter.colNum1.detail',
+ example: '1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.CHOOSECOLS.functionParameter.colNum2.name',
+ detail: 'formula.functionList.CHOOSECOLS.functionParameter.colNum2.detail',
+ example: '2',
+ require: 0,
+ repeat: 1,
+ },
],
},
{
@@ -140,19 +147,26 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.CHOOSEROWS.abstract',
functionParameter: [
{
- name: 'formula.functionList.CHOOSEROWS.functionParameter.number1.name',
- detail: 'formula.functionList.CHOOSEROWS.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CHOOSEROWS.functionParameter.array.name',
+ detail: 'formula.functionList.CHOOSEROWS.functionParameter.array.detail',
+ example: '{1,2,3;2,3,4}',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.CHOOSEROWS.functionParameter.number2.name',
- detail: 'formula.functionList.CHOOSEROWS.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.CHOOSEROWS.functionParameter.rowNum1.name',
+ detail: 'formula.functionList.CHOOSEROWS.functionParameter.rowNum1.detail',
+ example: '1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.CHOOSEROWS.functionParameter.rowNum2.name',
+ detail: 'formula.functionList.CHOOSEROWS.functionParameter.rowNum2.detail',
+ example: '2',
+ require: 0,
+ repeat: 1,
+ },
],
},
{
@@ -236,19 +250,26 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.FILTER.abstract',
functionParameter: [
{
- name: 'formula.functionList.FILTER.functionParameter.number1.name',
- detail: 'formula.functionList.FILTER.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.FILTER.functionParameter.array.name',
+ detail: 'formula.functionList.FILTER.functionParameter.array.detail',
+ example: 'A5:D20',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.FILTER.functionParameter.number2.name',
- detail: 'formula.functionList.FILTER.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.FILTER.functionParameter.include.name',
+ detail: 'formula.functionList.FILTER.functionParameter.include.detail',
+ example: '(C5:C20="Apple")*(A5:A20="East")',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.FILTER.functionParameter.ifEmpty.name',
+ detail: 'formula.functionList.FILTER.functionParameter.ifEmpty.detail',
+ example: '""',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -338,18 +359,18 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.HSTACK.abstract',
functionParameter: [
{
- name: 'formula.functionList.HSTACK.functionParameter.number1.name',
- detail: 'formula.functionList.HSTACK.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.HSTACK.functionParameter.array1.name',
+ detail: 'formula.functionList.HSTACK.functionParameter.array1.detail',
+ example: 'A2:C3',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.HSTACK.functionParameter.number2.name',
- detail: 'formula.functionList.HSTACK.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ name: 'formula.functionList.HSTACK.functionParameter.array2.name',
+ detail: 'formula.functionList.HSTACK.functionParameter.array2.detail',
+ example: 'E2:G3',
+ require: 0,
+ repeat: 1,
},
],
},
@@ -615,17 +636,31 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.SORT.abstract',
functionParameter: [
{
- name: 'formula.functionList.SORT.functionParameter.number1.name',
- detail: 'formula.functionList.SORT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SORT.functionParameter.array.name',
+ detail: 'formula.functionList.SORT.functionParameter.array.detail',
+ example: 'A2:A17',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.SORT.functionParameter.number2.name',
- detail: 'formula.functionList.SORT.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
+ name: 'formula.functionList.SORT.functionParameter.sortIndex.name',
+ detail: 'formula.functionList.SORT.functionParameter.sortIndex.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SORT.functionParameter.sortOrder.name',
+ detail: 'formula.functionList.SORT.functionParameter.sortOrder.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SORT.functionParameter.byCol.name',
+ detail: 'formula.functionList.SORT.functionParameter.byCol.detail',
+ example: 'false',
+ require: 0,
repeat: 0,
},
],
@@ -637,19 +672,40 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.SORTBY.abstract',
functionParameter: [
{
- name: 'formula.functionList.SORTBY.functionParameter.number1.name',
- detail: 'formula.functionList.SORTBY.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SORTBY.functionParameter.array.name',
+ detail: 'formula.functionList.SORTBY.functionParameter.array.detail',
+ example: 'D2:D9',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.SORTBY.functionParameter.number2.name',
- detail: 'formula.functionList.SORTBY.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SORTBY.functionParameter.byArray1.name',
+ detail: 'formula.functionList.SORTBY.functionParameter.byArray1.detail',
+ example: 'E2:E9',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SORTBY.functionParameter.sortOrder1.name',
+ detail: 'formula.functionList.SORTBY.functionParameter.sortOrder1.detail',
+ example: '1',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.SORTBY.functionParameter.byArray2.name',
+ detail: 'formula.functionList.SORTBY.functionParameter.byArray2.detail',
+ example: 'E2:E9',
+ require: 0,
+ repeat: 1,
+ },
+ {
+ name: 'formula.functionList.SORTBY.functionParameter.sortOrder2.name',
+ detail: 'formula.functionList.SORTBY.functionParameter.sortOrder2.detail',
+ example: '1',
+ require: 0,
+ repeat: 1,
+ },
],
},
{
@@ -725,16 +781,9 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.TRANSPOSE.abstract',
functionParameter: [
{
- name: 'formula.functionList.TRANSPOSE.functionParameter.number1.name',
- detail: 'formula.functionList.TRANSPOSE.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.TRANSPOSE.functionParameter.number2.name',
- detail: 'formula.functionList.TRANSPOSE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TRANSPOSE.functionParameter.array.name',
+ detail: 'formula.functionList.TRANSPOSE.functionParameter.array.detail',
+ example: 'A2:F9',
require: 1,
repeat: 0,
},
@@ -747,17 +796,24 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.UNIQUE.abstract',
functionParameter: [
{
- name: 'formula.functionList.UNIQUE.functionParameter.number1.name',
- detail: 'formula.functionList.UNIQUE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.UNIQUE.functionParameter.array.name',
+ detail: 'formula.functionList.UNIQUE.functionParameter.array.detail',
+ example: 'A2:A12',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.UNIQUE.functionParameter.number2.name',
- detail: 'formula.functionList.UNIQUE.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
+ name: 'formula.functionList.UNIQUE.functionParameter.byCol.name',
+ detail: 'formula.functionList.UNIQUE.functionParameter.byCol.detail',
+ example: 'false',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.UNIQUE.functionParameter.exactlyOnce.name',
+ detail: 'formula.functionList.UNIQUE.functionParameter.exactlyOnce.detail',
+ example: 'false',
+ require: 0,
repeat: 0,
},
],
@@ -805,18 +861,18 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [
abstract: 'formula.functionList.VSTACK.abstract',
functionParameter: [
{
- name: 'formula.functionList.VSTACK.functionParameter.number1.name',
- detail: 'formula.functionList.VSTACK.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.VSTACK.functionParameter.array1.name',
+ detail: 'formula.functionList.VSTACK.functionParameter.array1.detail',
+ example: 'A2:C3',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.VSTACK.functionParameter.number2.name',
- detail: 'formula.functionList.VSTACK.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ name: 'formula.functionList.VSTACK.functionParameter.array2.name',
+ detail: 'formula.functionList.VSTACK.functionParameter.array2.detail',
+ example: 'E2:G3',
+ require: 0,
+ repeat: 1,
},
],
},
diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.ts
index f47c111855..6c5410783f 100644
--- a/packages/sheets-formula/src/services/function-list/math.ts
+++ b/packages/sheets-formula/src/services/function-list/math.ts
@@ -1648,17 +1648,17 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
abstract: 'formula.functionList.TRUNC.abstract',
functionParameter: [
{
- name: 'formula.functionList.TRUNC.functionParameter.number1.name',
- detail: 'formula.functionList.TRUNC.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TRUNC.functionParameter.number.name',
+ detail: 'formula.functionList.TRUNC.functionParameter.number.detail',
+ example: '0.45',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.TRUNC.functionParameter.number2.name',
- detail: 'formula.functionList.TRUNC.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
+ name: 'formula.functionList.TRUNC.functionParameter.numDigits.name',
+ detail: 'formula.functionList.TRUNC.functionParameter.numDigits.detail',
+ example: '1',
+ require: 0,
repeat: 0,
},
],
diff --git a/packages/sheets-formula/src/services/function-list/text.ts b/packages/sheets-formula/src/services/function-list/text.ts
index a7f3756851..a23a4a14ae 100644
--- a/packages/sheets-formula/src/services/function-list/text.ts
+++ b/packages/sheets-formula/src/services/function-list/text.ts
@@ -575,16 +575,16 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [
abstract: 'formula.functionList.REPT.abstract',
functionParameter: [
{
- name: 'formula.functionList.REPT.functionParameter.number1.name',
- detail: 'formula.functionList.REPT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.REPT.functionParameter.text.name',
+ detail: 'formula.functionList.REPT.functionParameter.text.detail',
+ example: '"*-"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.REPT.functionParameter.number2.name',
- detail: 'formula.functionList.REPT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.REPT.functionParameter.numberTimes.name',
+ detail: 'formula.functionList.REPT.functionParameter.numberTimes.detail',
+ example: '3',
require: 1,
repeat: 0,
},
@@ -751,19 +751,47 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [
abstract: 'formula.functionList.TEXTAFTER.abstract',
functionParameter: [
{
- name: 'formula.functionList.TEXTAFTER.functionParameter.number1.name',
- detail: 'formula.functionList.TEXTAFTER.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TEXTAFTER.functionParameter.text.name',
+ detail: 'formula.functionList.TEXTAFTER.functionParameter.text.detail',
+ example: '"Red riding hood’s, red hood"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.TEXTAFTER.functionParameter.number2.name',
- detail: 'formula.functionList.TEXTAFTER.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TEXTAFTER.functionParameter.delimiter.name',
+ detail: 'formula.functionList.TEXTAFTER.functionParameter.delimiter.detail',
+ example: '"hood"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.TEXTAFTER.functionParameter.instanceNum.name',
+ detail: 'formula.functionList.TEXTAFTER.functionParameter.instanceNum.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTAFTER.functionParameter.matchMode.name',
+ detail: 'formula.functionList.TEXTAFTER.functionParameter.matchMode.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTAFTER.functionParameter.matchEnd.name',
+ detail: 'formula.functionList.TEXTAFTER.functionParameter.matchEnd.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTAFTER.functionParameter.ifNotFound.name',
+ detail: 'formula.functionList.TEXTAFTER.functionParameter.ifNotFound.detail',
+ example: '"not found"',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -773,19 +801,47 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [
abstract: 'formula.functionList.TEXTBEFORE.abstract',
functionParameter: [
{
- name: 'formula.functionList.TEXTBEFORE.functionParameter.number1.name',
- detail: 'formula.functionList.TEXTBEFORE.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TEXTBEFORE.functionParameter.text.name',
+ detail: 'formula.functionList.TEXTBEFORE.functionParameter.text.detail',
+ example: '"Red riding hood’s, red hood"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.TEXTBEFORE.functionParameter.number2.name',
- detail: 'formula.functionList.TEXTBEFORE.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TEXTBEFORE.functionParameter.delimiter.name',
+ detail: 'formula.functionList.TEXTBEFORE.functionParameter.delimiter.detail',
+ example: '"hood"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.TEXTBEFORE.functionParameter.instanceNum.name',
+ detail: 'formula.functionList.TEXTBEFORE.functionParameter.instanceNum.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTBEFORE.functionParameter.matchMode.name',
+ detail: 'formula.functionList.TEXTBEFORE.functionParameter.matchMode.detail',
+ example: '1',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTBEFORE.functionParameter.matchEnd.name',
+ detail: 'formula.functionList.TEXTBEFORE.functionParameter.matchEnd.detail',
+ example: '0',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTBEFORE.functionParameter.ifNotFound.name',
+ detail: 'formula.functionList.TEXTBEFORE.functionParameter.ifNotFound.detail',
+ example: '"not found"',
+ require: 0,
+ repeat: 0,
+ },
],
},
{
@@ -817,19 +873,47 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [
abstract: 'formula.functionList.TEXTSPLIT.abstract',
functionParameter: [
{
- name: 'formula.functionList.TEXTSPLIT.functionParameter.number1.name',
- detail: 'formula.functionList.TEXTSPLIT.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TEXTSPLIT.functionParameter.text.name',
+ detail: 'formula.functionList.TEXTSPLIT.functionParameter.text.detail',
+ example: '{1,2,3;4,5,6}',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.TEXTSPLIT.functionParameter.number2.name',
- detail: 'formula.functionList.TEXTSPLIT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.TEXTSPLIT.functionParameter.colDelimiter.name',
+ detail: 'formula.functionList.TEXTSPLIT.functionParameter.colDelimiter.detail',
+ example: '","',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.TEXTSPLIT.functionParameter.rowDelimiter.name',
+ detail: 'formula.functionList.TEXTSPLIT.functionParameter.rowDelimiter.detail',
+ example: '";"',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTSPLIT.functionParameter.ignoreEmpty.name',
+ detail: 'formula.functionList.TEXTSPLIT.functionParameter.ignoreEmpty.detail',
+ example: '',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTSPLIT.functionParameter.matchMode.name',
+ detail: 'formula.functionList.TEXTSPLIT.functionParameter.matchMode.detail',
+ example: '',
+ require: 0,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.TEXTSPLIT.functionParameter.padWith.name',
+ detail: 'formula.functionList.TEXTSPLIT.functionParameter.padWith.detail',
+ example: '',
+ require: 0,
+ repeat: 0,
+ },
],
},
{