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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(formula): add some lookup formulas (#3352)
wpxp1234565ab9c7d109cb
diff --git a/packages/engine-formula/src/functions/lookup/drop/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/drop/__tests__/index.spec.tsnew file mode 100644index 0000000000..f37e324575--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/drop/__tests__/index.spec.ts@@ -0,0 +1,336 @@+/**+ * 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 { Drop } 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 drop function', () => {+ const testFunction = new Drop(FUNCTION_NAMES_LOOKUP.DROP);++ describe('Drop', () => {+ 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 rows = NumberValueObject.create(1);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(2);++ const rows2 = NumberValueObject.create(0);+ const columns2 = NumberValueObject.create(0);+ const result2 = testFunction.calculate(array, rows2, columns2);+ expect(getObjectValue(result2)).toStrictEqual([+ [2, 2],+ [2, 2],+ ]);+ });++ it('Array value test', async () => {+ const array = ErrorValueObject.create(ErrorType.NAME);+ const rows = NumberValueObject.create(1);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const rows2 = NumberValueObject.create(0);+ const columns2 = NumberValueObject.create(0);+ const result2 = testFunction.calculate(array, rows2, columns2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const array2 = NumberValueObject.create(1);+ const rows3 = ArrayValueObject.create('{1;0;0}');+ const columns3 = ArrayValueObject.create('{1,0}');+ const result3 = testFunction.calculate(array2, rows3, columns3);+ expect(getObjectValue(result3)).toStrictEqual([+ [ErrorType.CALC, ErrorType.CALC],+ [ErrorType.CALC, 1],+ [ErrorType.CALC, 1],+ ]);++ const result4 = testFunction.calculate(array, rows3, columns3);+ expect(getObjectValue(result4)).toStrictEqual([+ [ErrorType.NAME, ErrorType.NAME],+ [ErrorType.NAME, ErrorType.NAME],+ [ErrorType.NAME, ErrorType.NAME],+ ]);++ const array3 = NullValueObject.create();+ const result5 = testFunction.calculate(array3, rows, columns);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);++ const result6 = testFunction.calculate(array3, rows3, columns3);+ expect(getObjectValue(result6)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ ]);+ });++ it('Rows value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(2);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.CALC);+ });++ it('Rows value test2', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = BooleanValueObject.create(true);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(2);+ });++ it('Rows value test3', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = BooleanValueObject.create(false);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2],+ [2],+ ]);+ });++ it('Rows value test4', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = StringValueObject.create('test');+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Rows value test5', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = ErrorValueObject.create(ErrorType.NAME);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Rows value test6', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = ArrayValueObject.create('{1,2}');+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.CALC],+ ]);+ });++ it('Columns value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = NumberValueObject.create(2);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.CALC);+ });++ it('Columns value test2', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = BooleanValueObject.create(true);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(2);+ });++ it('Columns value test3', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = BooleanValueObject.create(false);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2, 2],+ ]);+ });++ it('Columns value test4', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = StringValueObject.create('test');+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Columns value test5', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Columns value test6', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = ArrayValueObject.create('{1,2}');+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.CALC],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/lookup/drop/index.ts b/packages/engine-formula/src/functions/lookup/drop/index.tsnew file mode 100644index 0000000000..454d64e5ee--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/drop/index.ts@@ -0,0 +1,158 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Drop extends BaseFunction {+ override minParams = 2;++ override maxParams = 3;++ override calculate(array: BaseValueObject, rows: BaseValueObject, columns?: BaseValueObject): BaseValueObject {+ const _columns = columns ?? NumberValueObject.create(0);++ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;++ const maxRowLength = Math.max(+ rows.isArray() ? (rows as ArrayValueObject).getRowCount() : 1,+ _columns.isArray() ? (_columns as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ rows.isArray() ? (rows as ArrayValueObject).getColumnCount() : 1,+ _columns.isArray() ? (_columns as ArrayValueObject).getColumnCount() : 1+ );++ const rowsArray = expandArrayValueObject(maxRowLength, maxColumnLength, rows, ErrorValueObject.create(ErrorType.NA));+ const columnsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _columns, ErrorValueObject.create(ErrorType.NA));++ if (maxRowLength > 1 || maxColumnLength > 1) {+ return rowsArray.mapValue((rowsObject, rowIndex, columnIndex) => {+ const columnsObject = columnsArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (array.isError()) {+ return array;+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const { isError, errorObject } = this._checkRowsColumns(rowsObject, columnsObject, arrayRowCount, arrayColumnCount);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ if (array.isArray()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return array;+ });+ }++ if (array.isError()) {+ return array;+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const rowsObject = rows.isArray() ? (rows as ArrayValueObject).get(0, 0) as BaseValueObject : rows;+ const columnsObject = _columns.isArray() ? (_columns as ArrayValueObject).get(0, 0) as BaseValueObject : _columns;++ const { isError, errorObject, rowsValue, columnsValue } = this._checkRowsColumns(rowsObject, columnsObject, arrayRowCount, arrayColumnCount);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ return this._getResultArray(array, rowsValue as number, columnsValue as number, arrayRowCount, arrayColumnCount);+ }++ private _checkRowsColumns(rowsObject: BaseValueObject, columnsObject: BaseValueObject, arrayRowCount: number, arrayColumnCount: number) {+ if (rowsObject.isError()) {+ return {+ isError: true,+ errorObject: rowsObject as ErrorValueObject,+ };+ }++ if (columnsObject.isError()) {+ return {+ isError: true,+ errorObject: columnsObject as ErrorValueObject,+ };+ }++ const rowsValue = Math.trunc(+rowsObject.getValue());+ const columnsValue = Math.trunc(+columnsObject.getValue());++ if (Number.isNaN(rowsValue) || Number.isNaN(columnsValue)) {+ return {+ isError: true,+ errorObject: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ if (Math.abs(rowsValue) >= arrayRowCount || Math.abs(columnsValue) >= arrayColumnCount) {+ return {+ isError: true,+ errorObject: ErrorValueObject.create(ErrorType.CALC),+ };+ }++ return {+ isError: false,+ rowsValue,+ columnsValue,+ };+ }++ private _getResultArray(array: BaseValueObject, rows: number, columns: number, arrayRowCount: number, arrayColumnCount: number): BaseValueObject {+ const rowParam = rows >= 0 ? [rows, arrayRowCount] : [0, arrayRowCount + rows];+ const columnParam = columns >= 0 ? [columns, arrayColumnCount] : [0, arrayColumnCount + columns];++ let resultArray: ArrayValueObject;++ if ((rows === 0 && columns === 0)) {+ resultArray = array as ArrayValueObject;+ } else if (rows === 0) {+ resultArray = (array as ArrayValueObject).slice(undefined, columnParam) as ArrayValueObject;+ } else if (columns === 0) {+ resultArray = (array as ArrayValueObject).slice(rowParam, undefined) as ArrayValueObject;+ } else {+ resultArray = (array as ArrayValueObject).slice(rowParam, columnParam) as ArrayValueObject;+ }++ resultArray = resultArray.map((valueObject) => valueObject.isNull() ? NumberValueObject.create(0) : valueObject) as ArrayValueObject;++ if (arrayRowCount - rows === 1 && arrayColumnCount - columns === 1) {+ return resultArray.get(0, 0) as BaseValueObject;+ }++ return resultArray;+ };+}diff --git a/packages/engine-formula/src/functions/lookup/expand/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/expand/__tests__/index.spec.tsnew file mode 100644index 0000000000..b60be7ee7e--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/expand/__tests__/index.spec.ts@@ -0,0 +1,356 @@+/**+ * 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 { Expand } 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 expand function', () => {+ const testFunction = new Expand(FUNCTION_NAMES_LOOKUP.EXPAND);++ describe('Expand', () => {+ 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 rows = NumberValueObject.create(3);+ const columns = NumberValueObject.create(3);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2, 2, ErrorType.NA],+ [2, 2, ErrorType.NA],+ [ErrorType.NA, ErrorType.NA, ErrorType.NA],+ ]);+ });++ it('Array value test', async () => {+ const array = ErrorValueObject.create(ErrorType.NAME);+ const rows = NumberValueObject.create(1);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const rows2 = NumberValueObject.create(0);+ const columns2 = NumberValueObject.create(0);+ const result2 = testFunction.calculate(array, rows2, columns2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const array2 = NumberValueObject.create(1);+ const rows3 = ArrayValueObject.create('{1;0;0}');+ const columns3 = ArrayValueObject.create('{1,0}');+ const result3 = testFunction.calculate(array2, rows3, columns3);+ expect(getObjectValue(result3)).toStrictEqual([+ [1, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ ]);++ const result4 = testFunction.calculate(array, rows3, columns3);+ expect(getObjectValue(result4)).toStrictEqual([+ [ErrorType.NAME, ErrorType.NAME],+ [ErrorType.NAME, ErrorType.NAME],+ [ErrorType.NAME, ErrorType.NAME],+ ]);++ const array3 = NullValueObject.create();+ const result5 = testFunction.calculate(array3, rows, columns);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);++ const result6 = testFunction.calculate(array3, rows3, columns3);+ expect(getObjectValue(result6)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ ]);++ const result7 = testFunction.calculate(array2, rows, columns);+ expect(getObjectValue(result7)).toStrictEqual(1);+ });++ it('Rows value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NullValueObject.create();+ const columns = NumberValueObject.create(2);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2, ErrorType.NA],+ ]);+ });++ it('Rows value test2', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = BooleanValueObject.create(true);+ const columns = NumberValueObject.create(2);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2, ErrorType.NA],+ ]);+ });++ it('Rows value test3', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = BooleanValueObject.create(false);+ const columns = NumberValueObject.create(2);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Rows value test4', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = StringValueObject.create('test');+ const columns = NumberValueObject.create(2);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Rows value test5', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = ErrorValueObject.create(ErrorType.NAME);+ const columns = NumberValueObject.create(2);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Rows value test6', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = ArrayValueObject.create('{1,2}');+ const columns = NumberValueObject.create(2);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2, 2],+ ]);+ });++ it('Columns value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(2);+ const columns = NullValueObject.create();+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2],+ [ErrorType.NA],+ ]);+ });++ it('Columns value test2', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(2);+ const columns = BooleanValueObject.create(true);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2],+ [ErrorType.NA],+ ]);+ });++ it('Columns value test3', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(2);+ const columns = BooleanValueObject.create(false);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Columns value test4', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(2);+ const columns = StringValueObject.create('test');+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Columns value test5', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(2);+ const columns = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Columns value test6', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(2);+ const columns = ArrayValueObject.create('{1,2}');+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2, 2],+ ]);+ });++ it('PadWith value test6', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(3);+ const columns = NumberValueObject.create(3);+ const padWith = ArrayValueObject.create('{"a","b"}');+ const result = testFunction.calculate(array, rows, columns, padWith);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);++ const padWith2 = ArrayValueObject.create('{"a"}');+ const result2 = testFunction.calculate(array, rows, columns, padWith2);+ expect(getObjectValue(result2)).toStrictEqual([+ [2, 2, 'a'],+ [2, 2, 'a'],+ ['a', 'a', 'a'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/lookup/expand/index.ts b/packages/engine-formula/src/functions/lookup/expand/index.tsnew file mode 100644index 0000000000..94021444e4--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/expand/index.ts@@ -0,0 +1,210 @@+/**+ * 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 { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Expand extends BaseFunction {+ override minParams = 2;++ override maxParams = 4;++ override calculate(array: BaseValueObject, rows: BaseValueObject, columns?: BaseValueObject, padWith?: BaseValueObject): BaseValueObject {+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;++ let _rows = rows;+ let _columns = columns ?? NumberValueObject.create(arrayColumnCount);+ const _padWith = padWith ?? ErrorValueObject.create(ErrorType.NA);++ if (rows.isNull()) {+ _rows = NumberValueObject.create(arrayRowCount);+ }++ if (_columns.isNull()) {+ _columns = NumberValueObject.create(arrayColumnCount);+ }++ const maxRowLength = Math.max(+ _rows.isArray() ? (_rows as ArrayValueObject).getRowCount() : 1,+ _columns.isArray() ? (_columns as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ _rows.isArray() ? (_rows as ArrayValueObject).getColumnCount() : 1,+ _columns.isArray() ? (_columns as ArrayValueObject).getColumnCount() : 1+ );++ const rowsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _rows, ErrorValueObject.create(ErrorType.NA));+ const columnsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _columns, ErrorValueObject.create(ErrorType.NA));++ if (maxRowLength > 1 || maxColumnLength > 1) {+ return rowsArray.mapValue((rowsObject, rowIndex, columnIndex) => {+ const columnsObject = columnsArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (array.isError()) {+ return array;+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const { isError, errorObject } = this._checkRowsColumnsPadWith(rowsObject, columnsObject, _padWith, arrayRowCount, arrayColumnCount);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ if (array.isArray()) {+ return (array as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return array;+ });+ }++ if (array.isError()) {+ return array;+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const rowsObject = _rows.isArray() ? (_rows as ArrayValueObject).get(0, 0) as BaseValueObject : _rows;+ const columnsObject = _columns.isArray() ? (_columns as ArrayValueObject).get(0, 0) as BaseValueObject : _columns;++ const { isError, errorObject, rowsValue, columnsValue, padWithObject } = this._checkRowsColumnsPadWith(rowsObject, columnsObject, _padWith, arrayRowCount, arrayColumnCount);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ return this._getResultArray(array, rowsValue as number, columnsValue as number, padWithObject as BaseValueObject, arrayRowCount, arrayColumnCount);+ }++ private _checkRowsColumnsPadWith(+ rowsObject: BaseValueObject,+ columnsObject: BaseValueObject,+ padWith: BaseValueObject,+ arrayRowCount: number,+ arrayColumnCount: number+ ) {+ if (rowsObject.isError()) {+ return {+ isError: true,+ errorObject: rowsObject as ErrorValueObject,+ };+ }++ if (columnsObject.isError()) {+ return {+ isError: true,+ errorObject: columnsObject as ErrorValueObject,+ };+ }++ const rowsValue = Math.trunc(+rowsObject.getValue());+ const columnsValue = Math.trunc(+columnsObject.getValue());++ if (Number.isNaN(rowsValue) || Number.isNaN(columnsValue)) {+ return {+ isError: true,+ errorObject: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ if (Math.abs(rowsValue) < arrayRowCount || Math.abs(columnsValue) < arrayColumnCount) {+ return {+ isError: true,+ errorObject: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ let _padWith = padWith;++ if (padWith.isArray()) {+ const rowCount = (padWith as ArrayValueObject).getRowCount();+ const columnCount = (padWith as ArrayValueObject).getColumnCount();++ if (rowCount > 1 || columnCount > 1) {+ return {+ isError: true,+ errorObject: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ _padWith = (padWith as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return {+ isError: false,+ rowsValue,+ columnsValue,+ padWithObject: _padWith,+ };+ }++ private _getResultArray(+ array: BaseValueObject,+ rows: number,+ columns: number,+ padWith: BaseValueObject,+ arrayRowCount: number,+ arrayColumnCount: number+ ): BaseValueObject {+ let resultArray: BaseValueObject[][] = [];++ if (array.isArray()) {+ resultArray = (array as ArrayValueObject).map((valueObject) => valueObject.isNull() ? NumberValueObject.create(0) : valueObject).getArrayValue() as BaseValueObject[][];+ } else {+ resultArray = [[array]];+ }++ const addRows = Math.max(0, rows - arrayRowCount);+ const addColumns = Math.max(0, columns - arrayColumnCount);++ for (let r = 0; r < addRows; r++) {+ resultArray.push(new Array(arrayColumnCount).fill(padWith));+ }++ for (let c = 0; c < addColumns; c++) {+ resultArray.forEach((row) => {+ row.push(padWith);+ });+ }++ if (rows === 1 && columns === 1) {+ return resultArray[0][0];+ }++ return ArrayValueObject.create({+ calculateValueList: resultArray,+ rowCount: resultArray.length,+ columnCount: resultArray[0].length,+ 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.tsindex 295946f3df..3edf6d1ecb 100644--- a/packages/engine-formula/src/functions/lookup/function-map.ts+++ b/packages/engine-formula/src/functions/lookup/function-map.ts@@ -22,6 +22,8 @@ import { Choosecols } from './choosecols';import { Chooserows } from './chooserows';import { Column } from './column';import { Columns } from './columns';+import { Drop } from './drop';+import { Expand } from './expand';import { Filter } from './filter';import { Hlookup } from './hlookup';import { Hstack } from './hstack';@@ -33,10 +35,15 @@ import { Row } from './row';import { Rows } from './rows';import { Sort } from './sort';import { Sortby } from './sortby';+import { Take } from './take';+import { Tocol } from './tocol';+import { Torow } from './torow';import { Transpose } from './transpose';import { Unique } from './unique';import { Vlookup } from './vlookup';import { Vstack } from './vstack';+import { Wrapcols } from './wrapcols';+import { Wraprows } from './wraprows';import { Xlookup } from './xlookup';import { Xmatch } from './xmatch';import { Index } from './index';@@ -49,6 +56,8 @@ export const functionLookup = [[Chooserows, FUNCTION_NAMES_LOOKUP.CHOOSEROWS],[Column, FUNCTION_NAMES_LOOKUP.COLUMN],[Columns, FUNCTION_NAMES_LOOKUP.COLUMNS],+ [Drop, FUNCTION_NAMES_LOOKUP.DROP],+ [Expand, FUNCTION_NAMES_LOOKUP.EXPAND],[Filter, FUNCTION_NAMES_LOOKUP.FILTER],[Hlookup, FUNCTION_NAMES_LOOKUP.HLOOKUP],[Hstack, FUNCTION_NAMES_LOOKUP.HSTACK],@@ -61,10 +70,15 @@ export const functionLookup = [[Rows, FUNCTION_NAMES_LOOKUP.ROWS],[Sort, FUNCTION_NAMES_LOOKUP.SORT],[Sortby, FUNCTION_NAMES_LOOKUP.SORTBY],+ [Take, FUNCTION_NAMES_LOOKUP.TAKE],+ [Tocol, FUNCTION_NAMES_LOOKUP.TOCOL],+ [Torow, FUNCTION_NAMES_LOOKUP.TOROW],[Transpose, FUNCTION_NAMES_LOOKUP.TRANSPOSE],[Unique, FUNCTION_NAMES_LOOKUP.UNIQUE],[Vlookup, FUNCTION_NAMES_LOOKUP.VLOOKUP],[Vstack, FUNCTION_NAMES_LOOKUP.VSTACK],+ [Wrapcols, FUNCTION_NAMES_LOOKUP.WRAPCOLS],+ [Wraprows, FUNCTION_NAMES_LOOKUP.WRAPROWS],[Xlookup, FUNCTION_NAMES_LOOKUP.XLOOKUP],[Xmatch, FUNCTION_NAMES_LOOKUP.XMATCH],];diff --git a/packages/engine-formula/src/functions/lookup/take/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/take/__tests__/index.spec.tsnew file mode 100644index 0000000000..1c3cc3b3f9--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/take/__tests__/index.spec.ts@@ -0,0 +1,339 @@+/**+ * 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 { Take } 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 take function', () => {+ const testFunction = new Take(FUNCTION_NAMES_LOOKUP.TAKE);++ describe('Take', () => {+ 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 rows = NumberValueObject.create(1);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(2);++ const rows2 = NumberValueObject.create(4);+ const columns2 = NumberValueObject.create(4);+ const result2 = testFunction.calculate(array, rows2, columns2);+ expect(getObjectValue(result2)).toStrictEqual([+ [2, 2],+ [2, 2],+ ]);+ });++ it('Array value test', async () => {+ const array = ErrorValueObject.create(ErrorType.NAME);+ const rows = NumberValueObject.create(1);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const rows2 = NumberValueObject.create(0);+ const columns2 = NumberValueObject.create(0);+ const result2 = testFunction.calculate(array, rows2, columns2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const array2 = NumberValueObject.create(1);+ const rows3 = ArrayValueObject.create('{1;0;0}');+ const columns3 = ArrayValueObject.create('{1,0}');+ const result3 = testFunction.calculate(array2, rows3, columns3);+ expect(getObjectValue(result3)).toStrictEqual([+ [1, ErrorType.CALC],+ [ErrorType.CALC, ErrorType.CALC],+ [ErrorType.CALC, ErrorType.CALC],+ ]);++ const result4 = testFunction.calculate(array, rows3, columns3);+ expect(getObjectValue(result4)).toStrictEqual([+ [ErrorType.NAME, ErrorType.NAME],+ [ErrorType.NAME, ErrorType.NAME],+ [ErrorType.NAME, ErrorType.NAME],+ ]);++ const array3 = NullValueObject.create();+ const result5 = testFunction.calculate(array3, rows, columns);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);++ const result6 = testFunction.calculate(array3, rows3, columns3);+ expect(getObjectValue(result6)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, ErrorType.VALUE],+ ]);++ const result7 = testFunction.calculate(array2, rows, columns);+ expect(getObjectValue(result7)).toStrictEqual(1);+ });++ it('Rows value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NullValueObject.create();+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2],+ [2],+ ]);+ });++ it('Rows value test2', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = BooleanValueObject.create(true);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(2);+ });++ it('Rows value test3', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = BooleanValueObject.create(false);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.CALC);+ });++ it('Rows value test4', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = StringValueObject.create('test');+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Rows value test5', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = ErrorValueObject.create(ErrorType.NAME);+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Rows value test6', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = ArrayValueObject.create('{1,2}');+ const columns = NumberValueObject.create(1);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.VALUE],+ ]);+ });++ it('Columns value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = NullValueObject.create();+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [2, 2],+ ]);+ });++ it('Columns value test2', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = BooleanValueObject.create(true);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(2);+ });++ it('Columns value test3', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = BooleanValueObject.create(false);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.CALC);+ });++ it('Columns value test4', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = StringValueObject.create('test');+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Columns value test5', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Columns value test6', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2, 2],+ [2, 2],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const rows = NumberValueObject.create(1);+ const columns = ArrayValueObject.create('{1,2}');+ const result = testFunction.calculate(array, rows, columns);+ expect(getObjectValue(result)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.VALUE],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/lookup/take/index.ts b/packages/engine-formula/src/functions/lookup/take/index.tsnew file mode 100644index 0000000000..9059682926--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/take/index.ts@@ -0,0 +1,179 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Take extends BaseFunction {+ override minParams = 2;++ override maxParams = 3;++ override calculate(array: BaseValueObject, rows: BaseValueObject, columns?: BaseValueObject): BaseValueObject {+ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;++ let _rows = rows;+ let _columns = columns ?? NumberValueObject.create(arrayColumnCount);++ if (rows.isNull()) {+ _rows = NumberValueObject.create(arrayRowCount);+ }++ if (_columns.isNull()) {+ _columns = NumberValueObject.create(arrayColumnCount);+ }++ const maxRowLength = Math.max(+ _rows.isArray() ? (_rows as ArrayValueObject).getRowCount() : 1,+ _columns.isArray() ? (_columns as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ _rows.isArray() ? (_rows as ArrayValueObject).getColumnCount() : 1,+ _columns.isArray() ? (_columns as ArrayValueObject).getColumnCount() : 1+ );++ const rowsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _rows, ErrorValueObject.create(ErrorType.NA));+ const columnsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _columns, ErrorValueObject.create(ErrorType.NA));++ if (maxRowLength > 1 || maxColumnLength > 1) {+ return rowsArray.mapValue((rowsObject, rowIndex, columnIndex) => {+ const columnsObject = columnsArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (array.isError()) {+ return array;+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const { isError, errorObject } = this._checkRowsColumns(rowsObject, columnsObject, arrayRowCount, arrayColumnCount);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ if (array.isArray()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return array;+ });+ }++ if (array.isError()) {+ return array;+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const rowsObject = _rows.isArray() ? (_rows as ArrayValueObject).get(0, 0) as BaseValueObject : _rows;+ const columnsObject = _columns.isArray() ? (_columns as ArrayValueObject).get(0, 0) as BaseValueObject : _columns;++ const { isError, errorObject, rowsValue, columnsValue } = this._checkRowsColumns(rowsObject, columnsObject, arrayRowCount, arrayColumnCount);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ return this._getResultArray(array, rowsValue as number, columnsValue as number, arrayRowCount, arrayColumnCount);+ }++ private _checkRowsColumns(rowsObject: BaseValueObject, columnsObject: BaseValueObject, arrayRowCount: number, arrayColumnCount: number) {+ if (rowsObject.isError()) {+ return {+ isError: true,+ errorObject: rowsObject as ErrorValueObject,+ };+ }++ if (columnsObject.isError()) {+ return {+ isError: true,+ errorObject: columnsObject as ErrorValueObject,+ };+ }++ let rowsValue = Math.trunc(+rowsObject.getValue());+ let columnsValue = Math.trunc(+columnsObject.getValue());++ if (Number.isNaN(rowsValue) || Number.isNaN(columnsValue)) {+ return {+ isError: true,+ errorObject: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ if (Math.abs(rowsValue) === 0 || Math.abs(columnsValue) === 0) {+ return {+ isError: true,+ errorObject: ErrorValueObject.create(ErrorType.CALC),+ };+ }++ if (rowsValue > arrayRowCount) {+ rowsValue = arrayRowCount;+ }++ if (columnsValue > arrayColumnCount) {+ columnsValue = arrayColumnCount;+ }++ return {+ isError: false,+ rowsValue,+ columnsValue,+ };+ }++ private _getResultArray(array: BaseValueObject, rows: number, columns: number, arrayRowCount: number, arrayColumnCount: number): BaseValueObject {+ if (!array.isArray()) {+ return array;+ }++ const rowParam = rows >= 0 ? [0, rows] : [arrayRowCount + rows, arrayRowCount];+ const columnParam = columns >= 0 ? [0, columns] : [arrayColumnCount + columns, arrayColumnCount];++ let resultArray: ArrayValueObject;++ if ((rows === arrayRowCount && columns === arrayColumnCount)) {+ resultArray = array as ArrayValueObject;+ } else if (rows === arrayRowCount) {+ resultArray = (array as ArrayValueObject).slice(undefined, columnParam) as ArrayValueObject;+ } else if (columns === arrayColumnCount) {+ resultArray = (array as ArrayValueObject).slice(rowParam, undefined) as ArrayValueObject;+ } else {+ resultArray = (array as ArrayValueObject).slice(rowParam, columnParam) as ArrayValueObject;+ }++ resultArray = resultArray.map((valueObject) => valueObject.isNull() ? NumberValueObject.create(0) : valueObject) as ArrayValueObject;++ if (rows === 1 && columns === 1) {+ return resultArray.get(0, 0) as BaseValueObject;+ }++ return resultArray;+ };+}diff --git a/packages/engine-formula/src/functions/lookup/tocol/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/tocol/__tests__/index.spec.tsnew file mode 100644index 0000000000..65599461bf--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/tocol/__tests__/index.spec.ts@@ -0,0 +1,210 @@+/**+ * 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 { Tocol } from '../index';+import { 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 tocol function', () => {+ const testFunction = new Tocol(FUNCTION_NAMES_LOOKUP.TOCOL);++ describe('Tocol', () => {+ it('Value is normal', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ [true, ErrorType.NAME, null, 'James'],+ [false, 'Harry', 1.23, '彭德威'],+ ]),+ rowCount: 3,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const ignore = NumberValueObject.create(3);+ const scanByColumn = NumberValueObject.create(0);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben'],+ [1],+ ['Mary'],+ [-2],+ [true],+ ['James'],+ [false],+ ['Harry'],+ [1.23],+ ['彭德威'],+ ]);+ });++ it('Array value test', async () => {+ const array = ErrorValueObject.create(ErrorType.NAME);+ const ignore = NumberValueObject.create(3);+ const scanByColumn = NumberValueObject.create(0);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const array2 = NullValueObject.create();+ const result2 = testFunction.calculate(array2, ignore, scanByColumn);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const array3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(array3, ignore, scanByColumn);+ expect(getObjectValue(result3)).toStrictEqual('test');++ const array4 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [ErrorType.NAME, null],+ ]),+ rowCount: 1,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result4 = testFunction.calculate(array4, ignore, scanByColumn);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.CALC);+ });++ it('Ignore value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ [true, ErrorType.NAME, null, 'James'],+ [false, 'Harry', 1.23, '彭德威'],+ ]),+ rowCount: 3,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const ignore = NumberValueObject.create(0);+ const scanByColumn = NumberValueObject.create(0);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben'],+ [1],+ ['Mary'],+ [-2],+ [true],+ [ErrorType.NAME],+ [0],+ ['James'],+ [false],+ ['Harry'],+ [1.23],+ ['彭德威'],+ ]);++ const ignore2 = NumberValueObject.create(1);+ const result2 = testFunction.calculate(array, ignore2, scanByColumn);+ expect(getObjectValue(result2)).toStrictEqual([+ ['Ben'],+ [1],+ ['Mary'],+ [-2],+ [true],+ [ErrorType.NAME],+ ['James'],+ [false],+ ['Harry'],+ [1.23],+ ['彭德威'],+ ]);++ const ignore3 = NumberValueObject.create(2);+ const result3 = testFunction.calculate(array, ignore3, scanByColumn);+ expect(getObjectValue(result3)).toStrictEqual([+ ['Ben'],+ [1],+ ['Mary'],+ [-2],+ [true],+ [0],+ ['James'],+ [false],+ ['Harry'],+ [1.23],+ ['彭德威'],+ ]);++ const ignore4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(array, ignore4, scanByColumn);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);++ const ignore5 = StringValueObject.create('test');+ const result5 = testFunction.calculate(array, ignore5, scanByColumn);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);+ });++ it('ScanByColumn value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ [true, ErrorType.NAME, null, 'James'],+ [false, 'Harry', 1.23, '彭德威'],+ ]),+ rowCount: 3,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const ignore = NumberValueObject.create(3);+ const scanByColumn = NumberValueObject.create(1);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben'],+ [true],+ [false],+ [1],+ ['Harry'],+ ['Mary'],+ [1.23],+ [-2],+ ['James'],+ ['彭德威'],+ ]);++ const scanByColumn2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(array, ignore, scanByColumn2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const scanByColumn3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(array, ignore, scanByColumn3);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);++ const scanByColumn4 = ArrayValueObject.create('{1,0,-1}');+ const result4 = testFunction.calculate(array, ignore, scanByColumn4);+ expect(getObjectValue(result4)).toStrictEqual([+ ['Ben', 'Ben', 'Ben'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/lookup/tocol/index.ts b/packages/engine-formula/src/functions/lookup/tocol/index.tsnew file mode 100644index 0000000000..616af14be2--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/tocol/index.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 { ErrorType } from '../../../basics/error-type';+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BooleanValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Tocol extends BaseFunction {+ override minParams = 1;++ override maxParams = 3;++ override calculate(array: BaseValueObject, ignore?: BaseValueObject, scanByColumn?: BaseValueObject): BaseValueObject {+ const _ignore = ignore ?? NumberValueObject.create(0);+ const _scanByColumn = scanByColumn ?? BooleanValueObject.create(false);++ const maxRowLength = Math.max(+ _ignore.isArray() ? (_ignore as ArrayValueObject).getRowCount() : 1,+ _scanByColumn.isArray() ? (_scanByColumn as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ _ignore.isArray() ? (_ignore as ArrayValueObject).getColumnCount() : 1,+ _scanByColumn.isArray() ? (_scanByColumn as ArrayValueObject).getColumnCount() : 1+ );++ const ignoreArray = expandArrayValueObject(maxRowLength, maxColumnLength, _ignore, ErrorValueObject.create(ErrorType.NA));+ const scanByColumnArray = expandArrayValueObject(maxRowLength, maxColumnLength, _scanByColumn, ErrorValueObject.create(ErrorType.NA));++ const resultArray = ignoreArray.mapValue((ignoreObject, rowIndex, columnIndex) => {+ const scanByColumnObject = scanByColumnArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (array.isError()) {+ return array;+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (ignoreObject.isError()) {+ return ignoreObject;+ }++ if (scanByColumnObject.isError()) {+ return scanByColumnObject;+ }++ const ignoreValue = Math.trunc(+ignoreObject.getValue());+ const scanByColumnValue = +scanByColumnObject.getValue();++ if (Number.isNaN(ignoreValue) || ignoreValue < 0 || ignoreValue > 3 || Number.isNaN(scanByColumnValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (!array.isArray()) {+ return array;+ }++ let result: BaseValueObject[] = [];++ if (scanByColumnValue) {+ result = this._getArrayValueByColumn(array, ignoreValue);+ } else {+ result = this._getArrayValueByRow(array, ignoreValue);+ }++ if (result.length === 0) {+ return ErrorValueObject.create(ErrorType.CALC);+ }++ if (maxRowLength > 1 || maxColumnLength > 1 || result.length === 1) {+ return result[0];+ }++ return ArrayValueObject.create({+ calculateValueList: result.map((valueObject) => [valueObject]),+ rowCount: result.length,+ columnCount: 1,+ unitId: this.unitId as string,+ sheetId: this.subUnitId as string,+ row: this.row,+ column: this.column,+ });+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _getArrayValueByColumn(array: BaseValueObject, ignore: number): BaseValueObject[] {+ const _array = array as ArrayValueObject;+ const arrayRowCount = _array.getRowCount();+ const arrayColumnCount = _array.getColumnCount();++ const result: BaseValueObject[] = [];++ for (let c = 0; c < arrayColumnCount; c++) {+ for (let r = 0; r < arrayRowCount; r++) {+ const valueObject = _array.get(r, c) as BaseValueObject;++ if (!this._isIgnore(valueObject, ignore)) {+ result.push(valueObject.isNull() ? NumberValueObject.create(0) : valueObject);+ }+ }+ }++ return result;+ }++ private _getArrayValueByRow(array: BaseValueObject, ignore: number): BaseValueObject[] {+ const _array = array as ArrayValueObject;+ const arrayRowCount = _array.getRowCount();+ const arrayColumnCount = _array.getColumnCount();++ const result: BaseValueObject[] = [];++ for (let r = 0; r < arrayRowCount; r++) {+ for (let c = 0; c < arrayColumnCount; c++) {+ const valueObject = _array.get(r, c) as BaseValueObject;++ if (!this._isIgnore(valueObject, ignore)) {+ result.push(valueObject.isNull() ? NumberValueObject.create(0) : valueObject);+ }+ }+ }++ return result;+ }++ private _isIgnore(valueObject: BaseValueObject, ignore: number): boolean {+ switch (ignore) {+ case 0:+ return false;+ case 1:+ return valueObject.isNull();+ case 2:+ return valueObject.isError();+ case 3:+ return valueObject.isNull() || valueObject.isError();+ default:+ return false;+ }+ }+}diff --git a/packages/engine-formula/src/functions/lookup/torow/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/torow/__tests__/index.spec.tsnew file mode 100644index 0000000000..ee2ea73fc0--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/torow/__tests__/index.spec.ts@@ -0,0 +1,161 @@+/**+ * 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 { Torow } from '../index';+import { 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 torow function', () => {+ const testFunction = new Torow(FUNCTION_NAMES_LOOKUP.TOROW);++ describe('Torow', () => {+ it('Value is normal', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ [true, ErrorType.NAME, null, 'James'],+ [false, 'Harry', 1.23, '彭德威'],+ ]),+ rowCount: 3,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const ignore = NumberValueObject.create(3);+ const scanByColumn = NumberValueObject.create(0);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben', 1, 'Mary', -2, true, 'James', false, 'Harry', 1.23, '彭德威'],+ ]);+ });++ it('Array value test', async () => {+ const array = ErrorValueObject.create(ErrorType.NAME);+ const ignore = NumberValueObject.create(3);+ const scanByColumn = NumberValueObject.create(0);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const array2 = NullValueObject.create();+ const result2 = testFunction.calculate(array2, ignore, scanByColumn);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const array3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(array3, ignore, scanByColumn);+ expect(getObjectValue(result3)).toStrictEqual('test');++ const array4 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [ErrorType.NAME, null],+ ]),+ rowCount: 1,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result4 = testFunction.calculate(array4, ignore, scanByColumn);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.CALC);+ });++ it('Ignore value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ [true, ErrorType.NAME, null, 'James'],+ [false, 'Harry', 1.23, '彭德威'],+ ]),+ rowCount: 3,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const ignore = NumberValueObject.create(0);+ const scanByColumn = NumberValueObject.create(0);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben', 1, 'Mary', -2, true, ErrorType.NAME, 0, 'James', false, 'Harry', 1.23, '彭德威'],+ ]);++ const ignore2 = NumberValueObject.create(1);+ const result2 = testFunction.calculate(array, ignore2, scanByColumn);+ expect(getObjectValue(result2)).toStrictEqual([+ ['Ben', 1, 'Mary', -2, true, ErrorType.NAME, 'James', false, 'Harry', 1.23, '彭德威'],+ ]);++ const ignore3 = NumberValueObject.create(2);+ const result3 = testFunction.calculate(array, ignore3, scanByColumn);+ expect(getObjectValue(result3)).toStrictEqual([+ ['Ben', 1, 'Mary', -2, true, 0, 'James', false, 'Harry', 1.23, '彭德威'],+ ]);++ const ignore4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(array, ignore4, scanByColumn);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);++ const ignore5 = StringValueObject.create('test');+ const result5 = testFunction.calculate(array, ignore5, scanByColumn);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);+ });++ it('ScanByColumn value test', async () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ [true, ErrorType.NAME, null, 'James'],+ [false, 'Harry', 1.23, '彭德威'],+ ]),+ rowCount: 3,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const ignore = NumberValueObject.create(3);+ const scanByColumn = NumberValueObject.create(1);+ const result = testFunction.calculate(array, ignore, scanByColumn);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben', true, false, 1, 'Harry', 'Mary', 1.23, -2, 'James', '彭德威'],+ ]);++ const scanByColumn2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(array, ignore, scanByColumn2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const scanByColumn3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(array, ignore, scanByColumn3);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);++ const scanByColumn4 = ArrayValueObject.create('{1,0,-1}');+ const result4 = testFunction.calculate(array, ignore, scanByColumn4);+ expect(getObjectValue(result4)).toStrictEqual([+ ['Ben', 'Ben', 'Ben'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/lookup/torow/index.ts b/packages/engine-formula/src/functions/lookup/torow/index.tsnew file mode 100644index 0000000000..7b1123eeb3--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/torow/index.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 { ErrorType } from '../../../basics/error-type';+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BooleanValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Torow extends BaseFunction {+ override minParams = 1;++ override maxParams = 3;++ override calculate(array: BaseValueObject, ignore?: BaseValueObject, scanByColumn?: BaseValueObject): BaseValueObject {+ const _ignore = ignore ?? NumberValueObject.create(0);+ const _scanByColumn = scanByColumn ?? BooleanValueObject.create(false);++ const maxRowLength = Math.max(+ _ignore.isArray() ? (_ignore as ArrayValueObject).getRowCount() : 1,+ _scanByColumn.isArray() ? (_scanByColumn as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ _ignore.isArray() ? (_ignore as ArrayValueObject).getColumnCount() : 1,+ _scanByColumn.isArray() ? (_scanByColumn as ArrayValueObject).getColumnCount() : 1+ );++ const ignoreArray = expandArrayValueObject(maxRowLength, maxColumnLength, _ignore, ErrorValueObject.create(ErrorType.NA));+ const scanByColumnArray = expandArrayValueObject(maxRowLength, maxColumnLength, _scanByColumn, ErrorValueObject.create(ErrorType.NA));++ const resultArray = ignoreArray.mapValue((ignoreObject, rowIndex, columnIndex) => {+ const scanByColumnObject = scanByColumnArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (array.isError()) {+ return array;+ }++ if (ignoreObject.isError()) {+ return ignoreObject;+ }++ if (scanByColumnObject.isError()) {+ return scanByColumnObject;+ }++ const ignoreValue = Math.trunc(+ignoreObject.getValue());+ const scanByColumnValue = +scanByColumnObject.getValue();++ if (Number.isNaN(ignoreValue) || ignoreValue < 0 || ignoreValue > 3 || Number.isNaN(scanByColumnValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (array.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (!array.isArray()) {+ return array;+ }++ let result: BaseValueObject[] = [];++ if (scanByColumnValue) {+ result = this._getArrayValueByColumn(array, ignoreValue);+ } else {+ result = this._getArrayValueByRow(array, ignoreValue);+ }++ if (result.length === 0) {+ return ErrorValueObject.create(ErrorType.CALC);+ }++ if (maxRowLength > 1 || maxColumnLength > 1 || result.length === 1) {+ return result[0];+ }++ return ArrayValueObject.create({+ calculateValueList: [result],+ rowCount: 1,+ columnCount: result.length,+ unitId: this.unitId as string,+ sheetId: this.subUnitId as string,+ row: this.row,+ column: this.column,+ });+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _getArrayValueByColumn(array: BaseValueObject, ignore: number): BaseValueObject[] {+ const _array = array as ArrayValueObject;+ const arrayRowCount = _array.getRowCount();+ const arrayColumnCount = _array.getColumnCount();++ const result: BaseValueObject[] = [];++ for (let c = 0; c < arrayColumnCount; c++) {+ for (let r = 0; r < arrayRowCount; r++) {+ const valueObject = _array.get(r, c) as BaseValueObject;++ if (!this._isIgnore(valueObject, ignore)) {+ result.push(valueObject.isNull() ? NumberValueObject.create(0) : valueObject);+ }+ }+ }++ return result;+ }++ private _getArrayValueByRow(array: BaseValueObject, ignore: number): BaseValueObject[] {+ const _array = array as ArrayValueObject;+ const arrayRowCount = _array.getRowCount();+ const arrayColumnCount = _array.getColumnCount();++ const result: BaseValueObject[] = [];++ for (let r = 0; r < arrayRowCount; r++) {+ for (let c = 0; c < arrayColumnCount; c++) {+ const valueObject = _array.get(r, c) as BaseValueObject;++ if (!this._isIgnore(valueObject, ignore)) {+ result.push(valueObject.isNull() ? NumberValueObject.create(0) : valueObject);+ }+ }+ }++ return result;+ }++ private _isIgnore(valueObject: BaseValueObject, ignore: number): boolean {+ switch (ignore) {+ case 0:+ return false;+ case 1:+ return valueObject.isNull();+ case 2:+ return valueObject.isError();+ case 3:+ return valueObject.isNull() || valueObject.isError();+ default:+ return false;+ }+ }+}diff --git a/packages/engine-formula/src/functions/lookup/wrapcols/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/wrapcols/__tests__/index.spec.tsnew file mode 100644index 0000000000..7fb952d881--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/wrapcols/__tests__/index.spec.ts@@ -0,0 +1,139 @@+/**+ * 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 { Wrapcols } from '../index';+import { 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 wrapcols function', () => {+ const testFunction = new Wrapcols(FUNCTION_NAMES_LOOKUP.WRAPCOLS);++ describe('Wrapcols', () => {+ it('Value is normal', async () => {+ const vector = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ ]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const wrapCount = NumberValueObject.create(3);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben', -2],+ [1, ErrorType.NA],+ ['Mary', ErrorType.NA],+ ]);+ });++ it('Vector value test', async () => {+ const vector = ErrorValueObject.create(ErrorType.NAME);+ const wrapCount = NumberValueObject.create(3);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const vector2 = NullValueObject.create();+ const result2 = testFunction.calculate(vector2, wrapCount, padWith);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const vector3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(vector3, wrapCount, padWith);+ expect(getObjectValue(result3)).toStrictEqual('test');+ });++ it('WrapCount value test', async () => {+ const vector = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ ]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const wrapCount = NumberValueObject.create(0);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NUM);++ const wrapCount2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(vector, wrapCount2, padWith);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const wrapCount3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(vector, wrapCount3, padWith);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);+ });++ it('PadWith value test', async () => {+ const vector = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ ]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const wrapCount = NumberValueObject.create(3);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben', -2],+ [1, ErrorType.NA],+ ['Mary', ErrorType.NA],+ ]);++ const padWith2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(vector, wrapCount, padWith2);+ expect(getObjectValue(result2)).toStrictEqual([+ ['Ben', -2],+ [1, ErrorType.NAME],+ ['Mary', ErrorType.NAME],+ ]);++ const padWith3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(vector, wrapCount, padWith3);+ expect(getObjectValue(result3)).toStrictEqual([+ ['Ben', -2],+ [1, 'test'],+ ['Mary', 'test'],+ ]);++ const padWith4 = ArrayValueObject.create('{"a", "b"}');+ const result4 = testFunction.calculate(vector, wrapCount, padWith4);+ expect(getObjectValue(result4)).toStrictEqual([+ ['Ben', 'Ben'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/lookup/wrapcols/index.ts b/packages/engine-formula/src/functions/lookup/wrapcols/index.tsnew file mode 100644index 0000000000..4317b50884--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/wrapcols/index.ts@@ -0,0 +1,131 @@+/**+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';++export class Wrapcols extends BaseFunction {+ override minParams = 2;++ override maxParams = 3;++ override calculate(vector: BaseValueObject, wrapCount: BaseValueObject, padWith?: BaseValueObject): BaseValueObject {+ let _padWith = padWith ?? ErrorValueObject.create(ErrorType.NA);++ if (_padWith.isNull()) {+ _padWith = ErrorValueObject.create(ErrorType.NA);+ }++ const vectorRowCount = vector.isArray() ? (vector as ArrayValueObject).getRowCount() : 1;+ const vectorColumnCount = vector.isArray() ? (vector as ArrayValueObject).getColumnCount() : 1;++ const maxRowLength = Math.max(+ wrapCount.isArray() ? (wrapCount as ArrayValueObject).getRowCount() : 1,+ _padWith.isArray() ? (_padWith as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ wrapCount.isArray() ? (wrapCount as ArrayValueObject).getColumnCount() : 1,+ _padWith.isArray() ? (_padWith as ArrayValueObject).getColumnCount() : 1+ );++ const wrapCountArray = expandArrayValueObject(maxRowLength, maxColumnLength, wrapCount, ErrorValueObject.create(ErrorType.NA));+ const padWithArray = expandArrayValueObject(maxRowLength, maxColumnLength, _padWith, ErrorValueObject.create(ErrorType.NA));++ const resultArray = wrapCountArray.mapValue((wrapCountObject, rowIndex, columnIndex) => {+ const padWithObject = padWithArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (vector.isError()) {+ return vector;+ }++ if (vector.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (wrapCountObject.isError()) {+ return wrapCountObject;+ }++ const wrapCountValue = Math.trunc(+wrapCountObject.getValue());++ if (+ (vectorRowCount > 1 && vectorColumnCount > 1) ||+ Number.isNaN(wrapCountValue)+ ) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (wrapCountValue < 1) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const vectorArray = vector.isArray() ? (vector as ArrayValueObject).getArrayValue().flat() : [vector];++ const result = this._getWrapArray(vectorArray as BaseValueObject[], wrapCountValue, padWithObject);++ if (maxRowLength > 1 || maxColumnLength > 1 || (result.length === 1 && result[0].length === 1)) {+ return result[0][0];+ }++ return ArrayValueObject.create({+ calculateValueList: result,+ rowCount: result.length,+ columnCount: result[0].length,+ unitId: this.unitId as string,+ sheetId: this.subUnitId as string,+ row: this.row,+ column: this.column,+ });+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _getWrapArray(vectorArray: BaseValueObject[], wrapCount: number, padWith: BaseValueObject): BaseValueObject[][] {+ const columns = Math.ceil(vectorArray.length / wrapCount);++ const _wrapCount = columns > 1 ? wrapCount : vectorArray.length;++ const result: BaseValueObject[][] = [];++ for (let c = 0; c < columns; c++) {+ for (let r = 0; r < _wrapCount; r++) {+ if (!result[r]) {+ result[r] = [];+ }++ const index = c * _wrapCount + r;++ if (index < vectorArray.length) {+ result[r].push(vectorArray[index].isNull() ? NumberValueObject.create(0) : vectorArray[index]);+ } else {+ result[r].push(padWith);+ }+ }+ }++ return result;+ }+}diff --git a/packages/engine-formula/src/functions/lookup/wraprows/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/wraprows/__tests__/index.spec.tsnew file mode 100644index 0000000000..14aea7a00f--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/wraprows/__tests__/index.spec.ts@@ -0,0 +1,135 @@+/**+ * 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 { Wraprows } from '../index';+import { 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 wraprows function', () => {+ const testFunction = new Wraprows(FUNCTION_NAMES_LOOKUP.WRAPROWS);++ describe('Wraprows', () => {+ it('Value is normal', async () => {+ const vector = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ ]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const wrapCount = NumberValueObject.create(3);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben', 1, 'Mary'],+ [-2, ErrorType.NA, ErrorType.NA],+ ]);+ });++ it('Vector value test', async () => {+ const vector = ErrorValueObject.create(ErrorType.NAME);+ const wrapCount = NumberValueObject.create(3);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const vector2 = NullValueObject.create();+ const result2 = testFunction.calculate(vector2, wrapCount, padWith);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const vector3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(vector3, wrapCount, padWith);+ expect(getObjectValue(result3)).toStrictEqual('test');+ });++ it('WrapCount value test', async () => {+ const vector = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ ]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const wrapCount = NumberValueObject.create(0);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NUM);++ const wrapCount2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(vector, wrapCount2, padWith);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const wrapCount3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(vector, wrapCount3, padWith);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);+ });++ it('PadWith value test', async () => {+ const vector = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['Ben', 1, 'Mary', -2],+ ]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const wrapCount = NumberValueObject.create(3);+ const padWith = NullValueObject.create();+ const result = testFunction.calculate(vector, wrapCount, padWith);+ expect(getObjectValue(result)).toStrictEqual([+ ['Ben', 1, 'Mary'],+ [-2, ErrorType.NA, ErrorType.NA],+ ]);++ const padWith2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(vector, wrapCount, padWith2);+ expect(getObjectValue(result2)).toStrictEqual([+ ['Ben', 1, 'Mary'],+ [-2, ErrorType.NAME, ErrorType.NAME],+ ]);++ const padWith3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(vector, wrapCount, padWith3);+ expect(getObjectValue(result3)).toStrictEqual([+ ['Ben', 1, 'Mary'],+ [-2, 'test', 'test'],+ ]);++ const padWith4 = ArrayValueObject.create('{"a", "b"}');+ const result4 = testFunction.calculate(vector, wrapCount, padWith4);+ expect(getObjectValue(result4)).toStrictEqual([+ ['Ben', 'Ben'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/lookup/wraprows/index.ts b/packages/engine-formula/src/functions/lookup/wraprows/index.tsnew file mode 100644index 0000000000..dda148eabd--- /dev/null+++ b/packages/engine-formula/src/functions/lookup/wraprows/index.ts@@ -0,0 +1,131 @@+/**+ * 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, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';++export class Wraprows extends BaseFunction {+ override minParams = 2;++ override maxParams = 3;++ override calculate(vector: BaseValueObject, wrapCount: BaseValueObject, padWith?: BaseValueObject): BaseValueObject {+ let _padWith = padWith ?? ErrorValueObject.create(ErrorType.NA);++ if (_padWith.isNull()) {+ _padWith = ErrorValueObject.create(ErrorType.NA);+ }++ const vectorRowCount = vector.isArray() ? (vector as ArrayValueObject).getRowCount() : 1;+ const vectorColumnCount = vector.isArray() ? (vector as ArrayValueObject).getColumnCount() : 1;++ const maxRowLength = Math.max(+ wrapCount.isArray() ? (wrapCount as ArrayValueObject).getRowCount() : 1,+ _padWith.isArray() ? (_padWith as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ wrapCount.isArray() ? (wrapCount as ArrayValueObject).getColumnCount() : 1,+ _padWith.isArray() ? (_padWith as ArrayValueObject).getColumnCount() : 1+ );++ const wrapCountArray = expandArrayValueObject(maxRowLength, maxColumnLength, wrapCount, ErrorValueObject.create(ErrorType.NA));+ const padWithArray = expandArrayValueObject(maxRowLength, maxColumnLength, _padWith, ErrorValueObject.create(ErrorType.NA));++ const resultArray = wrapCountArray.mapValue((wrapCountObject, rowIndex, columnIndex) => {+ const padWithObject = padWithArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (vector.isError()) {+ return vector;+ }++ if (vector.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (wrapCountObject.isError()) {+ return wrapCountObject;+ }++ const wrapCountValue = Math.trunc(+wrapCountObject.getValue());++ if (+ (vectorRowCount > 1 && vectorColumnCount > 1) ||+ Number.isNaN(wrapCountValue)+ ) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (wrapCountValue < 1) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const vectorArray = vector.isArray() ? (vector as ArrayValueObject).getArrayValue().flat() : [vector];++ const result = this._getWrapArray(vectorArray as BaseValueObject[], wrapCountValue, padWithObject);++ if (maxRowLength > 1 || maxColumnLength > 1 || (result.length === 1 && result[0].length === 1)) {+ return result[0][0];+ }++ return ArrayValueObject.create({+ calculateValueList: result,+ rowCount: result.length,+ columnCount: result[0].length,+ unitId: this.unitId as string,+ sheetId: this.subUnitId as string,+ row: this.row,+ column: this.column,+ });+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _getWrapArray(vectorArray: BaseValueObject[], wrapCount: number, padWith: BaseValueObject): BaseValueObject[][] {+ const rows = Math.ceil(vectorArray.length / wrapCount);++ const _wrapCount = rows > 1 ? wrapCount : vectorArray.length;++ const result: BaseValueObject[][] = [];++ for (let r = 0; r < rows; r++) {+ const row = [];++ for (let c = 0; c < _wrapCount; c++) {+ const index = r * _wrapCount + c;++ if (index < vectorArray.length) {+ row.push(vectorArray[index].isNull() ? NumberValueObject.create(0) : vectorArray[index]);+ } else {+ row.push(padWith);+ }+ }++ result.push(row);+ }++ return result;+ }+}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.tsindex 7181a8a90f..ed4c4053a3 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@@ -143,8 +143,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: 'array', detail: 'The array from which to drop rows or columns.' },+ rows: { name: 'rows', detail: 'The number of rows to drop. A negative value drops from the end of the array.' },+ columns: { name: 'columns', detail: 'The number of columns to exclude. A negative value drops from the end of the array.' },},},EXPAND: {@@ -157,8 +158,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: 'array', detail: 'The array to expand.' },+ rows: { name: 'rows', detail: 'The number of rows in the expanded array. If missing, rows will not be expanded.' },+ columns: { name: 'columns', detail: 'The number of columns in the expanded array. If missing, columns will not be expanded.' },+ padWith: { name: 'pad_with', detail: 'The value with which to pad. The default is #N/A.' },},},FILTER: {@@ -443,8 +446,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: 'array', detail: 'The array from which to take rows or columns.' },+ rows: { name: 'rows', detail: 'The number of rows to take. A negative value takes from the end of the array.' },+ columns: { name: 'columns', detail: 'The number of columns to take. A negative value takes from the end of the array.' },},},TOCOL: {@@ -457,8 +461,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: 'array', detail: 'The array or reference to return as a column.' },+ ignore: { name: 'ignore', detail: 'Whether to ignore certain types of values. By default, no values are ignored. Specify one of the following:\n0 Keep all values (default)\n1 Ignore blanks\n2 Ignore errors\n3 Ignore blanks and errors' },+ scanByColumn: { name: 'scan_by_column', detail: 'Scan the array by column. By default, the array is scanned by row. Scanning determines whether the values are ordered by row or by column.' },},},TOROW: {@@ -471,8 +476,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: 'array', detail: 'The array or reference to return as a row.' },+ ignore: { name: 'ignore', detail: 'Whether to ignore certain types of values. By default, no values are ignored. Specify one of the following:\n0 Keep all values (default)\n1 Ignore blanks\n2 Ignore errors\n3 Ignore blanks and errors' },+ scanByColumn: { name: 'scan_by_column', detail: 'Scan the array by column. By default, the array is scanned by row. Scanning determines whether the values are ordered by row or by column.' },},},TRANSPOSE: {@@ -555,8 +561,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: 'vector', detail: 'The vector or reference to wrap.' },+ wrapCount: { name: 'wrap_count', detail: 'The maximum number of values for each column.' },+ padWith: { name: 'pad_with', detail: 'The value with which to pad. The default is #N/A.' },},},WRAPROWS: {@@ -569,8 +576,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: 'vector', detail: 'The vector or reference to wrap.' },+ wrapCount: { name: 'wrap_count', detail: 'The maximum number of values for each row.' },+ padWith: { name: 'pad_with', detail: 'The value with which to pad. The default is #N/A.' },},},XLOOKUP: {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.tsindex 382f74590b..685f7e1a6e 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@@ -123,8 +123,8 @@ export default {},},DROP: {- description: '配列の先頭または末尾から指定した数の行または列を除外します',- abstract: '配列の先頭または末尾から指定した数の行または列を除外します',+ description: '配列の先頭または末尾から指定した数の行または列を削除します',+ abstract: '配列の先頭または末尾から指定した数の行または列を削除します',links: [{title: '指導',@@ -132,8 +132,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '配列', detail: '行または列を削除する配列。' },+ rows: { name: '行の数', detail: '削除する行の数。 負の値は配列の末尾から削除されます。' },+ columns: { name: '列の数', detail: '削除する列の数。 負の値は配列の末尾から削除されます。' },},},EXPAND: {@@ -146,8 +147,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '配列', detail: '展開する配列。' },+ rows: { name: '行の数', detail: '展開された配列内の行数。 存在しない場合、行は展開されません。' },+ columns: { name: '列の数', detail: '展開された配列内の列の数。 存在しない場合、列は展開されません。' },+ padWith: { name: '埋め込む値', detail: '埋め込む値。 既定値は #N/A です。' },},},FILTER: {@@ -432,8 +435,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '配列', detail: '行または列を取得する配列。' },+ rows: { name: '行の数', detail: '取得する行の数。 負の値は配列の最後から取得します。' },+ columns: { name: '列の数', detail: '取得する列の数。 負の値は配列の最後から取得します。' },},},TOCOL: {@@ -446,8 +450,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '配列', detail: '列として返す配列または参照。' },+ ignore: { name: '無視値', detail: '特定の種類の値を無視するかどうか。 既定では、値は無視されません。 次のいずれかを指定します。\n0 すべての値を保持する (既定)\n1 空白を無視する\n2 エラーを無視する\n3 空白とエラーを無視する' },+ scanByColumn: { name: '配列を列でスキャンします', detail: '配列を列でスキャンします。 既定では、配列は行ごとにスキャンされます。 スキャンにより、値が行順か列順かが決まります。' },},},TOROW: {@@ -460,8 +465,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '配列', detail: '行として返す配列または参照。' },+ ignore: { name: '無視値', detail: '特定の種類の値を無視するかどうか。 既定では、値は無視されません。 次のいずれかを指定します。\n0 すべての値を保持する (既定)\n1 空白を無視する\n2 エラーを無視する\n3 空白とエラーを無視する' },+ scanByColumn: { name: '配列を列でスキャンします', detail: '配列を列でスキャンします。 既定では、配列は行ごとにスキャンされます。 スキャンにより、値が行順か列順かが決まります。' },},},TRANSPOSE: {@@ -535,8 +541,8 @@ export default {},},WRAPCOLS: {- description: '指定した数の要素の後に、指定した行または列の値を列でラップします',- abstract: '指定した数の要素の後に、指定した行または列の値を列でラップします',+ description: '指定した数の要素の後に、指定された値の行または列を列ごとにラップして、新しい配列を形成します。',+ abstract: '指定した数の要素の後に、指定された値の行または列を列ごとにラップして、新しい配列を形成します。',links: [{title: '指導',@@ -544,13 +550,14 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: 'ベクター', detail: 'ラップするベクターまたは参照。' },+ wrapCount: { name: '改行の数', detail: '各列の値の最大数。' },+ padWith: { name: '埋め込む値', detail: '埋め込む値。 既定値は #N/A です。' },},},WRAPROWS: {- description: '指定した数の要素の後に、指定された行または値の列を行ごとにラップします',- abstract: '指定した数の要素の後に、指定された行または値の列を行ごとにラップします',+ description: '指定した数の要素の後に、指定された行または値の列を行ごとにラップして、新しい配列を形成します。',+ abstract: '指定した数の要素の後に、指定された行または値の列を行ごとにラップして、新しい配列を形成します。',links: [{title: '指導',@@ -558,8 +565,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: 'ベクター', detail: 'ラップするベクターまたは参照。' },+ wrapCount: { name: '改行の数', detail: '各行の値の最大数。' },+ padWith: { name: '埋め込む値', detail: '埋め込む値。 既定値は #N/A です。' },},},XLOOKUP: {diff --git a/packages/sheets-formula/src/locale/function-list/lookup/vi-VN.ts b/packages/sheets-formula/src/locale/function-list/lookup/vi-VN.tsindex 411c36f28c..c83a5a6534 100644--- a/packages/sheets-formula/src/locale/function-list/lookup/vi-VN.ts+++ b/packages/sheets-formula/src/locale/function-list/lookup/vi-VN.ts@@ -138,8 +138,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'đầu tiên' },- number2: { name: 'number2', detail: 'thứ hai' },+ array: { name: 'mảng', detail: 'Mảng mà từ đó thả hàng hoặc cột.' },+ rows: { name: 'số hàng', detail: 'Số hàng cần thả. Giá trị âm giảm từ cuối mảng.' },+ columns: { name: 'số cột', detail: 'Số cột cần loại trừ. Giá trị âm giảm từ cuối mảng.' },},},EXPAND: {@@ -152,8 +153,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'đầu tiên' },- number2: { name: 'number2', detail: 'thứ hai' },+ array: { name: 'mảng', detail: 'Mảng cần bung rộng.' },+ rows: { name: 'số hàng', detail: 'Số hàng trong mảng đã bung rộng. Nếu thiếu, hàng sẽ không được bung rộng.' },+ columns: { name: 'số cột', detail: 'Số cột trong mảng đã bung rộng. Nếu thiếu, cột sẽ không được bung rộng.' },+ padWith: { name: 'giá trị cần đệm', detail: 'Giá trị cần đệm. Mặc định là #N/A.' },},},FILTER: {@@ -355,6 +358,51 @@ export default {sortOrder2: { name: 'thứ tự sắp xếp 2', detail: 'Thứ tự dùng để sắp xếp. 1 cho tăng dần, -1 cho giảm dần. Mặc định là tăng dần.' },},},+ TAKE: {+ description: 'Trả về một số hàng hoặc cột liền kề đã xác định từ điểm bắt đầu hoặc kết thúc của một mảng.',+ abstract: 'Trả về một số hàng hoặc cột liền kề đã xác định từ điểm bắt đầu hoặc kết thúc của một mảng.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/take-%E5%87%BD%E6%95%B0-25382ff1-5da1-4f78-ab43-f33bd2e4e003',+ },+ ],+ functionParameter: {+ array: { name: 'mảng', detail: 'Mảng lấy hàng hoặc cột từ đó.' },+ rows: { name: 'số hàng', detail: 'Số hàng cần thực hiện. Giá trị âm lấy từ cuối mảng.' },+ columns: { name: 'số cột', detail: 'Số cột cần thực hiện. Giá trị âm lấy từ cuối mảng.' },+ },+ },+ TOCOL: {+ description: 'Trả về mảng trong một cột đơn.',+ abstract: 'Trả về mảng trong một cột đơn.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/tocol-%E5%87%BD%E6%95%B0-22839d9b-0b55-4fc1-b4e6-2761f8f122ed',+ },+ ],+ functionParameter: {+ array: { name: 'mảng', detail: 'Mảng hoặc tham chiếu muốn trả về dưới dạng cột.' },+ ignore: { name: 'bỏ qua giá trị', detail: 'Có bỏ qua một số kiểu giá trị nhất định hay không. Theo mặc định, không có giá trị nào bị bỏ qua. Xác định một trong những hành động sau:\n0 Giữ tất cả các giá trị (mặc định)\n1 Bỏ qua giá trị trống\n2 Bỏ qua lỗi\n3 Bỏ qua giá trị trống và lỗi' },+ scanByColumn: { name: 'quét mảng theo cột', detail: 'Quét mảng theo cột. Theo mặc định, mảng được quét theo hàng. Quét xác định xem các giá trị được sắp xếp theo hàng hay theo cột.' },+ },+ },+ TOROW: {+ description: 'Trả về mảng trong một hàng đơn.',+ abstract: 'Trả về mảng trong một hàng đơn.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/torow-%E5%87%BD%E6%95%B0-b90d0964-a7d9-44b7-816b-ffa5c2fe2289',+ },+ ],+ functionParameter: {+ array: { name: 'mảng', detail: 'Mảng hoặc tham chiếu muốn trả về dưới dạng một hàng.' },+ ignore: { name: 'bỏ qua giá trị', detail: 'Có bỏ qua một số kiểu giá trị nhất định hay không. Theo mặc định, không có giá trị nào bị bỏ qua. Xác định một trong những hành động sau:\n0 Giữ tất cả các giá trị (mặc định)\n1 Bỏ qua giá trị trống\n2 Bỏ qua lỗi\n3 Bỏ qua giá trị trống và lỗi' },+ scanByColumn: { name: 'quét mảng theo cột', detail: 'Quét mảng theo cột. Theo mặc định, mảng được quét theo hàng. Quét xác định xem các giá trị được sắp xếp theo hàng hay theo cột.' },+ },+ },TRANSPOSE: {description: 'Trả về chuyển vị của một mảng',abstract: 'Trả về chuyển vị của một mảng',@@ -425,6 +473,36 @@ export default {array2: { name: 'mảng', detail: 'Mảng để nối thêm.' },},},+ WRAPCOLS: {+ description: 'Ngắt dòng hoặc cột giá trị được cung cấp theo cột sau một số lượng các thành phần được chỉ định để tạo thành một mảng mới.',+ abstract: 'Ngắt dòng hoặc cột giá trị được cung cấp theo cột sau một số lượng các thành phần được chỉ định để tạo thành một mảng mới.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/wrapcols-%E5%87%BD%E6%95%B0-d038b05a-57b7-4ee0-be94-ded0792511e2',+ },+ ],+ functionParameter: {+ vector: { name: 'véc-tơ', detail: 'Véc-tơ hoặc tham chiếu để ngắt dòng.' },+ wrapCount: { name: 'số lần ngắt dòng', detail: 'Số lượng giá trị tối đa cho mỗi cột.' },+ padWith: { name: 'giá trị cần đệm', detail: 'Giá trị cần đệm. Mặc định là #N/A.' },+ },+ },+ WRAPROWS: {+ description: 'Ngắt dòng hoặc cột giá trị được cung cấp theo hàng sau một số lượng các thành phần được chỉ định để tạo thành một mảng mới.',+ abstract: 'Ngắt dòng hoặc cột giá trị được cung cấp theo hàng sau một số lượng các thành phần được chỉ định để tạo thành một mảng mới.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/wraprows-%E5%87%BD%E6%95%B0-796825f3-975a-4cee-9c84-1bbddf60ade0',+ },+ ],+ functionParameter: {+ vector: { name: 'véc-tơ', detail: 'Véc-tơ hoặc tham chiếu để ngắt dòng.' },+ wrapCount: { name: 'số lần ngắt dòng', detail: 'Số lượng giá trị tối đa cho mỗi hàng.' },+ padWith: { name: 'giá trị cần đệm', detail: 'Giá trị cần đệm. Mặc định là #N/A.' },+ },+ },XLOOKUP: {description: 'Hàm tìm kiếm một phạm vi hoặc mảng và trả về mục tương ứng với kết quả khớp đầu tiên mà nó tìm thấy. Nếu không có kết quả khớp nào tồn tại, XLOOKUP có thể trả về kết quả khớp (gần đúng) gần nhất',abstract: 'Tìm kiếm một phạm vi hoặc mảng và trả về mục tương ứng với kết quả khớp đầu tiên được tìm thấy.',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.tsindex 297bc34ffa..74405e16bb 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@@ -124,8 +124,8 @@ export default {},},DROP: {- description: '从数组的开头或末尾排除指定数量的行或列',- abstract: '从数组的开头或末尾排除指定数量的行或列',+ description: '从数组的开头或末尾删除指定数量的行或列',+ abstract: '从数组的开头或末尾删除指定数量的行或列',links: [{title: '教学',@@ -133,8 +133,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '数组', detail: '要从中删除行或列的数组。' },+ rows: { name: '行数', detail: '要删除的行数。负数表示从数组末尾开始删除。' },+ columns: { name: '列数', detail: '要删除的列数。负数表示从数组末尾开始删除。' },},},EXPAND: {@@ -147,8 +148,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '数组', detail: '要展开的数组。' },+ rows: { name: '行数', detail: '扩展数组中的行数。 如果缺少,行将不会展开。' },+ columns: { name: '列数', detail: '展开数组中的列数。 如果缺少,列将不会展开。' },+ padWith: { name: '填充值', detail: '要填充的值。 默认值为 #N/A。' },},},FILTER: {@@ -430,8 +433,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '数组', detail: '要从中获取行或列的数组。' },+ rows: { name: '行数', detail: '要获取的行数。负数表示从数组末尾开始获取。' },+ columns: { name: '列数', detail: '要获取的列数。负数表示从数组末尾开始获取。' },},},TOCOL: {@@ -444,8 +448,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '数组', detail: '要作为列返回的数组或引用。' },+ ignore: { name: '忽略值', detail: '是否忽略某些类型的值。默认情况下,不会忽略任何值。 指定下列操作之一:\n0 保留所有值(默认)\n1 忽略空白\n2 忽略错误\n3 忽略空白和错误' },+ scanByColumn: { name: '按列扫描数组', detail: '按列扫描数组。 默认情况下,按行扫描数组。 扫描确定值是按行排序还是按列排序。' },},},TOROW: {@@ -458,8 +463,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '数组', detail: '要作为行返回的数组或引用。' },+ ignore: { name: '忽略值', detail: '是否忽略某些类型的值。默认情况下,不会忽略任何值。 指定下列操作之一:\n0 保留所有值(默认)\n1 忽略空白\n2 忽略错误\n3 忽略空白和错误' },+ scanByColumn: { name: '按列扫描数组', detail: '按列扫描数组。 默认情况下,按行扫描数组。 扫描确定值是按行排序还是按列排序。' },},},TRANSPOSE: {@@ -534,8 +540,8 @@ export default {},},WRAPCOLS: {- description: '在指定数量的元素之后按列包装提供的行或值列',- abstract: '在指定数量的元素之后按列包装提供的行或值列',+ description: '将提供的行或列的值按列换行到指定数量的元素之后以形成新数组。',+ abstract: '将提供的行或列的值按列换行到指定数量的元素之后以形成新数组。',links: [{title: '教学',@@ -543,13 +549,14 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: '矢量', detail: '要换行的矢量或引用。' },+ wrapCount: { name: '换行数量', detail: '每列的值的最大数量。' },+ padWith: { name: '填充值', detail: '要填充的值。 默认值为 #N/A。' },},},WRAPROWS: {- description: '在指定数量的元素之后按行包装提供的行或值列',- abstract: '在指定数量的元素之后按行包装提供的行或值列',+ description: '将提供的行或列的值按行换行到指定数量的元素之后以形成新数组。',+ abstract: '将提供的行或列的值按行换行到指定数量的元素之后以形成新数组。',links: [{title: '教学',@@ -557,8 +564,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: '矢量', detail: '要换行的矢量或引用。' },+ wrapCount: { name: '换行数量', detail: '每行的值的最大数量。' },+ padWith: { name: '填充值', detail: '要填充的值。 默认值为 #N/A。' },},},XLOOKUP: {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.tsindex 49f5ab52b4..1b4b761a89 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@@ -133,8 +133,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '陣列', detail: '要排除列或欄的陣列。' },+ rows: { name: '列數', detail: '要排除的列數。負值會從陣列結尾排除。' },+ columns: { name: '欄數', detail: '要排除的欄數。負值會從陣列結尾排除。' },},},EXPAND: {@@ -147,8 +148,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '陣列', detail: '要展開的陣列。' },+ rows: { name: '列數', detail: '展開陣列中的列數。 如果遺失,將不會展開列。' },+ columns: { name: '欄數', detail: '展開陣列中的欄數。 如果遺失,欄將不會展開。' },+ padWith: { name: '填塞值', detail: '要填塞的值。 預設值為 #N/A。' },},},FILTER: {@@ -430,13 +433,14 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '陣列', detail: '要取用列或欄的陣列。' },+ rows: { name: '列數', detail: '要取用的列數。負值會從陣列結尾取用。' },+ columns: { name: '欄數', detail: '要取用的欄數。負值會從陣列結尾取用。' },},},TOCOL: {- description: '傳回單一列中的陣列',- abstract: '傳回單一列中的陣列',+ description: '傳回單一欄中的陣列。',+ abstract: '傳回單一欄中的陣列。',links: [{title: '教導',@@ -444,13 +448,14 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '陣列', detail: '要以欄返回的陣列或參照。' },+ ignore: { name: '忽略值', detail: '是否要忽略特定類型的值。 根據預設,不會忽略任何值。 指定下列其中一項動作:\n0 保留所有值 (預設)\n1 略過空白\n2 略過錯誤\n3 略過空白和錯誤' },+ scanByColumn: { name: '依欄掃描陣列', detail: '依欄掃描陣列。 根據預設,陣列會以列掃描。 掃描會決定值是依列或欄排序。' },},},TOROW: {- description: '傳回單一行中的陣列',- abstract: '傳回單一行中的陣列',+ description: '傳回單一列中的陣列。',+ abstract: '傳回單一列中的陣列。',links: [{title: '教導',@@ -458,8 +463,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '陣列', detail: '要以列返回的陣列或參照。' },+ ignore: { name: '忽略值', detail: '是否要忽略特定類型的值。 根據預設,不會忽略任何值。 指定下列其中一項動作:\n0 保留所有值 (預設)\n1 略過空白\n2 略過錯誤\n3 略過空白和錯誤' },+ scanByColumn: { name: '依欄掃描陣列', detail: '依欄掃描陣列。 根據預設,陣列會以列掃描。 掃描會決定值是依列或欄排序。' },},},TRANSPOSE: {@@ -534,8 +540,8 @@ export default {},},WRAPCOLS: {- description: '在指定數量的元素之後按列包裝提供的行或值列',- abstract: '在指定數量的元素之後按列包裝提供的行或值列',+ description: '在指定的元素數之後,將提供的列或欄的值以欄換行,以形成新陣列。',+ abstract: '在指定的元素數之後,將提供的列或欄的值以欄換行,以形成新陣列。',links: [{title: '教導',@@ -543,13 +549,14 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: '向量', detail: '要換行的向量或參照。' },+ wrapCount: { name: '換行數目', detail: '每一欄的最大值數目。' },+ padWith: { name: '填塞值', detail: '要填塞的值。 預設值為 #N/A。' },},},WRAPROWS: {- description: '在指定數量的元素之後按行包裝提供的行或值列',- abstract: '在指定數量的元素之後按行包裝提供的行或值列',+ description: '在指定的元素數之後,將提供的列或欄的值以列換行,以形成新陣列。',+ abstract: '在指定的元素數之後,將提供的列或欄的值以列換行,以形成新陣列。',links: [{title: '教導',@@ -557,8 +564,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ vector: { name: '向量', detail: '要換行的向量或參照。' },+ wrapCount: { name: '換行數目', detail: '每一列的最大值數目。' },+ padWith: { name: '填塞值', detail: '要填塞的值。 預設值為 #N/A。' },},},XLOOKUP: {diff --git a/packages/sheets-formula/src/services/function-list/lookup.ts b/packages/sheets-formula/src/services/function-list/lookup.tsindex f4fb8cd46c..d12572aac6 100644--- a/packages/sheets-formula/src/services/function-list/lookup.ts+++ b/packages/sheets-formula/src/services/function-list/lookup.ts@@ -199,19 +199,26 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [abstract: 'formula.functionList.DROP.abstract',functionParameter: [{- name: 'formula.functionList.DROP.functionParameter.number1.name',- detail: 'formula.functionList.DROP.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.DROP.functionParameter.array.name',+ detail: 'formula.functionList.DROP.functionParameter.array.detail',+ example: 'A2:C4',require: 1,repeat: 0,},{- name: 'formula.functionList.DROP.functionParameter.number2.name',- detail: 'formula.functionList.DROP.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.DROP.functionParameter.rows.name',+ detail: 'formula.functionList.DROP.functionParameter.rows.detail',+ example: '2',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.DROP.functionParameter.columns.name',+ detail: 'formula.functionList.DROP.functionParameter.columns.detail',+ example: '2',+ require: 0,+ repeat: 0,+ },],},{@@ -221,19 +228,33 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [abstract: 'formula.functionList.EXPAND.abstract',functionParameter: [{- name: 'formula.functionList.EXPAND.functionParameter.number1.name',- detail: 'formula.functionList.EXPAND.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.EXPAND.functionParameter.array.name',+ detail: 'formula.functionList.EXPAND.functionParameter.array.detail',+ example: 'A2',require: 1,repeat: 0,},{- name: 'formula.functionList.EXPAND.functionParameter.number2.name',- detail: 'formula.functionList.EXPAND.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.EXPAND.functionParameter.rows.name',+ detail: 'formula.functionList.EXPAND.functionParameter.rows.detail',+ example: '3',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.EXPAND.functionParameter.columns.name',+ detail: 'formula.functionList.EXPAND.functionParameter.columns.detail',+ example: '3',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.EXPAND.functionParameter.padWith.name',+ detail: 'formula.functionList.EXPAND.functionParameter.padWith.detail',+ example: '"-"',+ require: 0,+ repeat: 0,+ },],},{@@ -708,19 +729,26 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [abstract: 'formula.functionList.TAKE.abstract',functionParameter: [{- name: 'formula.functionList.TAKE.functionParameter.number1.name',- detail: 'formula.functionList.TAKE.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.TAKE.functionParameter.array.name',+ detail: 'formula.functionList.TAKE.functionParameter.array.detail',+ example: 'A2:C4',require: 1,repeat: 0,},{- name: 'formula.functionList.TAKE.functionParameter.number2.name',- detail: 'formula.functionList.TAKE.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.TAKE.functionParameter.rows.name',+ detail: 'formula.functionList.TAKE.functionParameter.rows.detail',+ example: '2',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.TAKE.functionParameter.columns.name',+ detail: 'formula.functionList.TAKE.functionParameter.columns.detail',+ example: '2',+ require: 0,+ repeat: 0,+ },],},{@@ -730,17 +758,24 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [abstract: 'formula.functionList.TOCOL.abstract',functionParameter: [{- name: 'formula.functionList.TOCOL.functionParameter.number1.name',- detail: 'formula.functionList.TOCOL.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.TOCOL.functionParameter.array.name',+ detail: 'formula.functionList.TOCOL.functionParameter.array.detail',+ example: 'A2:D4',require: 1,repeat: 0,},{- name: 'formula.functionList.TOCOL.functionParameter.number2.name',- detail: 'formula.functionList.TOCOL.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.TOCOL.functionParameter.ignore.name',+ detail: 'formula.functionList.TOCOL.functionParameter.ignore.detail',+ example: '1',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.TOCOL.functionParameter.scanByColumn.name',+ detail: 'formula.functionList.TOCOL.functionParameter.scanByColumn.detail',+ example: 'TRUE',+ require: 0,repeat: 0,},],@@ -752,17 +787,24 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [abstract: 'formula.functionList.TOROW.abstract',functionParameter: [{- name: 'formula.functionList.TOROW.functionParameter.number1.name',- detail: 'formula.functionList.TOROW.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.TOROW.functionParameter.array.name',+ detail: 'formula.functionList.TOROW.functionParameter.array.detail',+ example: 'A2:D4',require: 1,repeat: 0,},{- name: 'formula.functionList.TOROW.functionParameter.number2.name',- detail: 'formula.functionList.TOROW.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.TOROW.functionParameter.ignore.name',+ detail: 'formula.functionList.TOROW.functionParameter.ignore.detail',+ example: '1',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.TOROW.functionParameter.scanByColumn.name',+ detail: 'formula.functionList.TOROW.functionParameter.scanByColumn.detail',+ example: 'TRUE',+ require: 0,repeat: 0,},],@@ -876,19 +918,26 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [abstract: 'formula.functionList.WRAPCOLS.abstract',functionParameter: [{- name: 'formula.functionList.WRAPCOLS.functionParameter.number1.name',- detail: 'formula.functionList.WRAPCOLS.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.WRAPCOLS.functionParameter.vector.name',+ detail: 'formula.functionList.WRAPCOLS.functionParameter.vector.detail',+ example: 'A2:G2',require: 1,repeat: 0,},{- name: 'formula.functionList.WRAPCOLS.functionParameter.number2.name',- detail: 'formula.functionList.WRAPCOLS.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.WRAPCOLS.functionParameter.wrapCount.name',+ detail: 'formula.functionList.WRAPCOLS.functionParameter.wrapCount.detail',+ example: '3',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.WRAPCOLS.functionParameter.padWith.name',+ detail: 'formula.functionList.WRAPCOLS.functionParameter.padWith.detail',+ example: '"x"',+ require: 0,+ repeat: 0,+ },],},{@@ -898,19 +947,26 @@ export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [abstract: 'formula.functionList.WRAPROWS.abstract',functionParameter: [{- name: 'formula.functionList.WRAPROWS.functionParameter.number1.name',- detail: 'formula.functionList.WRAPROWS.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.WRAPROWS.functionParameter.vector.name',+ detail: 'formula.functionList.WRAPROWS.functionParameter.vector.detail',+ example: 'A2:G2',require: 1,repeat: 0,},{- name: 'formula.functionList.WRAPROWS.functionParameter.number2.name',- detail: 'formula.functionList.WRAPROWS.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.WRAPROWS.functionParameter.wrapCount.name',+ detail: 'formula.functionList.WRAPROWS.functionParameter.wrapCount.detail',+ example: '3',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.WRAPROWS.functionParameter.padWith.name',+ detail: 'formula.functionList.WRAPROWS.functionParameter.padWith.detail',+ example: '"x"',+ require: 0,+ repeat: 0,+ },],},{