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
fix(formula): add more functions, rename formula file (#878)
Dushusir8e201d49c6f0
diff --git a/packages/engine-formula/src/engine/ast-node/operator-node.ts b/packages/engine-formula/src/engine/ast-node/operator-node.tsindex 012787b515..4c2a3be598 100644--- a/packages/engine-formula/src/engine/ast-node/operator-node.ts+++ b/packages/engine-formula/src/engine/ast-node/operator-node.ts@@ -20,7 +20,7 @@ import { OPERATOR_TOKEN_COMPARE_SET, OPERATOR_TOKEN_SET, operatorToken } from '.import type { BaseFunction } from '../../functions/base-function';import { FUNCTION_NAMES_COMPATIBILITY } from '../../functions/compatibility/function-names';import { FUNCTION_NAMES_MATH } from '../../functions/math/function-names';-import type { Compare } from '../../functions/meta/compare/compare';+import type { Compare } from '../../functions/meta/compare';import { FUNCTION_NAMES_META } from '../../functions/meta/function-names';import { IFunctionService } from '../../services/function.service';import { LexerNode } from '../analysis/lexer-node';diff --git a/packages/engine-formula/src/functions/compatibility/concatenate/concatenate.ts b/packages/engine-formula/src/functions/compatibility/concatenate/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/compatibility/concatenate/concatenate.tsrename to packages/engine-formula/src/functions/compatibility/concatenate/index.tsdiff --git a/packages/engine-formula/src/functions/compatibility/function-map.ts b/packages/engine-formula/src/functions/compatibility/function-map.tsindex 93fe502e5c..eefe640217 100644--- a/packages/engine-formula/src/functions/compatibility/function-map.ts+++ b/packages/engine-formula/src/functions/compatibility/function-map.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { Concatenate } from './concatenate/concatenate';+import { Concatenate } from './concatenate';import { FUNCTION_NAMES_COMPATIBILITY } from './function-names';export const functionCompatibility = [[Concatenate, FUNCTION_NAMES_COMPATIBILITY.CONCATENATE]];diff --git a/packages/engine-formula/src/functions/lookup/function-map.ts b/packages/engine-formula/src/functions/lookup/function-map.tsindex 1d71919135..aa5c7037b3 100644--- a/packages/engine-formula/src/functions/lookup/function-map.ts+++ b/packages/engine-formula/src/functions/lookup/function-map.ts@@ -15,8 +15,8 @@*/import { FUNCTION_NAMES_LOOKUP } from './function-names';-import { Indirect } from './indirect/indirect';-import { Offset } from './offset/offset';+import { Indirect } from './indirect';+import { Offset } from './offset';export const functionLookup = [[Indirect, FUNCTION_NAMES_LOOKUP.INDIRECT],diff --git a/packages/engine-formula/src/functions/lookup/indirect/indirect.ts b/packages/engine-formula/src/functions/lookup/indirect/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/lookup/indirect/indirect.tsrename to packages/engine-formula/src/functions/lookup/indirect/index.tsdiff --git a/packages/engine-formula/src/functions/lookup/offset/offset.ts b/packages/engine-formula/src/functions/lookup/offset/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/lookup/offset/offset.tsrename to packages/engine-formula/src/functions/lookup/offset/index.tsdiff --git a/packages/engine-formula/src/functions/math/abs/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/abs/__tests__/index.spec.tsnew file mode 100644index 0000000000..4d2514658d--- /dev/null+++ b/packages/engine-formula/src/functions/math/abs/__tests__/index.spec.ts@@ -0,0 +1,137 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IRange } from '@univerjs/core';+import { ObjectMatrix } from '@univerjs/core';+import { beforeEach, describe, expect, it } from 'vitest';++import type { ISheetData } from '../../../../basics/common';+import { ErrorType } from '../../../../basics/error-type';+import { RangeReferenceObject } from '../../../../engine/reference-object/range-reference-object';+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Abs } from '..';++const cellData = {+ 0: {+ 0: {+ v: 1,+ },+ 1: {+ v: ' ',+ },+ 2: {+ v: 1.23,+ },+ 3: {+ v: true,+ },+ 4: {+ v: false,+ },+ },+ 1: {+ 0: {+ v: 0,+ },+ 1: {+ v: '100',+ },+ 2: {+ v: '2.34',+ },+ 3: {+ v: 'test',+ },+ 4: {+ v: -3,+ },+ },+};++describe('test abs', () => {+ let unitId: string;+ let sheetId: string;+ let sheetData: ISheetData = {};+ let abs: Abs;+ let absCalculate: (range: IRange) => ArrayValueObject;++ beforeEach(() => {+ unitId = 'test';+ sheetId = 'sheet1';+ sheetData = {+ [sheetId]: {+ cellData: new ObjectMatrix(cellData),+ rowCount: 4,+ columnCount: 3,+ },+ };++ // register abs+ abs = new Abs(FUNCTION_NAMES_MATH.ABS);+ absCalculate = (range: IRange) => {+ // range++ const rangeRef = new RangeReferenceObject(range, sheetId, unitId);+ rangeRef.setUnitData({+ [unitId]: sheetData,+ });++ return abs.calculate(rangeRef) as ArrayValueObject;+ };+ });++ describe('abs', () => {+ describe('correct situations', () => {+ it('single cell', async () => {+ // cell A1+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 0,+ endColumn: 0,+ };++ const arrayValue = absCalculate(cell);+ expect(arrayValue.getFirstCell().getValue()).toBe(1);+ });+ it('range', async () => {+ // cell A1:E2+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 1,+ endColumn: 4,+ };++ const arrayValue = absCalculate(cell);+ expect(arrayValue.toValue()).toStrictEqual([+ [1, '#VALUE!', 1.23, 1, 0],+ [0, 100, 2.34, '#VALUE!', 3],+ ]);+ });+ });++ describe('fault situations', () => {+ it('value error', async () => {+ const error = ErrorValueObject.create(ErrorType.VALUE);+ const errorValue = abs.calculate(error);+ expect(errorValue.isError()).toBeTruthy();+ });+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/abs/index.ts b/packages/engine-formula/src/functions/math/abs/index.tsnew file mode 100644index 0000000000..b56f550892--- /dev/null+++ b/packages/engine-formula/src/functions/math/abs/index.ts@@ -0,0 +1,34 @@+/**+ * 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 { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Abs extends BaseFunction {+ override calculate(variant: FunctionVariantType) {+ if (variant.isError()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (variant.isReferenceObject()) {+ variant = (variant as BaseReferenceObject).toArrayValueObject();+ }+ return (variant as BaseValueObject).abs();+ }+}diff --git a/packages/engine-formula/src/functions/math/acos/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/acos/__tests__/index.spec.tsnew file mode 100644index 0000000000..295441c695--- /dev/null+++ b/packages/engine-formula/src/functions/math/acos/__tests__/index.spec.ts@@ -0,0 +1,137 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IRange } from '@univerjs/core';+import { ObjectMatrix } from '@univerjs/core';+import { beforeEach, describe, expect, it } from 'vitest';++import type { ISheetData } from '../../../../basics/common';+import { ErrorType } from '../../../../basics/error-type';+import { RangeReferenceObject } from '../../../../engine/reference-object/range-reference-object';+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Acos } from '..';++const cellData = {+ 0: {+ 0: {+ v: 1,+ },+ 1: {+ v: ' ',+ },+ 2: {+ v: 1.23,+ },+ 3: {+ v: true,+ },+ 4: {+ v: false,+ },+ },+ 1: {+ 0: {+ v: 0,+ },+ 1: {+ v: '100',+ },+ 2: {+ v: '2.34',+ },+ 3: {+ v: 'test',+ },+ 4: {+ v: -3,+ },+ },+};++describe('test acos', () => {+ let unitId: string;+ let sheetId: string;+ let sheetData: ISheetData = {};+ let acos: Acos;+ let acosCalculate: (range: IRange) => ArrayValueObject;++ beforeEach(() => {+ unitId = 'test';+ sheetId = 'sheet1';+ sheetData = {+ [sheetId]: {+ cellData: new ObjectMatrix(cellData),+ rowCount: 4,+ columnCount: 3,+ },+ };++ // register acos+ acos = new Acos(FUNCTION_NAMES_MATH.ACOS);+ acosCalculate = (range: IRange) => {+ // range++ const rangeRef = new RangeReferenceObject(range, sheetId, unitId);+ rangeRef.setUnitData({+ [unitId]: sheetData,+ });++ return acos.calculate(rangeRef) as ArrayValueObject;+ };+ });++ describe('acos', () => {+ describe('correct situations', () => {+ it('single cell', async () => {+ // cell A1+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 0,+ endColumn: 0,+ };++ const arrayValue = acosCalculate(cell);+ expect(arrayValue.getFirstCell().getValue()).toBe(0);+ });+ it('range', async () => {+ // cell A1:E2+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 1,+ endColumn: 4,+ };++ const arrayValue = acosCalculate(cell);+ expect(arrayValue.toValue()).toStrictEqual([+ [0, '#VALUE!', '#NUM!', 0, 1.5707963267948966],+ [1.5707963267948966, '#NUM!', '#NUM!', '#VALUE!', '#NUM!'],+ ]);+ });+ });++ describe('fault situations', () => {+ it('value error', async () => {+ const error = ErrorValueObject.create(ErrorType.VALUE);+ const errorValue = acos.calculate(error);+ expect(errorValue.isError()).toBeTruthy();+ });+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/acos/index.ts b/packages/engine-formula/src/functions/math/acos/index.tsnew file mode 100644index 0000000000..9f642d3d64--- /dev/null+++ b/packages/engine-formula/src/functions/math/acos/index.ts@@ -0,0 +1,34 @@+/**+ * 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 { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Acos extends BaseFunction {+ override calculate(variant: FunctionVariantType) {+ if (variant.isError()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (variant.isReferenceObject()) {+ variant = (variant as BaseReferenceObject).toArrayValueObject();+ }+ return (variant as BaseValueObject).acos();+ }+}diff --git a/packages/engine-formula/src/functions/math/acosh/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/acosh/__tests__/index.spec.tsnew file mode 100644index 0000000000..f6c8bee1f0--- /dev/null+++ b/packages/engine-formula/src/functions/math/acosh/__tests__/index.spec.ts@@ -0,0 +1,137 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IRange } from '@univerjs/core';+import { ObjectMatrix } from '@univerjs/core';+import { beforeEach, describe, expect, it } from 'vitest';++import type { ISheetData } from '../../../../basics/common';+import { ErrorType } from '../../../../basics/error-type';+import { RangeReferenceObject } from '../../../../engine/reference-object/range-reference-object';+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Acosh } from '..';++const cellData = {+ 0: {+ 0: {+ v: 1,+ },+ 1: {+ v: ' ',+ },+ 2: {+ v: 1.23,+ },+ 3: {+ v: true,+ },+ 4: {+ v: false,+ },+ },+ 1: {+ 0: {+ v: 0,+ },+ 1: {+ v: '100',+ },+ 2: {+ v: '2.34',+ },+ 3: {+ v: 'test',+ },+ 4: {+ v: -3,+ },+ },+};++describe('test acosh', () => {+ let unitId: string;+ let sheetId: string;+ let sheetData: ISheetData = {};+ let acosh: Acosh;+ let acoshCalculate: (range: IRange) => ArrayValueObject;++ beforeEach(() => {+ unitId = 'test';+ sheetId = 'sheet1';+ sheetData = {+ [sheetId]: {+ cellData: new ObjectMatrix(cellData),+ rowCount: 4,+ columnCount: 3,+ },+ };++ // register acosh+ acosh = new Acosh(FUNCTION_NAMES_MATH.ACOSH);+ acoshCalculate = (range: IRange) => {+ // range++ const rangeRef = new RangeReferenceObject(range, sheetId, unitId);+ rangeRef.setUnitData({+ [unitId]: sheetData,+ });++ return acosh.calculate(rangeRef) as ArrayValueObject;+ };+ });++ describe('acosh', () => {+ describe('correct situations', () => {+ it('single cell', async () => {+ // cell A1+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 0,+ endColumn: 0,+ };++ const arrayValue = acoshCalculate(cell);+ expect(arrayValue.getFirstCell().getValue()).toBe(0);+ });+ it('range', async () => {+ // cell A1:E2+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 1,+ endColumn: 4,+ };++ const arrayValue = acoshCalculate(cell);+ expect(arrayValue.toValue()).toStrictEqual([+ [0, '#VALUE!', 0.6658635291565548, 0, '#NUM!'],+ ['#NUM!', 5.298292365610484, 1.494153066724473, '#VALUE!', '#NUM!'],+ ]);+ });+ });++ describe('fault situations', () => {+ it('value error', async () => {+ const error = ErrorValueObject.create(ErrorType.VALUE);+ const errorValue = acosh.calculate(error);+ expect(errorValue.isError()).toBeTruthy();+ });+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/acosh/index.ts b/packages/engine-formula/src/functions/math/acosh/index.tsnew file mode 100644index 0000000000..993857359d--- /dev/null+++ b/packages/engine-formula/src/functions/math/acosh/index.ts@@ -0,0 +1,34 @@+/**+ * 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 { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Acosh extends BaseFunction {+ override calculate(variant: FunctionVariantType) {+ if (variant.isError()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (variant.isReferenceObject()) {+ variant = (variant as BaseReferenceObject).toArrayValueObject();+ }+ return (variant as BaseValueObject).acosh();+ }+}diff --git a/packages/engine-formula/src/functions/math/acot/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/acot/__tests__/index.spec.tsnew file mode 100644index 0000000000..a954648402--- /dev/null+++ b/packages/engine-formula/src/functions/math/acot/__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 type { IRange } from '@univerjs/core';+import { ObjectMatrix } from '@univerjs/core';+import { beforeEach, describe, expect, it } from 'vitest';++import type { ISheetData } from '../../../../basics/common';+import { ErrorType } from '../../../../basics/error-type';+import { RangeReferenceObject } from '../../../../engine/reference-object/range-reference-object';+import type { ArrayValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Acot } from '..';++const cellData = {+ 0: {+ 0: {+ v: 1,+ },+ 1: {+ v: ' ',+ },+ 2: {+ v: 1.23,+ },+ 3: {+ v: true,+ },+ 4: {+ v: false,+ },+ },+ 1: {+ 0: {+ v: 0,+ },+ 1: {+ v: '100',+ },+ 2: {+ v: '2.34',+ },+ 3: {+ v: 'test',+ },+ 4: {+ v: -3,+ },+ },+};++describe('test acot', () => {+ let unitId: string;+ let sheetId: string;+ let sheetData: ISheetData = {};+ let acot: Acot;+ let acotCalculate: (range: IRange) => ArrayValueObject;++ beforeEach(() => {+ unitId = 'test';+ sheetId = 'sheet1';+ sheetData = {+ [sheetId]: {+ cellData: new ObjectMatrix(cellData),+ rowCount: 4,+ columnCount: 3,+ },+ };++ // register acot+ acot = new Acot(FUNCTION_NAMES_MATH.ACOT);+ acotCalculate = (range: IRange) => {+ // range++ const rangeRef = new RangeReferenceObject(range, sheetId, unitId);+ rangeRef.setUnitData({+ [unitId]: sheetData,+ });++ return acot.calculate(rangeRef) as ArrayValueObject;+ };+ });++ describe('acot', () => {+ describe('correct situations', () => {+ it('single cell', async () => {+ // cell A1+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 0,+ endColumn: 0,+ };++ const arrayValue = acotCalculate(cell);+ expect(arrayValue.getFirstCell().getValue()).toBe(0.7853981633974483);+ });+ it('range', async () => {+ // cell A1:E2+ const cell = {+ startRow: 0,+ startColumn: 0,+ endRow: 1,+ endColumn: 4,+ };++ const arrayValue = acotCalculate(cell);++ // =ACOT(-3) google gets -0.3217505544, but excel gets 2.819842+ expect(arrayValue.toValue()).toStrictEqual([+ [0.7853981633974483, '#VALUE!', 0.682622552417217, 0.7853981633974483, 1.5707963267948966],+ [1.5707963267948966, 0.009999666686665238, 0.40385979490737667, '#VALUE!', -0.3217505543966422],+ ]);+ });+ });++ describe('fault situations', () => {+ it('value error', async () => {+ const error = ErrorValueObject.create(ErrorType.VALUE);+ const errorValue = acot.calculate(error);+ expect(errorValue.isError()).toBeTruthy();+ });+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/acot/index.ts b/packages/engine-formula/src/functions/math/acot/index.tsnew file mode 100644index 0000000000..653405f739--- /dev/null+++ b/packages/engine-formula/src/functions/math/acot/index.ts@@ -0,0 +1,65 @@+/**+ * 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 { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Acot extends BaseFunction {+ override calculate(variant: FunctionVariantType) {+ if (variant.isError()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (variant.isReferenceObject()) {+ variant = (variant as BaseReferenceObject).toArrayValueObject();+ }++ if ((variant as BaseValueObject).isArray()) {+ return (variant as BaseValueObject).map((currentValue) => {+ if (currentValue.isError()) {+ return currentValue;+ }+ return acot(currentValue as BaseValueObject);+ });+ }++ return acot(variant as BaseValueObject);+ }+}++function acot(num: BaseValueObject) {+ let currentValue = num.getValue();++ if (num.isBoolean()) {+ currentValue = currentValue ? 1 : 0;+ }++ if (!Number.isFinite(currentValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const result = Math.atan(1 / Number(currentValue));++ if (Number.isNaN(result)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return new NumberValueObject(result);+}diff --git a/packages/engine-formula/src/functions/math/function-map.ts b/packages/engine-formula/src/functions/math/function-map.tsindex 0f7b829de4..3badc4c8f4 100644--- a/packages/engine-formula/src/functions/math/function-map.ts+++ b/packages/engine-formula/src/functions/math/function-map.ts@@ -14,13 +14,21 @@* limitations under the License.*/+import { Abs } from './abs';+import { Acos } from './acos';+import { Acosh } from './acosh';+import { Acot } from './acot';import { FUNCTION_NAMES_MATH } from './function-names';-import { Power } from './power/power';-import { Sum } from './sum/sum';-import { Sumif } from './sumif/sumif';-import { Sumifs } from './sumifs/sumifs';+import { Power } from './power';+import { Sum } from './sum';+import { Sumif } from './sumif';+import { Sumifs } from './sumifs';export const functionMath = [+ [Abs, FUNCTION_NAMES_MATH.ABS],+ [Acos, FUNCTION_NAMES_MATH.ACOS],+ [Acosh, FUNCTION_NAMES_MATH.ACOSH],+ [Acot, FUNCTION_NAMES_MATH.ACOT],[Sum, FUNCTION_NAMES_MATH.SUM],[Sumif, FUNCTION_NAMES_MATH.SUMIF],[Sumifs, FUNCTION_NAMES_MATH.SUMIFS],diff --git a/packages/engine-formula/src/functions/math/function-names.ts b/packages/engine-formula/src/functions/math/function-names.tsindex f63ee58faa..40b7bfe434 100644--- a/packages/engine-formula/src/functions/math/function-names.ts+++ b/packages/engine-formula/src/functions/math/function-names.ts@@ -15,6 +15,10 @@*/export enum FUNCTION_NAMES_MATH {+ ABS = 'ABS',+ ACOS = 'ACOS',+ ACOSH = 'ACOSH',+ ACOT = 'ACOT',SUM = 'SUM',SUMIF = 'SUMIF',SUMIFS = 'SUMIFS',diff --git a/packages/engine-formula/src/functions/math/power/power.ts b/packages/engine-formula/src/functions/math/power/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/math/power/power.tsrename to packages/engine-formula/src/functions/math/power/index.tsdiff --git a/packages/engine-formula/src/functions/math/sum/sum.ts b/packages/engine-formula/src/functions/math/sum/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/math/sum/sum.tsrename to packages/engine-formula/src/functions/math/sum/index.tsdiff --git a/packages/engine-formula/src/functions/math/sumif/__tests__/sumif.spec.ts b/packages/engine-formula/src/functions/math/sumif/__tests__/index.spec.tssimilarity index 99%rename from packages/engine-formula/src/functions/math/sumif/__tests__/sumif.spec.tsrename to packages/engine-formula/src/functions/math/sumif/__tests__/index.spec.tsindex a9bd7c8014..6028a3e6fc 100644--- a/packages/engine-formula/src/functions/math/sumif/__tests__/sumif.spec.ts+++ b/packages/engine-formula/src/functions/math/sumif/__tests__/index.spec.ts@@ -23,7 +23,7 @@ import { RangeReferenceObject } from '../../../../engine/reference-object/range-import { ValueObjectFactory } from '../../../../engine/value-object/array-value-object';import type { BaseValueObject } from '../../../../engine/value-object/base-value-object';import { FUNCTION_NAMES_MATH } from '../../function-names';-import { Sumif } from '../sumif';+import { Sumif } from '..';const cellData = {0: {diff --git a/packages/engine-formula/src/functions/math/sumif/sumif.ts b/packages/engine-formula/src/functions/math/sumif/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/math/sumif/sumif.tsrename to packages/engine-formula/src/functions/math/sumif/index.tsdiff --git a/packages/engine-formula/src/functions/math/sumifs/__tests__/sumifs.spec.ts b/packages/engine-formula/src/functions/math/sumifs/__tests__/index.spec.tssimilarity index 100%rename from packages/engine-formula/src/functions/math/sumifs/__tests__/sumifs.spec.tsrename to packages/engine-formula/src/functions/math/sumifs/__tests__/index.spec.tsdiff --git a/packages/engine-formula/src/functions/math/sumifs/sumifs.ts b/packages/engine-formula/src/functions/math/sumifs/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/math/sumifs/sumifs.tsrename to packages/engine-formula/src/functions/math/sumifs/index.tsdiff --git a/packages/engine-formula/src/functions/meta/compare/compare.ts b/packages/engine-formula/src/functions/meta/compare/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/meta/compare/compare.tsrename to packages/engine-formula/src/functions/meta/compare/index.tsdiff --git a/packages/engine-formula/src/functions/meta/divided/divided.ts b/packages/engine-formula/src/functions/meta/divided/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/meta/divided/divided.tsrename to packages/engine-formula/src/functions/meta/divided/index.tsdiff --git a/packages/engine-formula/src/functions/meta/function-map.ts b/packages/engine-formula/src/functions/meta/function-map.tsindex 9b9c223e96..343414cdd0 100644--- a/packages/engine-formula/src/functions/meta/function-map.ts+++ b/packages/engine-formula/src/functions/meta/function-map.ts@@ -14,13 +14,13 @@* limitations under the License.*/-import { Compare } from './compare/compare';-import { Divided } from './divided/divided';+import { Compare } from './compare';+import { Divided } from './divided';import { FUNCTION_NAMES_META } from './function-names';-import { Minus } from './minus/minus';-import { Multiply } from './multiply/multiply';-import { Plus } from './plus/plus';-import { Union } from './union/union';+import { Minus } from './minus';+import { Multiply } from './multiply';+import { Plus } from './plus';+import { Union } from './union';export const functionMeta = [[Compare, FUNCTION_NAMES_META.COMPARE],diff --git a/packages/engine-formula/src/functions/meta/minus/minus.ts b/packages/engine-formula/src/functions/meta/minus/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/meta/minus/minus.tsrename to packages/engine-formula/src/functions/meta/minus/index.tsdiff --git a/packages/engine-formula/src/functions/meta/multiply/multiply.ts b/packages/engine-formula/src/functions/meta/multiply/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/meta/multiply/multiply.tsrename to packages/engine-formula/src/functions/meta/multiply/index.tsdiff --git a/packages/engine-formula/src/functions/meta/plus/plus.ts b/packages/engine-formula/src/functions/meta/plus/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/meta/plus/plus.tsrename to packages/engine-formula/src/functions/meta/plus/index.tsdiff --git a/packages/engine-formula/src/functions/meta/union/union.ts b/packages/engine-formula/src/functions/meta/union/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/meta/union/union.tsrename to packages/engine-formula/src/functions/meta/union/index.tsdiff --git a/packages/engine-formula/src/functions/statistical/average/average.ts b/packages/engine-formula/src/functions/statistical/average/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/statistical/average/average.tsrename to packages/engine-formula/src/functions/statistical/average/index.tsdiff --git a/packages/engine-formula/src/functions/statistical/count/count.ts b/packages/engine-formula/src/functions/statistical/count/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/statistical/count/count.tsrename to packages/engine-formula/src/functions/statistical/count/index.tsdiff --git a/packages/engine-formula/src/functions/statistical/counta/counta.ts b/packages/engine-formula/src/functions/statistical/counta/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/statistical/counta/counta.tsrename to packages/engine-formula/src/functions/statistical/counta/index.tsdiff --git a/packages/engine-formula/src/functions/statistical/function-map.ts b/packages/engine-formula/src/functions/statistical/function-map.tsindex f8b9d7fa50..c886e708c9 100644--- a/packages/engine-formula/src/functions/statistical/function-map.ts+++ b/packages/engine-formula/src/functions/statistical/function-map.ts@@ -14,12 +14,12 @@* limitations under the License.*/-import { Average } from './average/average';-import { Count } from './count/count';-import { CountA } from './counta/counta';+import { Average } from './average';+import { Count } from './count';+import { CountA } from './counta';import { FUNCTION_NAMES_STATISTICAL } from './function-names';-import { Max } from './max/max';-import { Min } from './min/min';+import { Max } from './max';+import { Min } from './min';export const functionStatistical = [[Average, FUNCTION_NAMES_STATISTICAL.AVERAGE],diff --git a/packages/engine-formula/src/functions/statistical/max/max.ts b/packages/engine-formula/src/functions/statistical/max/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/statistical/max/max.tsrename to packages/engine-formula/src/functions/statistical/max/index.tsdiff --git a/packages/engine-formula/src/functions/statistical/min/min.ts b/packages/engine-formula/src/functions/statistical/min/index.tssimilarity index 100%rename from packages/engine-formula/src/functions/statistical/min/min.tsrename to packages/engine-formula/src/functions/statistical/min/index.tsdiff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.tsindex 6d0ba512ef..9f20a36615 100644--- a/packages/sheets-formula/src/controllers/prompt.controller.ts+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts@@ -553,7 +553,7 @@ export class PromptController extends Disposable {if (this._inputPanelState === InputPanelState.keyNormal) {// show search function panel- const searchList = this._descriptionService.getSearchListByName(token);+ const searchList = this._descriptionService.getSearchListByNameFirstLetter(token);this._hideFunctionPanel();if (searchList == null || searchList.length === 0) {return;diff --git a/packages/sheets-formula/src/locale/function-list/math/en-US.ts b/packages/sheets-formula/src/locale/function-list/math/en-US.tsindex 59b7f3a62d..77544f8c5e 100644--- a/packages/sheets-formula/src/locale/function-list/math/en-US.ts+++ b/packages/sheets-formula/src/locale/function-list/math/en-US.ts@@ -16,7 +16,7 @@export default {ABS: {- description: `Returns the absolute value of a number`,+ description: `Returns the absolute value of a number. The absolute value of a number is the number without its sign.`,abstract: `Returns the absolute value of a number`,links: [{@@ -25,12 +25,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The real number of which you want the absolute value.' },},},ACOS: {- description: `Returns the arccosine of a number`,+ description: `Returns the arccosine, or inverse cosine, of a number. The arccosine is the angle whose cosine is number. The returned angle is given in radians in the range 0 (zero) to pi.`,abstract: `Returns the arccosine of a number`,links: [{@@ -39,12 +38,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The cosine of the angle you want and must be from -1 to 1.' },},},ACOSH: {- description: `Returns the inverse hyperbolic cosine of a number`,+ description: `Returns the inverse hyperbolic cosine of a number. The number must be greater than or equal to 1. The inverse hyperbolic cosine is the value whose hyperbolic cosine is number, so ACOSH(COSH(number)) equals number.`,abstract: `Returns the inverse hyperbolic cosine of a number`,links: [{@@ -53,12 +51,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'Any real number equal to or greater than 1.' },},},ACOT: {- description: `Returns the arccotangent of a number`,+ description: `Returns the principal value of the arccotangent, or inverse cotangent, of a number.`,abstract: `Returns the arccotangent of a number`,links: [{@@ -67,8 +64,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: {+ name: 'number',+ detail: 'Number is the cotangent of the angle you want. This must be a real number.',+ },},},ACOTH: {diff --git a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/math/ja-JP.tsindex 70b7a0c88f..d848afa28b 100644--- a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts+++ b/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts@@ -16,7 +16,7 @@export default {ABS: {- description: `数値の絶対値を返します。`,+ description: `数値の絶対値を返します。 絶対値とは、数値から符号 (+、-) を除いた数の大きさのことです。`,abstract: `数値の絶対値を返します。`,links: [{@@ -25,12 +25,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '絶対値が必要な実数。' },},},ACOS: {- description: `数値のアークコサインを返します。`,+ description: `数値のアークコサイン (逆余弦) を返します。 アークコサインとは、そのコサインが数値となる角度のことです。 戻り値の角度は、0 (ゼロ) ~ pi の範囲内のラジアンで示されます。`,abstract: `数値のアークコサインを返します。`,links: [{@@ -39,12 +38,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '求める角度のコサインの値を、-1 ~ 1 の範囲で指定します。' },},},ACOSH: {- description: `数値の双曲線逆余弦 (ハイパーボリック コサインの逆関数) を返します。`,+ description: `数値の逆双曲線コサインを返します。 数値は 1 以上である必要があります。 逆双曲線コサインは、双曲線コサインが 数値の値なので、ACOSH(COSH(number)) は数値と等 しくなります。`,abstract: `数値の双曲線逆余弦 (ハイパーボリック コサインの逆関数) を返します。`,links: [{@@ -53,12 +51,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '1 以上の実数を指定します。' },},},ACOT: {- description: `数値の逆余接を返します。`,+ description: `コタンジェント、または逆コタンジェント、数値の主値を返します。`,abstract: `数値の逆余接を返します。`,links: [{@@ -67,8 +64,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: {+ name: '数値',+ detail: '数値は、求める角度のコタンジェントです。 これは実数である必要があります。',+ },},},ACOTH: {diff --git a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/math/zh-CN.tsindex 7a9c00e114..a8ed901aa7 100644--- a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts+++ b/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts@@ -16,7 +16,7 @@export default {ABS: {- description: '返回数字的绝对值',+ description: '返回数字的绝对值。一个数字的绝对值是该数字不带其符号的形式。',abstract: '返回数字的绝对值',links: [{@@ -25,12 +25,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '需要计算其绝对值的实数。' },},},ACOS: {- description: '返回数字的反余弦值',+ description:+ '返回数字的反余弦值。 反余弦值是指余弦值为 number 的角度。 返回的角度以弧度表示,弧度值在 0(零)到 pi 之间。',abstract: '返回数字的反余弦值',links: [{@@ -39,12 +39,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '所求角度的余弦值,必须介于 -1 到 1 之间。' },},},ACOSH: {- description: '返回数字的反双曲余弦值',+ description:+ '返回数字的反双曲余弦值。 该数字必须大于或等于 1。 反双曲余弦值是指双曲余弦值为 number 的值,因此 ACOSH(COSH(number)) 等于 number。',abstract: '返回数字的反双曲余弦值',links: [{@@ -53,12 +53,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '大于或等于 1 的任意实数。' },},},ACOT: {- description: '返回一个数的反余切值',+ description: '返回数字的反余切值的主值。',abstract: '返回一个数的反余切值',links: [{@@ -67,8 +66,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: 'Number 是需要的角度的正切值。 这必须是实数。' },},},ACOTH: {diff --git a/packages/sheets-formula/src/services/description.service.ts b/packages/sheets-formula/src/services/description.service.tsindex 1e1fd0cd42..a1052cf07f 100644--- a/packages/sheets-formula/src/services/description.service.ts+++ b/packages/sheets-formula/src/services/description.service.ts@@ -49,6 +49,13 @@ export interface IDescriptionService {*/getSearchListByName(searchText: string): ISearchItem[];+ /**+ * get search list by name, from first letter+ * @param searchText+ * @returns+ */+ getSearchListByNameFirstLetter(searchText: string): ISearchItem[];+/*** get search list by type, if type is -1, return all* @param type@@ -101,6 +108,20 @@ export class DescriptionService implements IDescriptionService, IDisposable {return searchList;}+ getSearchListByNameFirstLetter(searchText: string) {+ const searchList: ISearchItem[] = [];+ const functionList = this._functionService.getDescriptions();+ searchText = searchText.toLocaleUpperCase();+ functionList.forEach((item) => {+ const { functionName, abstract } = item;+ if (functionName.indexOf(searchText) === 0) {+ searchList.push({ name: functionName, desc: abstract });+ }+ });++ return searchList;+ }+getSearchListByType(type: number) {const searchList: ISearchItem[] = [];const functionList = this._functionService.getDescriptions();diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.tsindex 93bf39d811..dbb5773ad7 100644--- a/packages/sheets-formula/src/services/function-list/math.ts+++ b/packages/sheets-formula/src/services/function-list/math.ts@@ -18,6 +18,66 @@ import type { IFunctionInfo } from '@univerjs/engine-formula';import { FUNCTION_NAMES_MATH, FunctionType } from '@univerjs/engine-formula';export const FUNCTION_LIST_MATH: IFunctionInfo[] = [+ {+ functionName: FUNCTION_NAMES_MATH.ABS,+ functionType: FunctionType.Math,+ description: 'formula.functionList.ABS.description',+ abstract: 'formula.functionList.ABS.abstract',+ functionParameter: [+ {+ name: 'formula.functionList.ABS.functionParameter.number.name',+ detail: 'formula.functionList.ABS.functionParameter.number.detail',+ example: 'A1:A20',+ require: 1,+ repeat: 0,+ },+ ],+ },+ {+ functionName: FUNCTION_NAMES_MATH.ACOS,+ functionType: FunctionType.Math,+ description: 'formula.functionList.ACOS.description',+ abstract: 'formula.functionList.ACOS.abstract',+ functionParameter: [+ {+ name: 'formula.functionList.ACOS.functionParameter.number.name',+ detail: 'formula.functionList.ACOS.functionParameter.number.detail',+ example: 'A1:A20',+ require: 1,+ repeat: 0,+ },+ ],+ },+ {+ functionName: FUNCTION_NAMES_MATH.ACOSH,+ functionType: FunctionType.Math,+ description: 'formula.functionList.ACOSH.description',+ abstract: 'formula.functionList.ACOSH.abstract',+ functionParameter: [+ {+ name: 'formula.functionList.ACOSH.functionParameter.number.name',+ detail: 'formula.functionList.ACOSH.functionParameter.number.detail',+ example: 'A1:A20',+ require: 1,+ repeat: 0,+ },+ ],+ },+ {+ functionName: FUNCTION_NAMES_MATH.ACOT,+ functionType: FunctionType.Math,+ description: 'formula.functionList.ACOT.description',+ abstract: 'formula.functionList.ACOT.abstract',+ functionParameter: [+ {+ name: 'formula.functionList.ACOT.functionParameter.number.name',+ detail: 'formula.functionList.ACOT.functionParameter.number.detail',+ example: 'A1:A20',+ require: 1,+ repeat: 0,+ },+ ],+ },{functionName: FUNCTION_NAMES_MATH.SUM,aliasFunctionName: 'formula.functionList.SUM.aliasFunctionName',