Skip to content

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

feat(formula): add logical functions (#2644)

Hossein-Khan3e3e5723a04f
diff --git a/packages/engine-formula/src/functions/logical/false/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/false/__tests__/index.spec.ts
new file mode 100644
index 0000000000..75dc939fac
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/false/__tests__/index.spec.ts
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
+import { False } from '../index';
+
+describe('Test false function', () => {
+ const textFunction = new False(FUNCTION_NAMES_LOGICAL.FALSE);
+
+ describe('False', () => {
+ it('should return false', () => {
+ const result = textFunction.calculate();
+ expect(result.getValue()).toBe(false);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/logical/false/index.ts b/packages/engine-formula/src/functions/logical/false/index.ts
new file mode 100644
index 0000000000..40cedc18ff
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/false/index.ts
@@ -0,0 +1,28 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class False extends BaseFunction {
+ override minParams = 0;
+
+ override maxParams = 0;
+
+ override calculate() {
+ return BooleanValueObject.create(false);
+ }
+}
diff --git a/packages/engine-formula/src/functions/logical/function-map.ts b/packages/engine-formula/src/functions/logical/function-map.ts
index 40fb16a3af..9aaed9e954 100644
--- a/packages/engine-formula/src/functions/logical/function-map.ts
+++ b/packages/engine-formula/src/functions/logical/function-map.ts
@@ -15,18 +15,32 @@
*/
import { And } from './and';
+import { False } from './false';
import { FUNCTION_NAMES_LOGICAL } from './function-names';
import { If } from './if';
import { Iferror } from './iferror';
+import { Ifna } from './ifna';
+import { Ifs } from './ifs';
import { Lambda } from './lambda';
import { Makearray } from './makearray';
+import { Not } from './not';
import { Or } from './or';
+import { Switch } from './switch';
+import { True } from './true';
+import { Xor } from './xor';
export const functionLogical = [
[And, FUNCTION_NAMES_LOGICAL.AND],
+ [False, FUNCTION_NAMES_LOGICAL.FALSE],
[If, FUNCTION_NAMES_LOGICAL.IF],
+ [Ifna, FUNCTION_NAMES_LOGICAL.IFNA],
+ [Ifs, FUNCTION_NAMES_LOGICAL.IFS],
[Lambda, FUNCTION_NAMES_LOGICAL.LAMBDA],
[Makearray, FUNCTION_NAMES_LOGICAL.MAKEARRAY],
+ [Not, FUNCTION_NAMES_LOGICAL.NOT],
[Or, FUNCTION_NAMES_LOGICAL.OR],
[Iferror, FUNCTION_NAMES_LOGICAL.IFERROR],
+ [Switch, FUNCTION_NAMES_LOGICAL.SWITCH],
+ [True, FUNCTION_NAMES_LOGICAL.TRUE],
+ [Xor, FUNCTION_NAMES_LOGICAL.XOR],
];
diff --git a/packages/engine-formula/src/functions/logical/ifna/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/ifna/__tests__/index.spec.ts
new file mode 100644
index 0000000000..6f09b9a5d8
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/ifna/__tests__/index.spec.ts
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
+import { Ifna } from '../index';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test ifna function', () => {
+ const textFunction = new Ifna(FUNCTION_NAMES_LOGICAL.IFNA);
+
+ describe('Ifna', () => {
+ it('Value is normal', () => {
+ const value = NumberValueObject.create(1);
+ const valueIfNa = StringValueObject.create('N/A');
+ const result = textFunction.calculate(value, valueIfNa);
+ expect(result.getValue()).toBe(1);
+ });
+
+ it('Value is #N/A error', () => {
+ const value = ErrorValueObject.create(ErrorType.NA);
+ const valueIfNa = StringValueObject.create('N/A');
+ const result = textFunction.calculate(value, valueIfNa);
+ expect(result.getValue()).toBe('N/A');
+ });
+
+ it('Value is another error type', () => {
+ const value = ErrorValueObject.create(ErrorType.VALUE);
+ const valueIfNa = StringValueObject.create('N/A');
+ const result = textFunction.calculate(value, valueIfNa);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Value is array with #N/A error', () => {
+ const value = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1],
+ ['#N/A'],
+ [3],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const valueIfNa = StringValueObject.create('N/A');
+ const result = textFunction.calculate(value, valueIfNa);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [1],
+ ['N/A'],
+ [3],
+ ]);
+ });
+
+ it('Value is array and valueIfNa is array', () => {
+ const value = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1, '#N/A', 3],
+ ['#N/A', 5, '#N/A'],
+ ]),
+ rowCount: 2,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const valueIfNa = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['a1', 'a2', 'a3'],
+ ['b1', 'b2', 'b3'],
+ ]),
+ rowCount: 2,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(value, valueIfNa);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [1, 'a2', 3],
+ ['b1', 5, 'b3'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/logical/ifna/index.ts b/packages/engine-formula/src/functions/logical/ifna/index.ts
new file mode 100644
index 0000000000..38d29d3ced
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/ifna/index.ts
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BaseFunction } from '../../base-function';
+import { ErrorType } from '../../../basics/error-type';
+
+export class Ifna extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 2;
+
+ override calculate(value: BaseValueObject, valueIfNa: BaseValueObject) {
+ if (value.isError() && (value as ErrorValueObject).getErrorType() !== ErrorType.NA) {
+ return value;
+ }
+
+ if (valueIfNa.isError()) {
+ return valueIfNa;
+ }
+
+ if (!value.isArray()) {
+ return value.isError() && (value as ErrorValueObject).getErrorType() === ErrorType.NA ? valueIfNa : value;
+ }
+
+ // get max row length
+ const maxRowLength = Math.max(
+ value.isArray() ? (value as ArrayValueObject).getRowCount() : 1,
+ valueIfNa.isArray() ? (valueIfNa as ArrayValueObject).getRowCount() : 1
+ );
+
+ // get max column length
+ const maxColumnLength = Math.max(
+ value.isArray() ? (value as ArrayValueObject).getColumnCount() : 1,
+ valueIfNa.isArray() ? (valueIfNa as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const valueArray = expandArrayValueObject(maxRowLength, maxColumnLength, value);
+ const valueIfNaArray = expandArrayValueObject(maxRowLength, maxColumnLength, valueIfNa);
+
+ valueArray.iterator((cellValue, rowIndex, columnIndex) => {
+ if (cellValue?.isError() && (cellValue as ErrorValueObject).getErrorType() === ErrorType.NA) {
+ valueArray.set(rowIndex, columnIndex, valueIfNaArray.get(rowIndex, columnIndex));
+ }
+ });
+
+ return valueArray;
+ }
+}
diff --git a/packages/engine-formula/src/functions/logical/ifs/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/ifs/__tests__/index.spec.ts
new file mode 100644
index 0000000000..7015991c9c
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/ifs/__tests__/index.spec.ts
@@ -0,0 +1,208 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
+import { Ifs } from '../index';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { BooleanValueObject, NullValueObject, NumberValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test ifs function', () => {
+ const textFunction = new Ifs(FUNCTION_NAMES_LOGICAL.IFS);
+
+ describe('Ifs', () => {
+ it('Single condition true', () => {
+ const condition1 = BooleanValueObject.create(true);
+ const result1 = NumberValueObject.create(1);
+ const result = textFunction.calculate(condition1, result1);
+ expect(result.getValue()).toBe(1);
+ });
+
+ it('Single condition false', () => {
+ const condition1 = BooleanValueObject.create(false);
+ const result1 = NumberValueObject.create(1);
+ const result = textFunction.calculate(condition1, result1);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Multiple conditions first true', () => {
+ const condition1 = BooleanValueObject.create(true);
+ const result1 = NumberValueObject.create(1);
+ const condition2 = BooleanValueObject.create(false);
+ const result2 = NumberValueObject.create(2);
+ const result = textFunction.calculate(condition1, result1, condition2, result2);
+ expect(result.getValue()).toBe(1);
+ });
+
+ it('Multiple conditions second true', () => {
+ const condition1 = BooleanValueObject.create(false);
+ const result1 = NumberValueObject.create(1);
+ const condition2 = BooleanValueObject.create(true);
+ const result2 = NumberValueObject.create(2);
+ const result = textFunction.calculate(condition1, result1, condition2, result2);
+ expect(result.getValue()).toBe(2);
+ });
+
+ it('All conditions false', () => {
+ const condition1 = BooleanValueObject.create(false);
+ const result1 = NumberValueObject.create(1);
+ const condition2 = BooleanValueObject.create(false);
+ const result2 = NumberValueObject.create(2);
+ const result = textFunction.calculate(condition1, result1, condition2, result2);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Condition is array', () => {
+ const condition1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [false],
+ [true],
+ [false],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result1 = NumberValueObject.create(1);
+ const result = textFunction.calculate(condition1, result1);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [ErrorType.NA],
+ [1],
+ [ErrorType.NA],
+ ]);
+ });
+
+ it('Multiple conditions as arrays', () => {
+ const condition1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [false],
+ [true],
+ [false],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result1 = NumberValueObject.create(1);
+ const condition2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [false],
+ [true],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = NumberValueObject.create(2);
+ const result = textFunction.calculate(condition1, result1, condition2, result2);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [2],
+ [1],
+ [2],
+ ]);
+ });
+
+ it('Conditions and results are arrays', () => {
+ const condition1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [false, true],
+ [true, false],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1, 2],
+ [3, 4],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const condition2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true, false],
+ [false, true],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [5, 6],
+ [7, 8],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(condition1, result1, condition2, result2);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ [5, 2],
+ [3, 8],
+ ]);
+ });
+
+ it('Handles null values correctly', () => {
+ const condition1 = NullValueObject.create();
+ const result1 = NumberValueObject.create(1);
+ const result = textFunction.calculate(condition1, result1);
+ expect(result.getValue()).toBe(ErrorType.NA);
+ });
+
+ it('Handles error values in conditions', () => {
+ const condition1 = ErrorValueObject.create(ErrorType.VALUE);
+ const result1 = NumberValueObject.create(1);
+ const result = textFunction.calculate(condition1, result1);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Handles error values in results', () => {
+ const condition1 = BooleanValueObject.create(true);
+ const result1 = ErrorValueObject.create(ErrorType.VALUE);
+ const result = textFunction.calculate(condition1, result1);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/logical/ifs/index.ts b/packages/engine-formula/src/functions/logical/ifs/index.ts
new file mode 100644
index 0000000000..6884b06e99
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/ifs/index.ts
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NullValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Ifs extends BaseFunction {
+ override minParams = 2;
+
+ override maxParams = 255;
+
+ override calculate(...params: BaseValueObject[]) {
+ if (params.length % 2 !== 0) {
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ // Check for errors in input parameters
+ for (let i = 0; i < params.length; i++) {
+ if (params[i].isError()) {
+ return params[i];
+ }
+ }
+
+ if (!params.some((param) => param.isArray())) {
+ // Handle non-array inputs
+ for (let i = 0; i < params.length; i += 2) {
+ const condition = params[i];
+ const result = params[i + 1];
+
+ if (condition.isNull()) {
+ continue;
+ }
+
+ const conditionValue = condition.getValue();
+ if (conditionValue) {
+ return result.isNull() ? ErrorValueObject.create(ErrorType.NA) : result;
+ }
+ }
+ return ErrorValueObject.create(ErrorType.NA);
+ }
+
+ // Determine max row and column length
+ const maxRowLength = Math.max(
+ ...params.map((param) => (param.isArray() ? (param as ArrayValueObject).getRowCount() : 1))
+ );
+ const maxColumnLength = Math.max(
+ ...params.map((param) => (param.isArray() ? (param as ArrayValueObject).getColumnCount() : 1))
+ );
+
+ // Expand all array values to the same size
+ const expandedParams = params.map((param) =>
+ expandArrayValueObject(maxRowLength, maxColumnLength, param, ErrorValueObject.create(ErrorType.NA))
+ );
+
+ return expandedParams[0].map((_, rowIndex, columnIndex) => {
+ for (let i = 0; i < expandedParams.length; i += 2) {
+ const condition = expandedParams[i].get(rowIndex, columnIndex) || NullValueObject.create();
+ const result = expandedParams[i + 1].get(rowIndex, columnIndex) || NullValueObject.create();
+
+ if (condition.isNull()) {
+ continue;
+ }
+
+ if (condition.isError()) {
+ return condition;
+ }
+
+ const conditionValue = condition.getValue();
+ if (conditionValue) {
+ return result.isNull() ? ErrorValueObject.create(ErrorType.NA) : result;
+ }
+ }
+ return ErrorValueObject.create(ErrorType.NA);
+ });
+ }
+}
diff --git a/packages/engine-formula/src/functions/logical/not/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/not/__tests__/index.spec.ts
new file mode 100644
index 0000000000..a637028564
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/not/__tests__/index.spec.ts
@@ -0,0 +1,117 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
+import { Not } from '../index';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test not function', () => {
+ const textFunction = new Not(FUNCTION_NAMES_LOGICAL.NOT);
+
+ describe('Not', () => {
+ it('logical string', () => {
+ const logical = StringValueObject.create('a1');
+ const result = textFunction.calculate(logical);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('logical number 1', () => {
+ const logical = NumberValueObject.create(1);
+ const result = textFunction.calculate(logical);
+ expect(result.getValue()).toBe(false);
+ });
+
+ it('logical number 0', () => {
+ const logical = NumberValueObject.create(0);
+ const result = textFunction.calculate(logical);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('logical null', () => {
+ const logical = NullValueObject.create();
+ const result = textFunction.calculate(logical);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('logical true', () => {
+ const logical = BooleanValueObject.create(true);
+ const result = textFunction.calculate(logical);
+ expect(result.getValue()).toBe(false);
+ });
+
+ it('logical false', () => {
+ const logical = BooleanValueObject.create(false);
+ const result = textFunction.calculate(logical);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('logical is array, no logical value', () => {
+ const logical = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['a1'],
+ ['a2'],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(logical);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([[ErrorType.VALUE], [ErrorType.VALUE]]);
+ });
+
+ it('logical is array with logical values', () => {
+ const logical = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [false],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(logical);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([[false], [true]]);
+ });
+
+ it('logical is array with mixed values', () => {
+ const logical = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ [1],
+ ['a1'],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(logical);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([[false], [false], [ErrorType.VALUE]]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/logical/not/index.ts b/packages/engine-formula/src/functions/logical/not/index.ts
new file mode 100644
index 0000000000..bb0a825d4d
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/not/index.ts
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Not extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 1;
+
+ override calculate(logicalValue: BaseValueObject) {
+ if (logicalValue.isError()) {
+ return logicalValue;
+ }
+
+ if (logicalValue.isArray()) {
+ const resultArray = (logicalValue as ArrayValueObject).map((value) => {
+ if (value?.isError()) {
+ return value;
+ } else if (value?.isBoolean() || value?.isNumber()) {
+ return BooleanValueObject.create(!value.getValue());
+ } else {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+ });
+ return resultArray;
+ } else if (logicalValue.isBoolean() || logicalValue.isNumber()) {
+ return BooleanValueObject.create(!logicalValue.getValue());
+ } else {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+ }
+}
diff --git a/packages/engine-formula/src/functions/logical/switch/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/switch/__tests__/index.spec.ts
new file mode 100644
index 0000000000..0d058bfbb2
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/switch/__tests__/index.spec.ts
@@ -0,0 +1,176 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
+import { Switch } from '../index';
+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
+import { ErrorType } from '../../../../basics/error-type';
+
+describe('Test switch function', () => {
+ const textFunction = new Switch(FUNCTION_NAMES_LOGICAL.SWITCH);
+
+ describe('Switch', () => {
+ it('Single condition true', () => {
+ const expression = NumberValueObject.create(1);
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1);
+ expect(result.getValue()).toBe('One');
+ });
+
+ it('Single condition false with default', () => {
+ const expression = NumberValueObject.create(2);
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const defaultValue = StringValueObject.create('Default');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, defaultValue);
+ expect(result.getValue()).toBe('Default');
+ });
+
+ it('Multiple conditions with matching value', () => {
+ const expression = NumberValueObject.create(2);
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const switchValue2 = NumberValueObject.create(2);
+ const resultValue2 = StringValueObject.create('Two');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, switchValue2, resultValue2);
+ expect(result.getValue()).toBe('Two');
+ });
+
+ it('Multiple conditions without matching value, with default', () => {
+ const expression = NumberValueObject.create(3);
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const switchValue2 = NumberValueObject.create(2);
+ const resultValue2 = StringValueObject.create('Two');
+ const defaultValue = StringValueObject.create('Default');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, switchValue2, resultValue2, defaultValue);
+ expect(result.getValue()).toBe('Default');
+ });
+
+ it('Condition is array', () => {
+ const expression = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1],
+ [2],
+ [3],
+ ]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const switchValue2 = NumberValueObject.create(2);
+ const resultValue2 = StringValueObject.create('Two');
+ const defaultValue = StringValueObject.create('Default');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, switchValue2, resultValue2, defaultValue);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['One'],
+ ['Two'],
+ ['Default'],
+ ]);
+ });
+
+ it('Handles null values correctly', () => {
+ const expression = NullValueObject.create();
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const defaultValue = StringValueObject.create('Default');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, defaultValue);
+ expect(result.getValue()).toBe('Default');
+ });
+
+ it('Handles error values in expression', () => {
+ const expression = ErrorValueObject.create(ErrorType.VALUE);
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const defaultValue = StringValueObject.create('Default');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, defaultValue);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Handles error values in switch values', () => {
+ const expression = NumberValueObject.create(1);
+ const switchValue1 = ErrorValueObject.create(ErrorType.VALUE);
+ const resultValue1 = StringValueObject.create('One');
+ const defaultValue = StringValueObject.create('Default');
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, defaultValue);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('Handles arrays of different sizes', () => {
+ const expression = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1, 2],
+ [3, 4],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const switchValue2 = NumberValueObject.create(2);
+ const resultValue2 = StringValueObject.create('Two');
+ const defaultValue = StringValueObject.create('Default');
+
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, switchValue2, resultValue2, defaultValue);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['One', 'Two'],
+ ['Default', 'Default'],
+ ]);
+ });
+
+ it('Handles arrays with null and error values', () => {
+ const expression = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [1, null],
+ [ErrorType.VALUE, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 2,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ const switchValue1 = NumberValueObject.create(1);
+ const resultValue1 = StringValueObject.create('One');
+ const switchValue2 = NumberValueObject.create(2);
+ const resultValue2 = StringValueObject.create('Two');
+ const defaultValue = StringValueObject.create('Default');
+
+ const result = textFunction.calculate(expression, switchValue1, resultValue1, switchValue2, resultValue2, defaultValue);
+ expect(transformToValue(result.getArrayValue())).toStrictEqual([
+ ['One', 'Default'],
+ [ErrorType.VALUE, 'Two'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/logical/switch/index.ts b/packages/engine-formula/src/functions/logical/switch/index.ts
new file mode 100644
index 0000000000..1cacb40717
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/switch/index.ts
@@ -0,0 +1,104 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import { expandArrayValueObject } from '../../../engine/utils/array-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { NullValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Switch extends BaseFunction {
+ override minParams = 3;
+
+ override calculate(expression: BaseValueObject, ...args: BaseValueObject[]) {
+ if (expression.isError()) {
+ return expression;
+ }
+
+ const hasDefault = args.length % 2 !== 0;
+ const defaultValue = hasDefault ? args[args.length - 1] : NullValueObject.create();
+
+ if (!expression.isArray() && !args.some((arg) => arg.isArray())) {
+ return this._handleNonArrayInputs(expression, args, defaultValue, hasDefault);
+ }
+
+ return this._handleArrayInputs(expression, args, defaultValue, hasDefault);
+ }
+
+ private _handleNonArrayInputs(expression: BaseValueObject, args: BaseValueObject[], defaultValue: BaseValueObject, hasDefault: boolean) {
+ for (let i = 0; i < args.length - (hasDefault ? 1 : 0); i += 2) {
+ const switchValue = args[i];
+ const resultValue = args[i + 1];
+
+ if (switchValue.isNull()) {
+ continue;
+ }
+
+ if (switchValue.isError()) {
+ return switchValue;
+ }
+
+ if (expression.getValue() === switchValue.getValue()) {
+ return resultValue.isNull() ? ErrorValueObject.create(ErrorType.NA) : resultValue;
+ }
+ }
+
+ return defaultValue.isNull() ? ErrorValueObject.create(ErrorType.NA) : defaultValue;
+ }
+
+ private _handleArrayInputs(expression: BaseValueObject, args: BaseValueObject[], defaultValue: BaseValueObject, hasDefault: boolean) {
+ const maxRowLength = Math.max(
+ expression.isArray() ? (expression as ArrayValueObject).getRowCount() : 1,
+ ...args.map((arg) => (arg.isArray() ? (arg as ArrayValueObject).getRowCount() : 1)),
+ defaultValue.isArray() ? (defaultValue as ArrayValueObject).getRowCount() : 1
+ );
+
+ const maxColumnLength = Math.max(
+ expression.isArray() ? (expression as ArrayValueObject).getColumnCount() : 1,
+ ...args.map((arg) => (arg.isArray() ? (arg as ArrayValueObject).getColumnCount() : 1)),
+ defaultValue.isArray() ? (defaultValue as ArrayValueObject).getColumnCount() : 1
+ );
+
+ const expandedExpression = expandArrayValueObject(maxRowLength, maxColumnLength, expression);
+ const expandedArgs = args.map((arg) =>
+ expandArrayValueObject(maxRowLength, maxColumnLength, arg, ErrorValueObject.create(ErrorType.NA))
+ );
+ const expandedDefault = expandArrayValueObject(maxRowLength, maxColumnLength, defaultValue, ErrorValueObject.create(ErrorType.NA));
+
+ return expandedExpression.map((expValue, rowIndex, columnIndex) => {
+ for (let i = 0; i < expandedArgs.length - (hasDefault ? 1 : 0); i += 2) {
+ const switchValue = expandedArgs[i].get(rowIndex, columnIndex) || NullValueObject.create();
+ const resultValue = expandedArgs[i + 1].get(rowIndex, columnIndex) || NullValueObject.create();
+
+ if (switchValue.isNull()) {
+ continue;
+ }
+
+ if (switchValue.isError() || expValue.isError()) {
+ return switchValue.isError() ? switchValue : expValue;
+ }
+
+ if (expValue.getValue() === switchValue.getValue()) {
+ return resultValue.isNull() ? ErrorValueObject.create(ErrorType.NA) : resultValue;
+ }
+ }
+
+ const defaultCellValue = expandedDefault.get(rowIndex, columnIndex) || NullValueObject.create();
+ return defaultCellValue.isNull() ? ErrorValueObject.create(ErrorType.NA) : defaultCellValue;
+ });
+ }
+}
diff --git a/packages/engine-formula/src/functions/logical/true/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/true/__tests__/index.spec.ts
new file mode 100644
index 0000000000..74b2d31a14
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/true/__tests__/index.spec.ts
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
+import { True } from '../index';
+
+describe('Test true function', () => {
+ const textFunction = new True(FUNCTION_NAMES_LOGICAL.TRUE);
+
+ describe('True', () => {
+ it('should return true', () => {
+ const result = textFunction.calculate();
+ expect(result.getValue()).toBe(true);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/logical/true/index.ts b/packages/engine-formula/src/functions/logical/true/index.ts
new file mode 100644
index 0000000000..bbd82313ad
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/true/index.ts
@@ -0,0 +1,28 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class True extends BaseFunction {
+ override minParams = 0;
+
+ override maxParams = 0;
+
+ override calculate() {
+ return BooleanValueObject.create(true);
+ }
+}
diff --git a/packages/engine-formula/src/functions/logical/xor/__tests__/index.spec.ts b/packages/engine-formula/src/functions/logical/xor/__tests__/index.spec.ts
new file mode 100644
index 0000000000..cc1de0064f
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/xor/__tests__/index.spec.ts
@@ -0,0 +1,155 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { describe, expect, it } from 'vitest';
+
+import { FUNCTION_NAMES_LOGICAL } from '../../function-names';
+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
+import { ErrorType } from '../../../../basics/error-type';
+import { Xor } from '../index';
+
+describe('Test xor function', () => {
+ const textFunction = new Xor(FUNCTION_NAMES_LOGICAL.XOR);
+
+ describe('Xor', () => {
+ it('logical1 string', () => {
+ const logical1 = StringValueObject.create('a1');
+ const result = textFunction.calculate(logical1);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('logical1 number 1', () => {
+ const logical1 = NumberValueObject.create(1);
+ const result = textFunction.calculate(logical1);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('logical1 number 0', () => {
+ const logical1 = NumberValueObject.create(0);
+ const result = textFunction.calculate(logical1);
+ expect(result.getValue()).toBe(false);
+ });
+
+ it('logical1 null', () => {
+ const logical1 = NullValueObject.create();
+ const result = textFunction.calculate(logical1);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('logical1 true', () => {
+ const logical1 = BooleanValueObject.create(true);
+ const result = textFunction.calculate(logical1);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('logical1 true and logical2 false', () => {
+ const logical1 = BooleanValueObject.create(true);
+ const logical2 = BooleanValueObject.create(false);
+ const result = textFunction.calculate(logical1, logical2);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('logical1 false and logical2 false', () => {
+ const logical1 = BooleanValueObject.create(false);
+ const logical2 = BooleanValueObject.create(false);
+ const result = textFunction.calculate(logical1, logical2);
+ expect(result.getValue()).toBe(false);
+ });
+
+ it('logical1 true and logical2 true', () => {
+ const logical1 = BooleanValueObject.create(true);
+ const logical2 = BooleanValueObject.create(true);
+ const result = textFunction.calculate(logical1, logical2);
+ expect(result.getValue()).toBe(false);
+ });
+
+ it('logical1 is array, no logical value', () => {
+ const logical1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['a1'],
+ ['a2'],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(logical1);
+ expect(result.getValue()).toBe(ErrorType.VALUE);
+ });
+
+ it('logical1 is array and logical2 is array', () => {
+ const logical1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['a1'],
+ ['a2'],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const logical2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [true],
+ ['a4'],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(logical1, logical2);
+ expect(result.getValue()).toBe(true);
+ });
+
+ it('logical1 is array and logical2 is array, error value', () => {
+ const logical1 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ ['a1'],
+ ['a2'],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const logical2 = ArrayValueObject.create({
+ calculateValueList: transformToValueObject([
+ [false],
+ ['#NAME?'],
+ ]),
+ rowCount: 2,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const result = textFunction.calculate(logical1, logical2);
+ expect(result.getValue()).toBe('#NAME?');
+ });
+ });
+});
diff --git a/packages/engine-formula/src/functions/logical/xor/index.ts b/packages/engine-formula/src/functions/logical/xor/index.ts
new file mode 100644
index 0000000000..35cfeb6059
--- /dev/null
+++ b/packages/engine-formula/src/functions/logical/xor/index.ts
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ErrorType } from '../../../basics/error-type';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';
+import { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
+
+export class Xor extends BaseFunction {
+ override minParams = 1;
+
+ override maxParams = 255;
+
+ override calculate(...logicalValues: BaseValueObject[]) {
+ let trueCount = 0;
+ let noBoolean = true;
+ let errorValue = null;
+
+ for (const logicalValue of logicalValues) {
+ if (logicalValue.isError()) {
+ return logicalValue;
+ }
+
+ if (logicalValue.isArray()) {
+ (logicalValue as ArrayValueObject).iterator((value) => {
+ if (value?.isError()) {
+ errorValue = value;
+ return false;
+ } else if (value?.isBoolean() || value?.isNumber()) {
+ if (value.getValue()) {
+ trueCount++;
+ }
+ noBoolean = false;
+ }
+ });
+
+ if (errorValue) {
+ return errorValue;
+ }
+ } else if (logicalValue.isBoolean() || logicalValue.isNumber()) {
+ if (logicalValue.getValue()) {
+ trueCount++;
+ }
+ noBoolean = false;
+ }
+ }
+
+ return noBoolean ? ErrorValueObject.create(ErrorType.VALUE) : BooleanValueObject.create(trueCount % 2 === 1);
+ }
+}
diff --git a/packages/sheets-formula/src/locale/function-list/logical/en-US.ts b/packages/sheets-formula/src/locale/function-list/logical/en-US.ts
index 2262a4c8e3..fed8f92c2e 100644
--- a/packages/sheets-formula/src/locale/function-list/logical/en-US.ts
+++ b/packages/sheets-formula/src/locale/function-list/logical/en-US.ts
@@ -58,18 +58,15 @@ export default {
},
},
FALSE: {
- description: 'Returns the logical value FALSE',
- abstract: 'Returns the logical value FALSE',
+ description: 'Returns the logical value FALSE.',
+ abstract: 'Returns the logical value FALSE.',
links: [
{
title: 'Instruction',
url: 'https://support.microsoft.com/en-us/office/false-function-2d58dfa5-9c03-4259-bf8f-f0ae14346904',
},
],
- functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
- },
+ functionParameter: {},
},
IF: {
description: 'Specifies a logical test to perform',
@@ -116,8 +113,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: 'value', detail: 'The argument that is checked for the #N/A error value.' },
+ valueIfNa: { name: 'value_if_na', detail: 'The value to return if the formula evaluates to the #N/A error value.' },
},
},
IFS: {
@@ -130,8 +127,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logicalTest1: { name: 'logical_test1', detail: 'Condition that evaluates to TRUE or FALSE.' },
+ valueIfTrue1: { name: 'value_if_true1', detail: 'Result to be returned if logical_test1 evaluates to TRUE. Can be empty.' },
+ logicalTest2: { name: 'logical_test2...logical_test127', detail: 'Condition that evaluates to TRUE or FALSE.' },
+ valueIfTrue2: { name: 'value_if_true2...value_if_true127', detail: 'Result to be returned if logical_testN evaluates to TRUE. Each value_if_trueN corresponds with a condition logical_testN. Can be empty.' },
},
},
LAMBDA: {
@@ -201,8 +200,8 @@ export default {
},
},
NOT: {
- description: 'Reverses the logic of its argument',
- abstract: 'Reverses the logic of its argument',
+ description: 'Reverses the logic of its argument.',
+ abstract: 'Reverses the logic of its argument.',
links: [
{
title: 'Instruction',
@@ -210,8 +209,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logical: { name: 'logical', detail: 'The condition that you want to reverse the logic for, which can evaluate to either TRUE or FALSE.' },
},
},
OR: {
@@ -266,27 +264,26 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ expression: { name: 'expression', detail: 'Expression is the value (such as a number, date or some text) that will be compared against value1…value126.' },
+ value: { name: 'value1...value126', detail: 'ValueN is a value that will be compared against expression.' },
+ result: { name: 'result1...result126', detail: 'ResultN is the value to be returned when the corresponding valueN argument matches expression. ResultN and must be supplied for each corresponding valueN argument.' },
+ default: { name: 'default', detail: 'Default is the value to return in case no matches are found in the valueN expressions. The Default argument is identified by having no corresponding resultN expression (see examples). Default must be the final argument in the function.' },
},
},
TRUE: {
- description: 'Returns the logical value TRUE',
- abstract: 'Returns the logical value TRUE',
+ description: 'Returns the logical value TRUE.',
+ abstract: 'Returns the logical value TRUE.',
links: [
{
title: 'Instruction',
url: 'https://support.microsoft.com/en-us/office/true-function-7652c6e3-8987-48d0-97cd-ef223246b3fb',
},
],
- functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
- },
+ functionParameter: {},
},
XOR: {
- description: 'Returns a logical exclusive OR of all arguments',
- abstract: 'Returns a logical exclusive OR of all arguments',
+ description: 'Returns TRUE if an odd number of its arguments evaluate to TRUE, and FALSE if an even number of its arguments evaluate to TRUE.',
+ abstract: 'Returns TRUE if an odd number of arguments are TRUE',
links: [
{
title: 'Instruction',
@@ -294,8 +291,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logical1: { name: 'logical1', detail: 'The first condition that you want to test that can evaluate to either TRUE or FALSE.' },
+ logical2: { name: 'logical2', detail: 'Additional conditions that you want to test that can evaluate to either TRUE or FALSE, up to a maximum of 255 conditions.' },
},
},
};
diff --git a/packages/sheets-formula/src/locale/function-list/logical/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/logical/ja-JP.ts
index 298646894d..8cdddbe7a9 100644
--- a/packages/sheets-formula/src/locale/function-list/logical/ja-JP.ts
+++ b/packages/sheets-formula/src/locale/function-list/logical/ja-JP.ts
@@ -66,10 +66,7 @@ export default {
url: 'https://support.microsoft.com/ja-jp/office/false-%E9%96%A2%E6%95%B0-2d58dfa5-9c03-4259-bf8f-f0ae14346904',
},
],
- functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
- },
+ functionParameter: {},
},
IF: {
description: '値または数式が条件を満たしているかどうかを判定します。',
@@ -101,8 +98,8 @@ export default {
},
},
IFNA: {
- description: 'それ以外の場合は、式の結果を返します。',
- abstract: 'それ以外の場合は、式の結果を返します。',
+ description: '式の結果が #N/A になる場合に指定した値を返し、それ以外の場合は式の結果を返します',
+ abstract: '式の結果が #N/A になる場合に指定した値を返し、それ以外の場合は式の結果を返します',
links: [
{
title: '指導',
@@ -110,13 +107,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '値', detail: 'エラー値 #N/A があるかどうかを確認する引数。' },
+ valueIfNa: { name: '値_if_na', detail: '式が #N/A エラー値と評価された場合に返される値。' },
},
},
IFS: {
- description: '1つ以上の条件が満たされているかどうかをチェックして、最初の TRUE 条件に対応する値を返します。',
- abstract: '1つ以上の条件が満たされているかどうかをチェックして、最初の TRUE 条件に対応する値を返します。',
+ description: '1 つ以上の条件が満たされているかどうかを確認し、最初の TRUE 条件に対応する値を返します。',
+ abstract: '1 つ以上の条件が満たされているかどうかを確認し、最初の TRUE 条件に対応する値を返します。',
links: [
{
title: '指導',
@@ -124,8 +121,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logicalTest1: { name: '論理テスト1', detail: 'TRUE または FALSE に評価される条件。' },
+ valueIfTrue1: { name: '論理テスト1がTRUEの場合の値', detail: 'logical_test1 が TRUE と評価された場合に返される結果。空でもかまいません。' },
+ logicalTest2: { name: '論理テスト2...論理テスト127', detail: 'TRUE または FALSE に評価される条件。' },
+ valueIfTrue2: { name: '論理テスト2がTRUEの場合の値...論理テスト127がTRUEの場合の値', detail: 'logical_testN が TRUE と評価された場合に返される結果。各 value_if_trueN は条件 logical_testN に対応します。空でもかまいません。' },
},
},
LAMBDA: {
@@ -195,8 +194,8 @@ export default {
},
},
NOT: {
- description: '引数の論理値 (TRUE または FALSE) を逆にして返します。',
- abstract: '引数の論理値 (TRUE または FALSE) を逆にして返します。',
+ description: '引数の論理を反転します。',
+ abstract: '引数の論理を反転します。',
links: [
{
title: '指導',
@@ -204,8 +203,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logical: { name: '論理式', detail: '論理を反転する条件。TRUE または FALSE に評価されます。' },
},
},
OR: {
@@ -251,8 +249,8 @@ export default {
},
},
SWITCH: {
- description: '値の一覧に対して式を評価し、最初に一致する値に対応する結果を返します。 いずれにも一致しない場合は、任意指定の既定値が返されます。',
- abstract: '値の一覧に対して式を評価し、最初に一致する値に対応する結果を返します。 いずれにも一致しない場合は、任意指定の既定値が返されます。',
+ description: '式を値のリストと比較し、最初に一致する値に対応する結果を返します。一致する値がない場合は、オプションで既定値が返される場合があります。',
+ abstract: '式を値のリストと比較し、最初に一致する値に対応する結果を返します。一致する値がない場合は、オプションで既定値が返される場合があります。',
links: [
{
title: '指導',
@@ -260,8 +258,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ expression: { name: '式', detail: '式は、値1...値126 と比較される値です(数値、日付、テキストなど)。' },
+ value: { name: '値1...値126', detail: '値N は式と比較される値です。' },
+ result: { name: '結果1...結果126', detail: '結果N は対応する値N 引数が式と一致した場合に返される値です。結果N は対応する値N 引数ごとに提供する必要があります。' },
+ default: { name: '既定', detail: '既定は、値N 式で一致するものが見つからなかった場合に返される値です。既定の引数は、対応する結果N 式がないことで識別されます(例を参照)。既定は関数の最後の引数でなければなりません。' },
},
},
TRUE: {
@@ -273,14 +273,11 @@ export default {
url: 'https://support.microsoft.com/ja-jp/office/true-%E9%96%A2%E6%95%B0-7652c6e3-8987-48d0-97cd-ef223246b3fb',
},
],
- functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
- },
+ functionParameter: {},
},
XOR: {
- description: 'すべての引数の排他的論理和を返します。',
- abstract: 'すべての引数の排他的論理和を返します。',
+ description: '引数のうち奇数個の条件が TRUE の場合に TRUE を返し、偶数個の条件が TRUE の場合に FALSE を返します。',
+ abstract: '引数のうち奇数個の条件が TRUE の場合に TRUE を返します。',
links: [
{
title: '指導',
@@ -288,8 +285,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logical1: { name: '論理式 1', detail: 'TRUE または FALSE に評価できるテスト対象の 1 つ目の条件。' },
+ logical2: { name: '論理式 2', detail: '最大 255 個の条件まで、TRUE または FALSE のいずれかに評価できるテストする追加の条件。' },
},
},
};
diff --git a/packages/sheets-formula/src/locale/function-list/logical/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/logical/zh-CN.ts
index fc2ccbfbba..d8d1a6ab16 100644
--- a/packages/sheets-formula/src/locale/function-list/logical/zh-CN.ts
+++ b/packages/sheets-formula/src/locale/function-list/logical/zh-CN.ts
@@ -58,18 +58,15 @@ export default {
},
},
FALSE: {
- description: '返回逻辑值 FALSE',
- abstract: '返回逻辑值 FALSE',
+ description: '返回逻辑值 FALSE。',
+ abstract: '返回逻辑值 FALSE。',
links: [
{
title: '教学',
url: 'https://support.microsoft.com/zh-cn/office/false-%E5%87%BD%E6%95%B0-2d58dfa5-9c03-4259-bf8f-f0ae14346904',
},
],
- functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
- },
+ functionParameter: {},
},
IF: {
description: '指定要执行的逻辑检测',
@@ -101,8 +98,8 @@ export default {
},
},
IFNA: {
- description: '如果该表达式解析为 #N/A,则返回指定值;否则返回该表达式的结果',
- abstract: '如果该表达式解析为 #N/A,则返回指定值;否则返回该表达式的结果',
+ description: '如果表达式的结果为 #N/A,则返回您指定的值,否则返回表达式的结果',
+ abstract: '如果表达式的结果为 #N/A,则返回您指定的值,否则返回表达式的结果',
links: [
{
title: '教学',
@@ -110,13 +107,13 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ value: { name: '值', detail: '检查是否存在 #N/A 错误值的参数。' },
+ valueIfNa: { name: '如果为#N/A的值', detail: '如果公式结果为 #N/A 错误值,则返回的值。' },
},
},
IFS: {
- description: ' 检查是否满足一个或多个条件,且是否返回与第一个 TRUE 条件对应的值。',
- abstract: ' 检查是否满足一个或多个条件,且是否返回与第一个 TRUE 条件对应的值。',
+ description: '检查一个或多个条件是否满足,并返回第一个为 TRUE 的条件对应的值。',
+ abstract: '检查一个或多个条件是否满足,并返回第一个为 TRUE 的条件对应的值。',
links: [
{
title: '教学',
@@ -124,8 +121,10 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logicalTest1: { name: '逻辑测试1', detail: '计算结果为 TRUE 或 FALSE 的条件。' },
+ valueIfTrue1: { name: '如果为 TRUE 的值1', detail: '如果 logical_test1 的计算结果为 TRUE,返回的结果。可以为空。' },
+ logicalTest2: { name: '逻辑测试2...逻辑测试127', detail: '计算结果为 TRUE 或 FALSE 的条件。' },
+ valueIfTrue2: { name: '如果为 TRUE 的值2...如果为 TRUE 的值127', detail: '如果 logical_testN 的计算结果为 TRUE,返回的结果。每个 value_if_trueN 对应于一个条件 logical_testN。可以为空。' },
},
},
LAMBDA: {
@@ -196,8 +195,8 @@ export default {
},
},
NOT: {
- description: '对其参数的逻辑求反',
- abstract: '对其参数的逻辑求反',
+ description: '反转其参数的逻辑值。',
+ abstract: '反转其参数的逻辑值。',
links: [
{
title: '教学',
@@ -205,8 +204,7 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logical: { name: '逻辑表达式', detail: '您要反转逻辑的条件,可评估为 TRUE 或 FALSE。' },
},
},
OR: {
@@ -252,8 +250,8 @@ export default {
},
},
SWITCH: {
- description: '根据值列表计算表达式,并返回与第一个匹配值对应的结果。 如果不匹配,则可能返回可选默认值。',
- abstract: '根据值列表计算表达式,并返回与第一个匹配值对应的结果。 如果不匹配,则可能返回可选默认值。',
+ description: '将表达式与值列表进行比较,并返回与第一个匹配值对应的结果。如果没有匹配项,可以返回一个可选的默认值。',
+ abstract: '将表达式与值列表进行比较,并返回与第一个匹配值对应的结果。如果没有匹配项,可以返回一个可选的默认值。',
links: [
{
title: '教学',
@@ -261,27 +259,26 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ expression: { name: '表达式', detail: '表达式是将要与 value1…value126 进行比较的值(例如数字、日期或一些文本)。' },
+ value: { name: '值1...值126', detail: '值N 是将要与表达式进行比较的值。' },
+ result: { name: '结果1...结果126', detail: '结果N 是当对应的值N 参数与表达式匹配时要返回的值。必须为每个对应的值N 参数提供结果N。' },
+ default: { name: '默认', detail: '默认是在值N 表达式中找不到匹配项时要返回的值。默认参数通过没有对应的结果N 表达式来识别(参见示例)。默认必须是函数中的最后一个参数。' },
},
},
TRUE: {
- description: '返回逻辑值 TRUE',
- abstract: '返回逻辑值 TRUE',
+ description: '返回逻辑值 TRUE。',
+ abstract: '返回逻辑值 TRUE。',
links: [
{
title: '教学',
url: 'https://support.microsoft.com/zh-cn/office/true-%E5%87%BD%E6%95%B0-7652c6e3-8987-48d0-97cd-ef223246b3fb',
},
],
- functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
- },
+ functionParameter: {},
},
XOR: {
- description: '返回所有参数的逻辑“异或”值',
- abstract: '返回所有参数的逻辑“异或”值',
+ description: '如果参数中计算结果为 TRUE 的数量为奇数,则返回 TRUE;如果计算结果为 TRUE 的数量为偶数,则返回 FALSE。',
+ abstract: '如果参数中 TRUE 的数量为奇数,则返回 TRUE',
links: [
{
title: '教学',
@@ -289,8 +286,8 @@ export default {
},
],
functionParameter: {
- number1: { name: 'number1', detail: 'first' },
- number2: { name: 'number2', detail: 'second' },
+ logical1: { name: '逻辑表达式 1', detail: '第一个想要测试且计算结果可为 TRUE 或 FALSE 的条件。' },
+ logical2: { name: '逻辑表达式 2', detail: '其他想要测试且计算结果可为 TRUE 或 FALSE 的条件(最多 255 个条件)。' },
},
},
};
diff --git a/packages/sheets-formula/src/services/function-list/logical.ts b/packages/sheets-formula/src/services/function-list/logical.ts
index 16c7a86a02..ebbb80d5d5 100644
--- a/packages/sheets-formula/src/services/function-list/logical.ts
+++ b/packages/sheets-formula/src/services/function-list/logical.ts
@@ -89,20 +89,6 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
description: 'formula.functionList.FALSE.description',
abstract: 'formula.functionList.FALSE.abstract',
functionParameter: [
- {
- name: 'formula.functionList.FALSE.functionParameter.number1.name',
- detail: 'formula.functionList.FALSE.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.FALSE.functionParameter.number2.name',
- detail: 'formula.functionList.FALSE.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
],
},
{
@@ -163,16 +149,16 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.IFNA.abstract',
functionParameter: [
{
- name: 'formula.functionList.IFNA.functionParameter.number1.name',
- detail: 'formula.functionList.IFNA.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.IFNA.functionParameter.value.name',
+ detail: 'formula.functionList.IFNA.functionParameter.value.detail',
+ example: 'VLOOKUP(C3,C6:D11,2,FALSE)',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.IFNA.functionParameter.number2.name',
- detail: 'formula.functionList.IFNA.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.IFNA.functionParameter.valueIfNa.name',
+ detail: 'formula.functionList.IFNA.functionParameter.valueIfNa.detail',
+ example: '"Not Found"',
require: 1,
repeat: 0,
},
@@ -185,19 +171,33 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.IFS.abstract',
functionParameter: [
{
- name: 'formula.functionList.IFS.functionParameter.number1.name',
- detail: 'formula.functionList.IFS.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.IFS.functionParameter.logicalTest1.name',
+ detail: 'formula.functionList.IFS.functionParameter.logicalTest1.detail',
+ example: 'A2 = "foo"',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.IFS.functionParameter.number2.name',
- detail: 'formula.functionList.IFS.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.IFS.functionParameter.valueIfTrue1.name',
+ detail: 'formula.functionList.IFS.functionParameter.valueIfTrue1.detail',
+ example: '"A2 is foo"',
require: 1,
repeat: 0,
},
+ {
+ name: 'formula.functionList.IFS.functionParameter.logicalTest2.name',
+ detail: 'formula.functionList.IFS.functionParameter.logicalTest2.detail',
+ example: 'F2=1',
+ require: 0,
+ repeat: 1,
+ },
+ {
+ name: 'formula.functionList.IFS.functionParameter.valueIfTrue2.name',
+ detail: 'formula.functionList.IFS.functionParameter.valueIfTrue2.detail',
+ example: 'D2',
+ require: 0,
+ repeat: 1,
+ },
],
},
{
@@ -303,16 +303,9 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.NOT.abstract',
functionParameter: [
{
- name: 'formula.functionList.NOT.functionParameter.number1.name',
- detail: 'formula.functionList.NOT.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.NOT.functionParameter.number2.name',
- detail: 'formula.functionList.NOT.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.NOT.functionParameter.logical.name',
+ detail: 'formula.functionList.NOT.functionParameter.logical.detail',
+ example: 'A2>100',
require: 1,
repeat: 0,
},
@@ -391,16 +384,30 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.SWITCH.abstract',
functionParameter: [
{
- name: 'formula.functionList.SWITCH.functionParameter.number1.name',
- detail: 'formula.functionList.SWITCH.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SWITCH.functionParameter.expression.name',
+ detail: 'formula.functionList.SWITCH.functionParameter.expression.detail',
+ example: 'WEEKDAY(A2)',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.SWITCH.functionParameter.number2.name',
- detail: 'formula.functionList.SWITCH.functionParameter.number2.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.SWITCH.functionParameter.value.name',
+ detail: 'formula.functionList.SWITCH.functionParameter.value.detail',
+ example: '1',
+ require: 1,
+ repeat: 1,
+ },
+ {
+ name: 'formula.functionList.SWITCH.functionParameter.result.name',
+ detail: 'formula.functionList.SWITCH.functionParameter.result.detail',
+ example: '"Sunday"',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SWITCH.functionParameter.default.name',
+ detail: 'formula.functionList.SWITCH.functionParameter.default.detail',
+ example: '"No match"',
require: 1,
repeat: 0,
},
@@ -412,20 +419,6 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
description: 'formula.functionList.TRUE.description',
abstract: 'formula.functionList.TRUE.abstract',
functionParameter: [
- {
- name: 'formula.functionList.TRUE.functionParameter.number1.name',
- detail: 'formula.functionList.TRUE.functionParameter.number1.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
- {
- name: 'formula.functionList.TRUE.functionParameter.number2.name',
- detail: 'formula.functionList.TRUE.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
- },
],
},
{
@@ -435,18 +428,18 @@ export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [
abstract: 'formula.functionList.XOR.abstract',
functionParameter: [
{
- name: 'formula.functionList.XOR.functionParameter.number1.name',
- detail: 'formula.functionList.XOR.functionParameter.number1.detail',
- example: 'A1:A20',
+ name: 'formula.functionList.XOR.functionParameter.logical1.name',
+ detail: 'formula.functionList.XOR.functionParameter.logical1.detail',
+ example: '3>0',
require: 1,
repeat: 0,
},
{
- name: 'formula.functionList.XOR.functionParameter.number2.name',
- detail: 'formula.functionList.XOR.functionParameter.number2.detail',
- example: 'A1:A20',
- require: 1,
- repeat: 0,
+ name: 'formula.functionList.XOR.functionParameter.logical2.name',
+ detail: 'formula.functionList.XOR.functionParameter.logical2.detail',
+ example: '2<9',
+ require: 0,
+ repeat: 1,
},
],
},