Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(formula): add some text formulas (#3546)
wpxp1234564094288c6e6f
diff --git a/packages/engine-formula/src/basics/math.ts b/packages/engine-formula/src/basics/math.tsindex be79c40e8d..c071904403 100644--- a/packages/engine-formula/src/basics/math.ts+++ b/packages/engine-formula/src/basics/math.ts@@ -127,3 +127,58 @@ function adjoint(matrix: number[][]): number[][] {return adj;}++export const romanToArabicMap = new Map<string, number>([+ ['I', 1],+ ['V', 5],+ ['X', 10],+ ['L', 50],+ ['C', 100],+ ['D', 500],+ ['M', 1000],+]);++export const arabicToRomanMap = new Map<number, string>([+ [1, 'I'],+ [4, 'IV'],+ [5, 'V'],+ [9, 'IX'],+ [10, 'X'],+ [40, 'XL'],+ [45, 'VL'],+ [49, 'IL'],+ [50, 'L'],+ [90, 'XC'],+ [95, 'VC'],+ [99, 'IC'],+ [100, 'C'],+ [400, 'CD'],+ [450, 'LD'],+ [490, 'XD'],+ [495, 'VD'],+ [499, 'ID'],+ [500, 'D'],+ [900, 'CM'],+ [950, 'LM'],+ [990, 'XM'],+ [995, 'VM'],+ [999, 'IM'],+ [1000, 'M'],+]);++/**+ * form: A number specifying the type of roman numeral you want.+ * The roman numeral style ranges from Classic to Simplified, becoming more concise as the value of form increases+ * 0 Classic+ * 1 More concise+ * 2 More concise+ * 3 More concise+ * 4 Simplified+ */+export const romanFormArray: number[][] = [+ [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000, 4000],+ [1, 4, 5, 9, 10, 40, 45, 50, 90, 95, 100, 400, 450, 500, 900, 950, 1000, 4000],+ [1, 4, 5, 9, 10, 40, 45, 49, 50, 90, 95, 99, 100, 400, 450, 490, 500, 900, 950, 990, 1000, 4000],+ [1, 4, 5, 9, 10, 40, 45, 49, 50, 90, 95, 99, 100, 400, 450, 490, 495, 500, 900, 950, 990, 995, 1000, 4000],+ [1, 4, 5, 9, 10, 40, 45, 49, 50, 90, 95, 99, 100, 400, 450, 490, 495, 499, 500, 900, 950, 990, 995, 999, 1000, 4000],+];diff --git a/packages/engine-formula/src/engine/ast-node/function-node.ts b/packages/engine-formula/src/engine/ast-node/function-node.tsindex 203a50a6cb..281782e003 100644--- a/packages/engine-formula/src/engine/ast-node/function-node.ts+++ b/packages/engine-formula/src/engine/ast-node/function-node.ts@@ -56,6 +56,10 @@ export class FunctionNode extends BaseAstNode {if (this._functionExecutor.isAddress()) {this.setAddress();}++ if (this._functionExecutor.needsLocale) {+ this._setLocale();+ }}override get nodeType() {@@ -267,6 +271,10 @@ export class FunctionNode extends BaseAstNode {referenceObject.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData());}++ private _setLocale() {+ this._functionExecutor.setLocale(this._currentConfigService.getLocale());+ }}export class ErrorFunctionNode extends BaseAstNode {diff --git a/packages/engine-formula/src/engine/utils/char-kit.ts b/packages/engine-formula/src/engine/utils/char-kit.tsindex 3e22a03670..ff2b927d9b 100644--- a/packages/engine-formula/src/engine/utils/char-kit.ts+++ b/packages/engine-formula/src/engine/utils/char-kit.ts@@ -15,30 +15,70 @@*//**- * Korean in Excel does not count as two characters. Here we calculate all Chinese, Japanese and Korean characters as two characters.+ * excel logic is cofusing, so we use google sheet logic*- * ā -> 1- * ー -> 2- *- * @param str- * @returns+ * @param text+ * @returns number*/-export function charLenByte(str: string) {+export function charLenByte(text: string): number {let byteCount = 0;- for (let i = 0; i < str.length; i++) {- const charCode = str.charCodeAt(i);-- if (- (charCode >= 0x3040 && charCode <= 0x30FF) || // Japanese hiragana and katakana- (charCode >= 0x4E00 && charCode <= 0x9FFF) || // Chinese (simplified and traditional)- (charCode >= 0xAC00 && charCode <= 0xD7AF) // Korean language- ) {- byteCount += 2;- } else {- byteCount += 1;- }+ for (let i = 0; i < text.length; i++) {+ // const charCode = text.charCodeAt(i);++ // if (+ // (charCode >= 0x3040 && charCode <= 0x30FF) || // Japanese hiragana and katakana+ // (charCode >= 0x4E00 && charCode <= 0x9FFF) || // Chinese (simplified and traditional)+ // (charCode >= 0xAC00 && charCode <= 0xD7AF) // Korean language+ // ) {+ // byteCount += 2;+ // } else {+ // byteCount += 1;+ // }++ byteCount += getCharLenByteInText(text, i);}return byteCount;}++export function getCharLenByteInText(text: string, charIndex: number, direction: 'ltr' | 'rtl' = 'ltr'): number {+ const codePoint = getCodePoint(text, charIndex, direction);+ return codePoint > 255 ? 2 : 1;+}++function highSurrogate(charCode: number): boolean {+ return charCode >= 0xD800 && charCode <= 0xDBFF;+}++function lowSurrogate(charCode: number): boolean {+ return charCode >= 0xDC00 && charCode <= 0xDFFF;+}++function surrogatePair(highSurrogate: number, lowSurrogate: number): number {+ const highBits = (highSurrogate & 0x3FF) << 10;+ const lowBits = lowSurrogate & 0x3FF;+ return highBits + lowBits + 0x10000;+}++function getCodePoint(str: string, index: number, direction: 'ltr' | 'rtl' = 'ltr'): number {+ const charCode = str.charCodeAt(index);++ if (direction === 'ltr' && highSurrogate(charCode) && index + 1 < str.length) {+ const nextCharCode = str.charCodeAt(index + 1);++ if (lowSurrogate(nextCharCode)) {+ return surrogatePair(charCode, nextCharCode);+ }+ }++ if (direction === 'rtl' && lowSurrogate(charCode) && index - 1 >= 0) {+ const prevCharCode = str.charCodeAt(index - 1);++ if (highSurrogate(prevCharCode)) {+ return surrogatePair(prevCharCode, charCode);+ }+ }++ return charCode;+}diff --git a/packages/engine-formula/src/engine/utils/numfmt-kit.ts b/packages/engine-formula/src/engine/utils/numfmt-kit.tsindex c5e879fb88..5f3bed7785 100644--- a/packages/engine-formula/src/engine/utils/numfmt-kit.ts+++ b/packages/engine-formula/src/engine/utils/numfmt-kit.ts@@ -15,7 +15,8 @@*/import type { ICellData, Nullable, Styles } from '@univerjs/core';-import { numfmt } from '@univerjs/core';+import { LocaleType, numfmt } from '@univerjs/core';+import { FormulaAstLRU } from '../../basics/cache-lru';import { operatorToken } from '../../basics/token';const currencySymbols = [@@ -279,3 +280,129 @@ export function comparePatternPriority(previousPattern: string, nextPattern: strreturn previousPattern || nextPattern;}++/**+ * Get the currency symbol based on the locale+ * Now define it here+ * TODO: import from sheet-numfmt currencySymbolMap later+ *+ * @param locale+ * @returns+ */+const countryCurrencySymbolMap = new Map<LocaleType, string>([+ [LocaleType.EN_US, '$'],+ // [LocaleType.JA_JP, '¥'],+ [LocaleType.RU_RU, '₽'],+ [LocaleType.VI_VN, '₫'],+ [LocaleType.ZH_CN, '¥'],+ [LocaleType.ZH_TW, 'NT$'],+]);++function getCurrencySymbol(locale: LocaleType): string {+ return countryCurrencySymbolMap.get(locale) || '$';+}++export function getCurrencyFormat(locale: LocaleType, numberDigits: number = 2): string {+ let _numberDigits = numberDigits;++ if (numberDigits > 127) {+ _numberDigits = 127;+ }++ let decimal = '';++ if (_numberDigits > 0) {+ decimal = `.${'0'.repeat(_numberDigits)}`;+ }++ return `"${getCurrencySymbol(locale)}"#,##0${decimal}_);[Red]("${getCurrencySymbol(locale)}"#,##0${decimal})`;+}++export function applyCurrencyFormat(locale: LocaleType, number: number, numberDigits: number = 2): string {+ return numfmt.format(getCurrencyFormat(locale, numberDigits), number);+}++/**+ * String is number pattern or date or time, for example+ * "20%"+ * "2012-12-12"+ * "16:48:00"+ *+ * @param locale+ * @returns+ */+const stringToNumberPatternCache = new FormulaAstLRU<{+ value: number;+ pattern: string;+}>(100000);++export function stringIsNumberPattern(input: string) {+ let _input = input;++ if (_input.startsWith('"') && _input.endsWith('"')) {+ _input = _input.slice(1, -1);+ }++ const cacheValue = stringToNumberPatternCache.get(_input);++ if (cacheValue) {+ return {+ isNumberPattern: true,+ value: cacheValue.value,+ pattern: cacheValue.pattern,+ };+ }++ const numberPattern = numfmt.parseNumber(_input);++ if (numberPattern) {+ stringToNumberPatternCache.set(_input, {+ value: numberPattern.v as number,+ pattern: numberPattern.z as string,+ });++ return {+ isNumberPattern: true,+ value: numberPattern.v as number,+ pattern: numberPattern.z as string,+ };+ }++ const datePattern = numfmt.parseDate(_input);++ if (datePattern) {+ stringToNumberPatternCache.set(_input, {+ value: datePattern.v as number,+ pattern: datePattern.z as string,+ });++ return {+ isNumberPattern: true,+ value: datePattern.v as number,+ pattern: datePattern.z as string,+ };+ }++ const timePattern = numfmt.parseTime(_input);++ if (timePattern) {+ stringToNumberPatternCache.set(_input, {+ value: timePattern.v as number,+ pattern: timePattern.z as string,+ });++ return {+ isNumberPattern: true,+ value: timePattern.v as number,+ pattern: timePattern.z as string,+ };+ }++ return {+ isNumberPattern: false,+ };+}++export function clearStringToNumberPatternCache() {+ stringToNumberPatternCache.clear();+}diff --git a/packages/engine-formula/src/engine/value-object/array-value-object.ts b/packages/engine-formula/src/engine/value-object/array-value-object.tsindex a31b3c8087..3006077bbd 100644--- a/packages/engine-formula/src/engine/value-object/array-value-object.ts+++ b/packages/engine-formula/src/engine/value-object/array-value-object.ts@@ -24,6 +24,7 @@ import { CELL_INVERTED_INDEX_CACHE } from '../../basics/inverted-index-cache';import { regexTestArrayValue } from '../../basics/regex';import { compareToken } from '../../basics/token';import { ArrayBinarySearchType, ArrayOrderSearchType, getCompare } from '../utils/compare';+import { stringIsNumberPattern } from '../utils/numfmt-kit';import { BaseValueObject, ErrorValueObject } from './base-value-object';import { BooleanValueObject, createBooleanValueObjectByRawValue, createNumberValueObjectByRawValue, createStringValueObjectByRawValue, NullValueObject, NumberValueObject, StringValueObject } from './primitive-object';@@ -1897,6 +1898,11 @@ export class ValueObjectFactory {return NumberValueObject.create(Number(rawValue));}+ const { isNumberPattern, value, pattern } = stringIsNumberPattern(rawValue);+ if (isNumberPattern) {+ return NumberValueObject.create(value as number, pattern as string);+ }+const rawValueSingleLine = rawValue.replace(/\n/g, '').replace(/\r/g, '');if (!isStringWrappedByDoubleQuotes(rawValueSingleLine) && regexTestArrayValue(rawValueSingleLine)) {return ArrayValueObject.create(rawValueSingleLine);diff --git a/packages/engine-formula/src/functions/base-function.ts b/packages/engine-formula/src/functions/base-function.tsindex 930592aad8..7435122af2 100644--- a/packages/engine-formula/src/functions/base-function.ts+++ b/packages/engine-formula/src/functions/base-function.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IRange, Nullable } from '@univerjs/core';+import type { IRange, LocaleType, Nullable } from '@univerjs/core';import type { IFunctionNames } from '../basics/function';import type { BaseReferenceObject, FunctionVariantType, NodeValueType } from '../engine/reference-object/base-reference-object';@@ -42,6 +42,7 @@ export class BaseFunction {private _row: number = -1;private _column: number = -1;private _definedNames: Nullable<IDefinedNameMapItem>;+ private _locale: LocaleType;/*** Whether the function needs to expand the parameters@@ -53,6 +54,11 @@ export class BaseFunction {*/needsReferenceObject: boolean = false;+ /**+ * Whether the function needs handle locale+ */+ needsLocale: boolean = false;+/*** Minimum number of parameters*/@@ -111,6 +117,14 @@ export class BaseFunction {this._definedNames = definedNames;}+ getLocale() {+ return this._locale;+ }++ setLocale(locale: LocaleType) {+ this._locale = locale;+ }+isAsync() {return false;}diff --git a/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.tsindex 76c7dd40ec..c410b7b3ef 100644--- a/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/db/__tests__/index.spec.ts@@ -16,11 +16,11 @@import { describe, expect, it } from 'vitest';+import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';import { Db } from '../index';-import { NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';-import { ErrorType } from '../../../../basics/error-type';describe('Test db function', () => {const testFunction = new Db(FUNCTION_NAMES_FINANCIAL.DB);diff --git a/packages/engine-formula/src/functions/financial/db/index.ts b/packages/engine-formula/src/functions/financial/db/index.tsindex ed07858caa..0410925888 100644--- a/packages/engine-formula/src/functions/financial/db/index.ts+++ b/packages/engine-formula/src/functions/financial/db/index.ts@@ -15,18 +15,21 @@*/import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';export class Db extends BaseFunction {override minParams = 4;override maxParams = 5;+ override needsLocale = true;+override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, month?: BaseValueObject): BaseValueObject {let _month = month ?? NumberValueObject.create(12);@@ -146,7 +149,7 @@ export class Db extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));} else {return NumberValueObject.create(result);}diff --git a/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.tsindex 179a5e82d1..5b158249be 100644--- a/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/ddb/__tests__/index.spec.ts@@ -16,11 +16,11 @@import { describe, expect, it } from 'vitest';+import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';import { Ddb } from '../index';-import { NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';-import { ErrorType } from '../../../../basics/error-type';describe('Test ddb function', () => {const testFunction = new Ddb(FUNCTION_NAMES_FINANCIAL.DDB);diff --git a/packages/engine-formula/src/functions/financial/ddb/index.ts b/packages/engine-formula/src/functions/financial/ddb/index.tsindex a8e1db37f0..f799b1ee92 100644--- a/packages/engine-formula/src/functions/financial/ddb/index.ts+++ b/packages/engine-formula/src/functions/financial/ddb/index.ts@@ -15,19 +15,22 @@*/import { ErrorType } from '../../../basics/error-type';+import { calculateDDB } from '../../../basics/financial';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';-import { calculateDDB } from '../../../basics/financial';export class Ddb extends BaseFunction {override minParams = 4;override maxParams = 5;+ override needsLocale = true;+override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, period: BaseValueObject, factor?: BaseValueObject): BaseValueObject {let _factor = factor ?? NumberValueObject.create(2);@@ -95,7 +98,7 @@ export class Ddb extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));}return NumberValueObject.create(result);diff --git a/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.tsindex efd810da63..8d83e11b9e 100644--- a/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/fv/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Fv } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';-import { ErrorType } from '../../../../basics/error-type';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Fv } from '../index';describe('Test fv function', () => {const testFunction = new Fv(FUNCTION_NAMES_FINANCIAL.FV);diff --git a/packages/engine-formula/src/functions/financial/fv/index.ts b/packages/engine-formula/src/functions/financial/fv/index.tsindex 2adcba5a38..bd02c7e156 100644--- a/packages/engine-formula/src/functions/financial/fv/index.ts+++ b/packages/engine-formula/src/functions/financial/fv/index.ts@@ -14,21 +14,24 @@* limitations under the License.*/-import { calculateFV } from '../../../basics/financial';import { ErrorType } from '../../../basics/error-type';-import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { calculateFV } from '../../../basics/financial';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';export class Fv extends BaseFunction {override minParams = 3;override maxParams = 5;+ override needsLocale = true;+override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, pv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {const _pv = pv ?? NumberValueObject.create(0);const _type = type ?? NumberValueObject.create(0);@@ -82,7 +85,7 @@ export class Fv extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));} else {return NumberValueObject.create(result);}diff --git a/packages/engine-formula/src/functions/financial/ipmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/ipmt/__tests__/index.spec.tsindex 10c49e0963..4ac619eb97 100644--- a/packages/engine-formula/src/functions/financial/ipmt/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/ipmt/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Ipmt } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';-import { ErrorType } from '../../../../basics/error-type';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Ipmt } from '../index';describe('Test ipmt function', () => {const testFunction = new Ipmt(FUNCTION_NAMES_FINANCIAL.IPMT);diff --git a/packages/engine-formula/src/functions/financial/ipmt/index.ts b/packages/engine-formula/src/functions/financial/ipmt/index.tsindex c7dd79a27c..eee30dcaa1 100644--- a/packages/engine-formula/src/functions/financial/ipmt/index.ts+++ b/packages/engine-formula/src/functions/financial/ipmt/index.ts@@ -14,21 +14,24 @@* limitations under the License.*/-import { calculateIPMT } from '../../../basics/financial';import { ErrorType } from '../../../basics/error-type';-import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { calculateIPMT } from '../../../basics/financial';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';export class Ipmt extends BaseFunction {override minParams = 4;override maxParams = 6;+ override needsLocale = true;+override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {const _fv = fv ?? NumberValueObject.create(0);const _type = type ?? NumberValueObject.create(0);@@ -91,7 +94,7 @@ export class Ipmt extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));} else {return NumberValueObject.create(result);}diff --git a/packages/engine-formula/src/functions/financial/npv/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/npv/__tests__/index.spec.tsindex eaef4ec323..c1ed6d70e7 100644--- a/packages/engine-formula/src/functions/financial/npv/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/npv/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Npv } from '../index';-import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';-import { ErrorType } from '../../../../basics/error-type';+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Npv } from '../index';describe('Test npv function', () => {const testFunction = new Npv(FUNCTION_NAMES_FINANCIAL.NPV);diff --git a/packages/engine-formula/src/functions/financial/npv/index.ts b/packages/engine-formula/src/functions/financial/npv/index.tsindex 0985754665..98edad4fa4 100644--- a/packages/engine-formula/src/functions/financial/npv/index.ts+++ b/packages/engine-formula/src/functions/financial/npv/index.ts@@ -15,11 +15,12 @@*/import { ErrorType } from '../../../basics/error-type';-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { calculateNpv } from '../../../basics/financial';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';-import { calculateNpv } from '../../../basics/financial';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';interface IValuesType {isError: boolean;@@ -32,6 +33,8 @@ export class Npv extends BaseFunction {override maxParams = 255;+ override needsLocale = true;+override calculate(rate: BaseValueObject, ...variants: BaseValueObject[]): BaseValueObject {if (rate.isError()) {return rate;@@ -77,7 +80,7 @@ export class Npv extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));}return NumberValueObject.create(result);diff --git a/packages/engine-formula/src/functions/financial/pmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/pmt/__tests__/index.spec.tsindex 0737b6a340..85cbad803d 100644--- a/packages/engine-formula/src/functions/financial/pmt/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/pmt/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Pmt } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';-import { ErrorType } from '../../../../basics/error-type';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Pmt } from '../index';describe('Test pmt function', () => {const testFunction = new Pmt(FUNCTION_NAMES_FINANCIAL.PMT);diff --git a/packages/engine-formula/src/functions/financial/pmt/index.ts b/packages/engine-formula/src/functions/financial/pmt/index.tsindex ae119a00dd..1febbe2490 100644--- a/packages/engine-formula/src/functions/financial/pmt/index.ts+++ b/packages/engine-formula/src/functions/financial/pmt/index.ts@@ -15,20 +15,23 @@*/import { ErrorType } from '../../../basics/error-type';-import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { calculatePMT } from '../../../basics/financial';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { calculatePMT } from '../../../basics/financial';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';export class Pmt extends BaseFunction {override minParams = 3;override maxParams = 5;+ override needsLocale = true;+override calculate(rate: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {const _fv = fv ?? NumberValueObject.create(0);const _type = type ?? NumberValueObject.create(0);@@ -86,7 +89,7 @@ export class Pmt extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));} else {return NumberValueObject.create(result);}diff --git a/packages/engine-formula/src/functions/financial/ppmt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/ppmt/__tests__/index.spec.tsindex a8b0236a45..12d91f73c2 100644--- a/packages/engine-formula/src/functions/financial/ppmt/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/ppmt/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Ppmt } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';-import { ErrorType } from '../../../../basics/error-type';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Ppmt } from '../index';describe('Test ppmt function', () => {const testFunction = new Ppmt(FUNCTION_NAMES_FINANCIAL.PPMT);diff --git a/packages/engine-formula/src/functions/financial/ppmt/index.ts b/packages/engine-formula/src/functions/financial/ppmt/index.tsindex 445fdde9c9..85560c3cca 100644--- a/packages/engine-formula/src/functions/financial/ppmt/index.ts+++ b/packages/engine-formula/src/functions/financial/ppmt/index.ts@@ -14,21 +14,24 @@* limitations under the License.*/-import { calculateIPMT, calculatePMT } from '../../../basics/financial';import { ErrorType } from '../../../basics/error-type';-import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { calculateIPMT, calculatePMT } from '../../../basics/financial';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';export class Ppmt extends BaseFunction {override minParams = 4;override maxParams = 6;+ override needsLocale = true;+override calculate(rate: BaseValueObject, per: BaseValueObject, nper: BaseValueObject, pv: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {const _fv = fv ?? NumberValueObject.create(0);const _type = type ?? NumberValueObject.create(0);@@ -91,7 +94,7 @@ export class Ppmt extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));} else {return NumberValueObject.create(result);}diff --git a/packages/engine-formula/src/functions/financial/pv/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/pv/__tests__/index.spec.tsindex da45d74c04..33f210d0c3 100644--- a/packages/engine-formula/src/functions/financial/pv/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/pv/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Pv } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';-import { ErrorType } from '../../../../basics/error-type';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Pv } from '../index';describe('Test pv function', () => {const testFunction = new Pv(FUNCTION_NAMES_FINANCIAL.NPER);diff --git a/packages/engine-formula/src/functions/financial/pv/index.ts b/packages/engine-formula/src/functions/financial/pv/index.tsindex 68ba42bf4e..800ff5bc14 100644--- a/packages/engine-formula/src/functions/financial/pv/index.ts+++ b/packages/engine-formula/src/functions/financial/pv/index.ts@@ -15,19 +15,22 @@*/import { ErrorType } from '../../../basics/error-type';-import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';export class Pv extends BaseFunction {override minParams = 3;override maxParams = 5;+ override needsLocale = true;+override calculate(rate: BaseValueObject, nper: BaseValueObject, pmt: BaseValueObject, fv?: BaseValueObject, type?: BaseValueObject): BaseValueObject {const _fv = fv ?? NumberValueObject.create(0);const _type = type ?? NumberValueObject.create(0);@@ -84,7 +87,7 @@ export class Pv extends BaseFunction {}if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));} else {return NumberValueObject.create(result);}diff --git a/packages/engine-formula/src/functions/financial/sln/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/sln/__tests__/index.spec.tsindex 4f2ba93bdd..5dfe5e1007 100644--- a/packages/engine-formula/src/functions/financial/sln/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/sln/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Sln } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Sln } from '../index';describe('Test sln function', () => {const testFunction = new Sln(FUNCTION_NAMES_FINANCIAL.SLN);diff --git a/packages/engine-formula/src/functions/financial/sln/index.ts b/packages/engine-formula/src/functions/financial/sln/index.tsindex 46a34b1fd7..a85f3078da 100644--- a/packages/engine-formula/src/functions/financial/sln/index.ts+++ b/packages/engine-formula/src/functions/financial/sln/index.ts@@ -16,16 +16,19 @@import { ErrorType } from '../../../basics/error-type';import { expandArrayValueObject } from '../../../engine/utils/array-object';-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';export class Sln extends BaseFunction {override minParams = 3;override maxParams = 3;+ override needsLocale = true;+override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject): BaseValueObject {const maxRowLength = Math.max(cost.isArray() ? (cost as ArrayValueObject).getRowCount() : 1,@@ -70,7 +73,7 @@ export class Sln extends BaseFunction {const result = (costValue - salvageValue) / lifeValue;if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));}return NumberValueObject.create(result);diff --git a/packages/engine-formula/src/functions/financial/syd/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/syd/__tests__/index.spec.tsindex c725141ae8..7b7f5c2716 100644--- a/packages/engine-formula/src/functions/financial/syd/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/syd/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Syd } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Syd } from '../index';describe('Test syd function', () => {const testFunction = new Syd(FUNCTION_NAMES_FINANCIAL.SYD);diff --git a/packages/engine-formula/src/functions/financial/syd/index.ts b/packages/engine-formula/src/functions/financial/syd/index.tsindex e53e4a4d55..4bd97a470e 100644--- a/packages/engine-formula/src/functions/financial/syd/index.ts+++ b/packages/engine-formula/src/functions/financial/syd/index.ts@@ -16,16 +16,19 @@import { ErrorType } from '../../../basics/error-type';import { expandArrayValueObject } from '../../../engine/utils/array-object';-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';export class Syd extends BaseFunction {override minParams = 4;override maxParams = 4;+ override needsLocale = true;+override calculate(cost: BaseValueObject, salvage: BaseValueObject, life: BaseValueObject, per: BaseValueObject): BaseValueObject {const maxRowLength = Math.max(cost.isArray() ? (cost as ArrayValueObject).getRowCount() : 1,@@ -83,7 +86,7 @@ export class Syd extends BaseFunction {const result = (costValue - salvageValue) * (lifeValue - perValue + 1) * 2 / (lifeValue * (lifeValue + 1));if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));}return NumberValueObject.create(result);diff --git a/packages/engine-formula/src/functions/financial/tbillprice/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/tbillprice/__tests__/index.spec.tsindex 74ed46001c..e42679baf0 100644--- a/packages/engine-formula/src/functions/financial/tbillprice/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/tbillprice/__tests__/index.spec.ts@@ -16,12 +16,12 @@import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';-import { Tbillprice } from '../index';-import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';-import { ErrorType } from '../../../../basics/error-type';+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';+import { Tbillprice } from '../index';describe('Test tbillprice function', () => {const testFunction = new Tbillprice(FUNCTION_NAMES_FINANCIAL.TBILLPRICE);diff --git a/packages/engine-formula/src/functions/financial/tbillprice/index.ts b/packages/engine-formula/src/functions/financial/tbillprice/index.tsindex 1488bcc304..982668d378 100644--- a/packages/engine-formula/src/functions/financial/tbillprice/index.ts+++ b/packages/engine-formula/src/functions/financial/tbillprice/index.ts@@ -17,6 +17,7 @@import { excelSerialToDate, getDateSerialNumberByObject, getDaysInYear } from '../../../basics/date';import { ErrorType } from '../../../basics/error-type';import { checkVariantsErrorIsNullorArrayOrBoolean } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';@@ -26,6 +27,8 @@ export class Tbillprice extends BaseFunction {override maxParams = 3;+ override needsLocale = true;+override calculate(settlement: BaseValueObject, maturity: BaseValueObject, discount: BaseValueObject): BaseValueObject {const { isError, errorObject, variants } = checkVariantsErrorIsNullorArrayOrBoolean(settlement, maturity, discount);@@ -79,6 +82,6 @@ export class Tbillprice extends BaseFunction {return ErrorValueObject.create(ErrorType.NUM);}- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));}}diff --git a/packages/engine-formula/src/functions/financial/vdb/__tests__/index.spec.ts b/packages/engine-formula/src/functions/financial/vdb/__tests__/index.spec.tsindex 827fe41297..a2df7428f9 100644--- a/packages/engine-formula/src/functions/financial/vdb/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/financial/vdb/__tests__/index.spec.ts@@ -16,11 +16,11 @@import { describe, expect, it } from 'vitest';+import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';import { FUNCTION_NAMES_FINANCIAL } from '../../function-names';import { Vdb } from '../index';-import { NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';-import { ErrorType } from '../../../../basics/error-type';describe('Test vdb function', () => {const testFunction = new Vdb(FUNCTION_NAMES_FINANCIAL.VDB);diff --git a/packages/engine-formula/src/functions/financial/vdb/index.ts b/packages/engine-formula/src/functions/financial/vdb/index.tsindex 3816a3cc87..cb807d70b5 100644--- a/packages/engine-formula/src/functions/financial/vdb/index.ts+++ b/packages/engine-formula/src/functions/financial/vdb/index.ts@@ -15,19 +15,22 @@*/import { ErrorType } from '../../../basics/error-type';+import { calculateDDB } from '../../../basics/financial';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { getCurrencyFormat } from '../../../engine/utils/numfmt-kit';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { BooleanValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';-import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';-import { calculateDDB } from '../../../basics/financial';export class Vdb extends BaseFunction {override minParams = 5;override maxParams = 7;+ override needsLocale = true;+override calculate(cost: BaseValueObject,salvage: BaseValueObject,@@ -145,7 +148,7 @@ export class Vdb extends BaseFunction {const result = this._getResult(costValue, salvageValue, lifeValue, startPeriodValue, endPeriodValue, factorValue, noSwitchValue);if (rowIndex === 0 && columnIndex === 0) {- return NumberValueObject.create(result, '"¥"#,##0.00_);[Red]("¥"#,##0.00)');+ return NumberValueObject.create(result, getCurrencyFormat(this.getLocale()));}return NumberValueObject.create(result);diff --git a/packages/engine-formula/src/functions/math/arabic/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/arabic/__tests__/index.spec.tsnew file mode 100644index 0000000000..78fc0efec0--- /dev/null+++ b/packages/engine-formula/src/functions/math/arabic/__tests__/index.spec.ts@@ -0,0 +1,101 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Arabic } from '../index';++describe('Test arabic function', () => {+ const testFunction = new Arabic(FUNCTION_NAMES_MATH.ARABIC);++ describe('Arabic', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('mcmxii');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(1912);+ });++ it('Result is negtive', () => {+ const text = StringValueObject.create('-mcmxii');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(-1912);+ });++ it('Value is number', () => {+ const text = NumberValueObject.create(1);+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const text = BooleanValueObject.create(true);+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is null', () => {+ const text = NullValueObject.create();+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(0);+ });++ it('Value is error', () => {+ const text = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 'mxmvii', true, false, null],+ [0, 'llll', 'LVII', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ [ErrorType.VALUE, ErrorType.VALUE, 1997, ErrorType.VALUE, ErrorType.VALUE, 0],+ [ErrorType.VALUE, ErrorType.VALUE, 57, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['LVII'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual(57);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/arabic/index.ts b/packages/engine-formula/src/functions/math/arabic/index.tsnew file mode 100644index 0000000000..b2b9f037af--- /dev/null+++ b/packages/engine-formula/src/functions/math/arabic/index.ts@@ -0,0 +1,95 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { romanToArabicMap } from '../../../basics/math';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Arabic extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ // eslint-disable-next-line+ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError()) {+ return text;+ }++ if (text.isNull()) {+ return NumberValueObject.create(0);+ }++ if (text.isBoolean() || text.isNumber()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let textValue = text.getValue().toLocaleString().toLocaleUpperCase();++ if (textValue.length > 255) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const isNegtive = textValue.startsWith('-');++ if (isNegtive) {+ textValue = textValue.slice(1);+ }++ let result = 0;++ for (let i = 0; i < textValue.length; i++) {+ const currentCharValue = romanToArabicMap.get(textValue[i]) || 0;+ const nextCharValue = romanToArabicMap.get(textValue[i + 1]) || 0;+ const nextnextCharValue = romanToArabicMap.get(textValue[i + 2]) || 0;+ const nextnextnextCharValue = romanToArabicMap.get(textValue[i + 3]) || 0;++ if (+ !currentCharValue ||+ (nextnextCharValue >= nextCharValue && nextnextCharValue > currentCharValue) ||+ (currentCharValue === nextCharValue && currentCharValue === nextnextCharValue && currentCharValue === nextnextnextCharValue) ||+ currentCharValue === nextCharValue / 2+ ) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (currentCharValue < nextCharValue) {+ result -= currentCharValue;+ } else {+ result += currentCharValue;+ }+ }++ return NumberValueObject.create(isNegtive ? -result : result);+ }+}diff --git a/packages/engine-formula/src/functions/math/function-map.ts b/packages/engine-formula/src/functions/math/function-map.tsindex 7dc524b471..74c71d1016 100644--- a/packages/engine-formula/src/functions/math/function-map.ts+++ b/packages/engine-formula/src/functions/math/function-map.ts@@ -19,6 +19,7 @@ import { Acos } from './acos';import { Acosh } from './acosh';import { Acot } from './acot';import { Acoth } from './acoth';+import { Arabic } from './arabic';import { Asin } from './asin';import { Asinh } from './asinh';import { Atan } from './atan';@@ -68,6 +69,7 @@ import { Radians } from './radians';import { Rand } from './rand';import { Randarray } from './randarray';import { Randbetween } from './randbetween';+import { Roman } from './roman';import { Round } from './round';import { Rounddown } from './rounddown';import { Roundup } from './roundup';@@ -99,6 +101,7 @@ export const functionMath = [[Acosh, FUNCTION_NAMES_MATH.ACOSH],[Acot, FUNCTION_NAMES_MATH.ACOT],[Acoth, FUNCTION_NAMES_MATH.ACOTH],+ [Arabic, FUNCTION_NAMES_MATH.ARABIC],[Asin, FUNCTION_NAMES_MATH.ASIN],[Asinh, FUNCTION_NAMES_MATH.ASINH],[Atan, FUNCTION_NAMES_MATH.ATAN],@@ -147,6 +150,7 @@ export const functionMath = [[Rand, FUNCTION_NAMES_MATH.RAND],[Randarray, FUNCTION_NAMES_MATH.RANDARRAY],[Randbetween, FUNCTION_NAMES_MATH.RANDBETWEEN],+ [Roman, FUNCTION_NAMES_MATH.ROMAN],[Round, FUNCTION_NAMES_MATH.ROUND],[Rounddown, FUNCTION_NAMES_MATH.ROUNDDOWN],[Roundup, FUNCTION_NAMES_MATH.ROUNDUP],diff --git a/packages/engine-formula/src/functions/math/roman/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/roman/__tests__/index.spec.tsnew file mode 100644index 0000000000..41cf5454e8--- /dev/null+++ b/packages/engine-formula/src/functions/math/roman/__tests__/index.spec.ts@@ -0,0 +1,133 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Roman } from '../index';++describe('Test roman function', () => {+ const testFunction = new Roman(FUNCTION_NAMES_MATH.ROMAN);++ describe('Roman', () => {+ it('Value is normal', () => {+ const number = NumberValueObject.create(499);+ const form = NumberValueObject.create(0);+ const result = testFunction.calculate(number, form);+ expect(getObjectValue(result)).toStrictEqual('CDXCIX');+ });++ it('Number value test', () => {+ const number = NumberValueObject.create(-1);+ const form = NumberValueObject.create(0);+ const result = testFunction.calculate(number, form);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);++ const number2 = NumberValueObject.create(4000);+ const result2 = testFunction.calculate(number2, form);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const number3 = NullValueObject.create();+ const result3 = testFunction.calculate(number3, form);+ expect(getObjectValue(result3)).toStrictEqual('');++ const number4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(number4, form);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);++ const number5 = BooleanValueObject.create(true);+ const result5 = testFunction.calculate(number5, form);+ expect(getObjectValue(result5)).toStrictEqual('I');++ const number6 = StringValueObject.create('test');+ const result6 = testFunction.calculate(number6, form);+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);+ });++ it('Form value test', () => {+ const number = NumberValueObject.create(499);+ const form = NumberValueObject.create(-1);+ const result = testFunction.calculate(number, form);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);++ const form2 = NumberValueObject.create(1);+ const result2 = testFunction.calculate(number, form2);+ expect(getObjectValue(result2)).toStrictEqual('LDVLIV');++ const form3 = NumberValueObject.create(2);+ const result3 = testFunction.calculate(number, form3);+ expect(getObjectValue(result3)).toStrictEqual('XDIX');++ const form4 = NumberValueObject.create(3);+ const result4 = testFunction.calculate(number, form4);+ expect(getObjectValue(result4)).toStrictEqual('VDIV');++ const form5 = NumberValueObject.create(4);+ const result5 = testFunction.calculate(number, form5);+ expect(getObjectValue(result5)).toStrictEqual('ID');++ const form6 = NumberValueObject.create(5);+ const result6 = testFunction.calculate(number, form6);+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);++ const form7 = BooleanValueObject.create(true);+ const result7 = testFunction.calculate(number, form7);+ expect(getObjectValue(result7)).toStrictEqual('CDXCIX');++ const form8 = BooleanValueObject.create(false);+ const result8 = testFunction.calculate(number, form8);+ expect(getObjectValue(result8)).toStrictEqual('ID');++ const form9 = NullValueObject.create();+ const result9 = testFunction.calculate(number, form9);+ expect(getObjectValue(result9)).toStrictEqual('CDXCIX');++ const form10 = ErrorValueObject.create(ErrorType.NAME);+ const result10 = testFunction.calculate(number, form10);+ expect(getObjectValue(result10)).toStrictEqual(ErrorType.NAME);++ const form11 = StringValueObject.create('test');+ const result11 = testFunction.calculate(number, form11);+ expect(getObjectValue(result11)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is array', () => {+ const number = NumberValueObject.create(1999);+ const form = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [-1, null, 1.23, 2, '3.2', 4],+ [5, 0, true, false, 'test', ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, form);+ expect(getObjectValue(result)).toStrictEqual([+ [ErrorType.VALUE, 'MCMXCIX', 'MLMVLIV', 'MXMIX', 'MVMIV', 'MIM'],+ [ErrorType.VALUE, 'MCMXCIX', 'MCMXCIX', 'MIM', ErrorType.VALUE, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/roman/index.ts b/packages/engine-formula/src/functions/math/roman/index.tsnew file mode 100644index 0000000000..d82876f8bb--- /dev/null+++ b/packages/engine-formula/src/functions/math/roman/index.ts@@ -0,0 +1,138 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { arabicToRomanMap, romanFormArray } from '../../../basics/math';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Roman extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(number: BaseValueObject, form?: BaseValueObject): BaseValueObject {+ const _form = form ?? NumberValueObject.create(0);++ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ _form.isArray() ? (_form as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ _form.isArray() ? (_form as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const formArray = expandArrayValueObject(maxRowLength, maxColumnLength, _form, ErrorValueObject.create(ErrorType.NA));++ const resultArray = numberArray.mapValue((numberObject, rowIndex, columnIndex) => {+ const formObject = formArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (numberObject.isError()) {+ return numberObject;+ }++ if (formObject.isError()) {+ return formObject;+ }++ return this._handleSingleObject(numberObject, formObject);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(number: BaseValueObject, form: BaseValueObject): BaseValueObject {+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(number);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [numberObject] = variants as BaseValueObject[];++ let numberValue = Math.floor(+numberObject.getValue());++ let _form = form;++ if (_form.isString()) {+ _form = _form.convertToNumberObjectValue();++ if (_form.isError()) {+ return _form;+ }+ }++ let formValue = Math.floor(+_form.getValue());++ if (_form.isBoolean()) {+ formValue = _form.getValue() ? 0 : 4;+ }++ if (numberValue < 0 || numberValue > 3999 || formValue < 0 || formValue > 4) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const formArray = romanFormArray[formValue];++ let index = formArray.length - 1;+ let result = '';++ while (numberValue > 0) {+ index = this._binarySearch(numberValue, 0, index, formArray);++ const number = formArray[index];++ numberValue -= number;++ result += arabicToRomanMap.get(number);+ }++ return StringValueObject.create(result);+ }++ private _binarySearch(target: number, left: number, right: number, array: Array<number>): number {+ let _left = left;+ let _right = right;++ while (_right - _left > 1) {+ const mid = Math.floor((_left + _right) / 2);+ const midValue = array[mid];++ if (midValue === target) {+ return mid;+ }++ if (midValue > target) {+ _right = mid;+ } else {+ _left = mid;+ }+ }++ return _left !== _right && array[_right] <= target ? _right : _left;+ }+}diff --git a/packages/engine-formula/src/functions/statistical/countifs/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/countifs/__tests__/index.spec.tsindex b0c8c8c16f..c3ef85b144 100644--- a/packages/engine-formula/src/functions/statistical/countifs/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/statistical/countifs/__tests__/index.spec.ts@@ -15,11 +15,11 @@*/import { describe, expect, it } from 'vitest';-import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';-import { Countifs } from '../index';+import { ErrorType } from '../../../../basics/error-type';import { ArrayValueObject, transformToValue } from '../../../../engine/value-object/array-value-object';import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ErrorType } from '../../../../basics/error-type';+import { FUNCTION_NAMES_STATISTICAL } from '../../function-names';+import { Countifs } from '../index';describe('Test countifs function', () => {const testFunction = new Countifs(FUNCTION_NAMES_STATISTICAL.COUNTIFS);@@ -234,7 +234,7 @@ describe('Test countifs function', () => {const criteria2 = StringValueObject.create('<5/3/2011');const resultObject = testFunction.calculate(range1, criteria1, range2, criteria2);- expect(transformToValue(resultObject.getArrayValue())).toStrictEqual([[0]]);+ expect(transformToValue(resultObject.getArrayValue())).toStrictEqual([[2]]);});});});diff --git a/packages/engine-formula/src/functions/text/arraytotext/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/arraytotext/__test__/index.spec.tsnew file mode 100644index 0000000000..c62af29d96--- /dev/null+++ b/packages/engine-formula/src/functions/text/arraytotext/__test__/index.spec.ts@@ -0,0 +1,126 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { NullValueObject, NumberValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Arraytotext } from '../index';++describe('Test arraytotext function', () => {+ const testFunction = new Arraytotext(FUNCTION_NAMES_TEXT.ARRAYTOTEXT);++ describe('Arraytotext', () => {+ it('Value is normal', () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const format = NullValueObject.create();+ const result = testFunction.calculate(array, format);+ expect(getObjectValue(result)).toStrictEqual('1, , 1.23, TRUE, FALSE, , 0, 100, 2.34, test, -3, #NAME?');+ });++ it('Format value test', () => {+ const array = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const format = NumberValueObject.create(1);+ const result = testFunction.calculate(array, format);+ expect(getObjectValue(result)).toStrictEqual('{1," ",1.23,TRUE,FALSE,;0,100,2.34,"test",-3,#NAME?}');++ const format2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(array, format2);+ expect(getObjectValue(result2)).toStrictEqual('{1," ",1.23,TRUE,FALSE,;0,100,2.34,"test",-3,#NAME?}');++ const format3 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1],+ [true],+ [false],+ [null],+ [ErrorType.NAME],+ ]),+ rowCount: 5,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result3 = testFunction.calculate(array, format3);+ expect(getObjectValue(result3)).toStrictEqual([+ ['{1," ",1.23,TRUE,FALSE,;0,100,2.34,"test",-3,#NAME?}'],+ ['{1," ",1.23,TRUE,FALSE,;0,100,2.34,"test",-3,#NAME?}'],+ ['1, , 1.23, TRUE, FALSE, , 0, 100, 2.34, test, -3, #NAME?'],+ ['1, , 1.23, TRUE, FALSE, , 0, 100, 2.34, test, -3, #NAME?'],+ [ErrorType.NAME],+ ]);+ });++ it('Value is error', () => {+ const array = ErrorValueObject.create(ErrorType.NAME);+ const format = NullValueObject.create();+ const result = testFunction.calculate(array, format);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const array2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [ErrorType.NAME],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(array2, format);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/arraytotext/index.ts b/packages/engine-formula/src/functions/text/arraytotext/index.tsnew file mode 100644index 0000000000..5f7db44192--- /dev/null+++ b/packages/engine-formula/src/functions/text/arraytotext/index.ts@@ -0,0 +1,131 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../basics/error-type';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Arraytotext extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(array: BaseValueObject, format?: BaseValueObject): BaseValueObject {+ let _format = format ?? NumberValueObject.create(0);++ if (format?.isNull()) {+ _format = NumberValueObject.create(0);+ }++ if (_format.isArray()) {+ const resultArray = (_format as ArrayValueObject).mapValue((formatObject) => this._handleSingleObject(array, formatObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(array, _format);+ }++ private _handleSingleObject(array: BaseValueObject, format: BaseValueObject): BaseValueObject {+ const _array = this._checkArray(array);++ if (_array.isError()) {+ return _array;+ }++ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(format);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [formatObject] = variants as BaseValueObject[];++ const formatValue = +formatObject.getValue();++ const arrayRowCount = array.isArray() ? (array as ArrayValueObject).getRowCount() : 1;+ const arrayColumnCount = array.isArray() ? (array as ArrayValueObject).getColumnCount() : 1;++ let result = '';++ for (let r = 0; r < arrayRowCount; r++) {+ for (let c = 0; c < arrayColumnCount; c++) {+ const valueObject = array.isArray() ? (array as ArrayValueObject).get(r, c) as BaseValueObject : array;++ let value = `${valueObject.getValue()}`;++ if (valueObject.isNull()) {+ value = '';+ }++ if (valueObject.isBoolean()) {+ value = value.toLocaleUpperCase();+ }++ if (valueObject.isString() && formatValue) {+ result += `"${value}"`;+ } else {+ result += value;+ }++ if (!(r === arrayRowCount - 1 && c === arrayColumnCount - 1)) {+ if (formatValue) {+ if (c === arrayColumnCount - 1) {+ result += ';';+ } else {+ result += ',';+ }+ } else {+ result += ', ';+ }+ }+ }+ }++ if (formatValue) {+ result = `{${result}}`;+ }++ if (result.length > 32767) {+ return ErrorValueObject.create(ErrorType.CALC);+ }++ return StringValueObject.create(result);+ }++ private _checkArray(array: BaseValueObject): BaseValueObject {+ if (array.isArray()) {+ const arrayRowCount = (array as ArrayValueObject).getRowCount();+ const arrayColumnCount = (array as ArrayValueObject).getColumnCount();++ if (arrayRowCount > 1 || arrayColumnCount > 1) {+ return array;+ }++ return (array as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return array;+ }+}diff --git a/packages/engine-formula/src/functions/text/asc/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/asc/__test__/index.spec.tsnew file mode 100644index 0000000000..a8a24a8aa8--- /dev/null+++ b/packages/engine-formula/src/functions/text/asc/__test__/index.spec.ts@@ -0,0 +1,76 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Asc } from '../index';++describe('Test asc function', () => {+ const testFunction = new Asc(FUNCTION_NAMES_TEXT.ASC);++ describe('Asc', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('abc');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual('abc');+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null, 'Univer表格シート繁體한국인'],+ [0, '100', 'abc', 'test', -3, ErrorType.NAME, null],+ ]),+ rowCount: 2,+ columnCount: 7,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ [1, ' ', 1.23, true, false, 0, 'Univer表格シート繁體한국인'],+ [0, '100', 'abc', 'test', -3, ErrorType.NAME, 0],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['univer'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual('univer');+ });++ it('More test', () => {+ const text = StringValueObject.create('!@#¥%^&*()_-+=');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual('!@#¥%^&*()_-+=');+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/asc/index.ts b/packages/engine-formula/src/functions/text/asc/index.tsnew file mode 100644index 0000000000..5615cb851f--- /dev/null+++ b/packages/engine-formula/src/functions/text/asc/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 type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Asc extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError() || text.isNull() || text.isBoolean() || text.isNumber()) {+ return text;+ }++ const textValue = text.getValue().toLocaleString();++ let result = '';++ for (let i = 0; i < textValue.length; i++) {+ let charCode = textValue.charCodeAt(i);++ if (charCode === 12288) {+ charCode = 32;+ } else if (charCode >= 65281 && charCode <= 65374) {+ charCode -= 65248;+ }++ result += String.fromCharCode(charCode);+ }++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/bahttext/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/bahttext/__test__/index.spec.tsnew file mode 100644index 0000000000..264e30f948--- /dev/null+++ b/packages/engine-formula/src/functions/text/bahttext/__test__/index.spec.ts@@ -0,0 +1,96 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Bahttext } from '../index';++describe('Test bahttext function', () => {+ const testFunction = new Bahttext(FUNCTION_NAMES_TEXT.BAHTTEXT);++ describe('Bahttext', () => {+ it('Value is normal', () => {+ const number = NumberValueObject.create(123.45);+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual('หนึ่งร้อยยี่สิบสามบาทสี่สิบห้าสตางค์');+ });++ it('Number is negative', () => {+ const number = NumberValueObject.create(-2.34);+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual('ลบสองบาทสามสิบสี่สตางค์');+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual([+ ['หนึ่งบาทถ้วน', ErrorType.VALUE, 'หนึ่งบาทยี่สิบสามสตางค์', 'หนึ่งบาทถ้วน', 'ศูนย์บาทถ้วน', 'ศูนย์บาทถ้วน'],+ ['ศูนย์บาทถ้วน', 'หนึ่งร้อยบาทถ้วน', 'สองบาทสามสิบสี่สตางค์', ErrorType.VALUE, 'ลบสามบาทถ้วน', ErrorType.NAME],+ ]);++ const number2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1234567890],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(number2);+ expect(getObjectValue(result2)).toStrictEqual('หนึ่งพันสองร้อยสามสิบสี่ล้านห้าแสนหกหมื่นเจ็ดพันแปดร้อยเก้าสิบบาทถ้วน');+ });++ it('More test', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [0.123, 1111111],+ [10000000, 11],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual([+ ['สิบสองสตางค์', 'หนึ่งล้านหนึ่งแสนหนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบเอ็ดบาทถ้วน'],+ ['สิบล้านบาทถ้วน', 'สิบเอ็ดบาทถ้วน'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/bahttext/index.ts b/packages/engine-formula/src/functions/text/bahttext/index.tsnew file mode 100644index 0000000000..f663225934--- /dev/null+++ b/packages/engine-formula/src/functions/text/bahttext/index.ts@@ -0,0 +1,122 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Bahttext extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject): BaseValueObject {+ if (number.isArray()) {+ const resultArray = (number as ArrayValueObject).mapValue((numberObject) => this._handleSingleObject(numberObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(number);+ }++ private _handleSingleObject(number: BaseValueObject): BaseValueObject {+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(number);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [numberObject] = variants as BaseValueObject[];++ const numberValue = +numberObject.getValue();++ const integerPart = Math.abs(Number.parseInt(numberValue.toString(), 10));+ const decimalPart = Number.parseFloat((Math.abs(numberValue) - integerPart).toFixed(2));++ let result = '';++ if (integerPart === 0) {+ if (decimalPart !== 0) {+ result = `${numberValue < 0 ? 'ลบ' : ''}${this._convertNumberToThaiText(decimalPart * 100)}สตางค์`;+ } else {+ result = 'ศูนย์บาทถ้วน';+ }+ } else {+ if (decimalPart === 0) {+ result = `${numberValue < 0 ? 'ลบ' : ''}${this._convertNumberToThaiText(integerPart)}บาทถ้วน`;+ } else {+ result = `${numberValue < 0 ? 'ลบ' : ''}${this._convertNumberToThaiText(integerPart)}บาท${this._convertNumberToThaiText(decimalPart * 100)}สตางค์`;+ }+ }++ return StringValueObject.create(result);+ }++ private _convertNumberToThaiText(number: number): string {+ const units = ['ล้าน', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', '']; // 10^6, 10^1, 10^2, 10^3, 10^4, 10^5, 10^0+ const digits = ['ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า']; // 0~9+ const special = ['ลบ', 'บาท', 'ถ้วน', 'สตางค์', 'ยี่', 'เอ็ด', ',', ' ', '฿']; // minus, baht, integer, satang, two, one, comma, space, baht symbol++ const numberText = number.toString();+ const n = numberText.length;++ let result = '';++ for (let i = n; i > 0; i--) {+ const digit = Number.parseInt(numberText.charAt(n - i), 10);++ let digitText = digits[digit];+ const position = i > 1 ? (i - 1) % 6 : 6;++ if (position === 1 && digit === 2) {+ digitText = special[4];+ }++ if (digit === 1) {+ switch (position) {+ case 0:+ case 6:+ result += i < n ? special[5] : digitText;+ break;+ case 1:+ break;+ default:+ result += digitText;+ break;+ }+ } else if (digit === 0) {+ if (position === 0) {+ result += units[position];+ }++ continue;+ } else {+ result += digitText;+ }++ result += units[position];+ }++ return result;+ }+}diff --git a/packages/engine-formula/src/functions/text/char/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/char/__test__/index.spec.tsnew file mode 100644index 0000000000..e483b4cf5b--- /dev/null+++ b/packages/engine-formula/src/functions/text/char/__test__/index.spec.ts@@ -0,0 +1,80 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Char } from '../index';++describe('Test char function', () => {+ const testFunction = new Char(FUNCTION_NAMES_TEXT.CHAR);++ describe('Char', () => {+ it('Value is normal', () => {+ const number = NumberValueObject.create(123.45);+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual('{');+ });++ it('Number is negative', () => {+ const number = NumberValueObject.create(-2.34);+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual([+ ['', ErrorType.VALUE, '', '', ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, 'd', '', ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ ]);++ const number2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1234567890],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(number2);+ expect(getObjectValue(result2)).toStrictEqual('˒');++ const number3 = NumberValueObject.create(28);+ const result3 = testFunction.calculate(number3);+ expect(getObjectValue(result3)).toStrictEqual('');+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/char/index.ts b/packages/engine-formula/src/functions/text/char/index.tsnew file mode 100644index 0000000000..ef10e774d4--- /dev/null+++ b/packages/engine-formula/src/functions/text/char/index.ts@@ -0,0 +1,84 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { DataStreamTreeTokenType } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++// special case for some characters causing doc stream issues+const filterCodeArray = Object.values(DataStreamTreeTokenType).filter((value) => {+ return [+ DataStreamTreeTokenType.TABLE_START,+ DataStreamTreeTokenType.TABLE_ROW_START,+ DataStreamTreeTokenType.TABLE_CELL_START,+ DataStreamTreeTokenType.TABLE_CELL_END,+ DataStreamTreeTokenType.TABLE_ROW_END,+ DataStreamTreeTokenType.TABLE_END,+ DataStreamTreeTokenType.CUSTOM_RANGE_START,+ DataStreamTreeTokenType.CUSTOM_RANGE_END,+ DataStreamTreeTokenType.CUSTOM_BLOCK,+ ].includes(value as DataStreamTreeTokenType);+});++export class Char extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject): BaseValueObject {+ if (number.isArray()) {+ const resultArray = (number as ArrayValueObject).mapValue((numberObject) => this._handleSingleObject(numberObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(number);+ }++ private _handleSingleObject(number: BaseValueObject): BaseValueObject {+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(number);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [numberObject] = variants as BaseValueObject[];++ const numberValue = Math.floor(+numberObject.getValue());++ if (numberValue <= 0) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let result = String.fromCharCode(numberValue);++ // special case for some characters causing doc stream issues+ if (filterCodeArray.some((value) => value === result)) {+ result = String.fromCharCode(1);+ }++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/clean/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/clean/__test__/index.spec.tsnew file mode 100644index 0000000000..787fb98a0b--- /dev/null+++ b/packages/engine-formula/src/functions/text/clean/__test__/index.spec.ts@@ -0,0 +1,70 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Clean } from '../index';++describe('Test clean function', () => {+ const testFunction = new Clean(FUNCTION_NAMES_TEXT.CLEAN);++ describe('Clean', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('月度报表');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual('月度报表');+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ [1, ' ', 1.23, true, false, ''],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['123'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual('123');+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/clean/index.ts b/packages/engine-formula/src/functions/text/clean/index.tsnew file mode 100644index 0000000000..5ff577c1e9--- /dev/null+++ b/packages/engine-formula/src/functions/text/clean/index.ts@@ -0,0 +1,57 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Clean extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError() || text.isBoolean() || text.isNumber()) {+ return text;+ }++ if (text.isNull()) {+ return StringValueObject.create('');+ }++ const textValue = `${text.getValue()}`;++ // eslint-disable-next-line no-control-regex+ const result = textValue.replace(/[\0-\x1F]/g, '');++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/code/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/code/__test__/index.spec.tsnew file mode 100644index 0000000000..cece962f34--- /dev/null+++ b/packages/engine-formula/src/functions/text/code/__test__/index.spec.ts@@ -0,0 +1,76 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Code } from '../index';++describe('Test code function', () => {+ const testFunction = new Code(FUNCTION_NAMES_TEXT.CODE);++ describe('Code', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('A');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(65);+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文', true, false, null],+ [0, 'ABC', '!', 'ÿ', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ [49, 32, 20013, 84, 70, ErrorType.VALUE],+ [48, 65, 33, 255, 45, ErrorType.NAME],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['หนึ่งบาทถ้วน'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual(3627);+ });++ it('More test', () => {+ const text = StringValueObject.create('');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/code/index.ts b/packages/engine-formula/src/functions/text/code/index.tsnew file mode 100644index 0000000000..84a8ef7f23--- /dev/null+++ b/packages/engine-formula/src/functions/text/code/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 type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Code extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError()) {+ return text;+ }++ if (text.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let textValue = text.getValue().toLocaleString();++ if (text.isBoolean()) {+ textValue = textValue.toLocaleUpperCase();+ }++ if (textValue === '') {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const result = textValue.charCodeAt(0);++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/dbcs/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/dbcs/__test__/index.spec.tsnew file mode 100644index 0000000000..6cd96a70d7--- /dev/null+++ b/packages/engine-formula/src/functions/text/dbcs/__test__/index.spec.ts@@ -0,0 +1,71 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Dbcs } from '../index';++describe('Test dbcs function', () => {+ const testFunction = new Dbcs(FUNCTION_NAMES_TEXT.DBCS);++ describe('Dbcs', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('abc');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual('abc');+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null, 'Univer表格シート繁體한국인'],+ [0, '100', 'abc', 'test', -3, ErrorType.NAME, null],++ ]),+ rowCount: 2,+ columnCount: 7,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ ['1', ' ', '1.23', 'TRUE', 'FALSE', '', 'Univer表格シート繁體한국인'],+ ['0', '100', 'abc', 'test', '-3', ErrorType.NAME, ''],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['univer'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual('univer');+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/dbcs/index.ts b/packages/engine-formula/src/functions/text/dbcs/index.tsnew file mode 100644index 0000000000..d326a1c447--- /dev/null+++ b/packages/engine-formula/src/functions/text/dbcs/index.ts@@ -0,0 +1,72 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Dbcs extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError()) {+ return text;+ }++ if (text.isNull()) {+ return StringValueObject.create('');+ }++ let textValue = `${text.getValue()}`;++ if (text.isBoolean()) {+ textValue = textValue.toLocaleUpperCase();+ }++ let result = '';++ for (let i = 0; i < textValue.length; i++) {+ const char = textValue.charCodeAt(i);++ if (char >= 0x21 && char <= 0x7E) {+ result += String.fromCharCode(char + 0xFEE0);+ } else if (char === 0x20) {+ result += String.fromCharCode(0x3000);+ } else {+ result += textValue.charAt(i);+ }+ }++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/dollar/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/dollar/__test__/index.spec.tsnew file mode 100644index 0000000000..2a0b3fcf05--- /dev/null+++ b/packages/engine-formula/src/functions/text/dollar/__test__/index.spec.ts@@ -0,0 +1,115 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Dollar } from '../index';++describe('Test dollar function', () => {+ const testFunction = new Dollar(FUNCTION_NAMES_TEXT.DOLLAR);++ describe('Dollar', () => {+ it('Value is normal', () => {+ const number = NumberValueObject.create(1234.567);+ const decimals = NullValueObject.create();+ const result = testFunction.calculate(number, decimals);+ expect(getObjectValue(result)).toStrictEqual('$1,234.57 ');+ });++ it('Value is negative', () => {+ const number = NumberValueObject.create(-1234.567);+ const decimals = NullValueObject.create();+ const result = testFunction.calculate(number, decimals);+ expect(getObjectValue(result)).toStrictEqual('($1,234.57)');+ });++ it('Decimals value test', () => {+ const number = NumberValueObject.create(1234.567);+ const decimals = NumberValueObject.create(-2);+ const result = testFunction.calculate(number, decimals);+ expect(getObjectValue(result)).toStrictEqual('$1,200 ');++ const decimals2 = NumberValueObject.create(-4);+ const result2 = testFunction.calculate(number, decimals2);+ expect(getObjectValue(result2)).toStrictEqual('$0 ');++ const decimals3 = NumberValueObject.create(4);+ const result3 = testFunction.calculate(number, decimals3);+ expect(getObjectValue(result3)).toStrictEqual('$1,234.5670 ');++ const decimals4 = NumberValueObject.create(128);+ const result4 = testFunction.calculate(number, decimals4);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);++ const decimals5 = NumberValueObject.create(-10);+ const result5 = testFunction.calculate(number, decimals5);+ expect(getObjectValue(result5)).toStrictEqual('$0 ');+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const decimals = NullValueObject.create();+ const result = testFunction.calculate(number, decimals);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = BooleanValueObject.create(true);+ const decimals = NullValueObject.create();+ const result = testFunction.calculate(number, decimals);+ expect(getObjectValue(result)).toStrictEqual('$1.00 ');+ });++ it('Value is error', () => {+ const number = NumberValueObject.create(1234.567);+ const decimals = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(number, decimals);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const number2 = ErrorValueObject.create(ErrorType.NAME);+ const decimals2 = NumberValueObject.create(2);+ const result2 = testFunction.calculate(number2, decimals2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const decimals = NullValueObject.create();+ const result = testFunction.calculate(number, decimals);+ expect(getObjectValue(result)).toStrictEqual([+ ['$1.00 ', ErrorType.VALUE, '$1.23 ', '$1.00 ', '$0.00 ', '$0.00 '],+ ['$0.00 ', '$100.00 ', '$2.34 ', ErrorType.VALUE, '($3.00)', ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/dollar/index.ts b/packages/engine-formula/src/functions/text/dollar/index.tsnew file mode 100644index 0000000000..eb71f47e0d--- /dev/null+++ b/packages/engine-formula/src/functions/text/dollar/index.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 type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { round } from '../../../engine/utils/math-kit';+import { applyCurrencyFormat } from '../../../engine/utils/numfmt-kit';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Dollar extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override needsLocale = true;++ override calculate(number: BaseValueObject, decimals?: BaseValueObject): BaseValueObject {+ let _decimals = decimals ?? NumberValueObject.create(2);++ if (_decimals.isNull()) {+ _decimals = NumberValueObject.create(2);+ }++ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ _decimals.isArray() ? (_decimals as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ _decimals.isArray() ? (_decimals as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const decimalsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _decimals, ErrorValueObject.create(ErrorType.NA));++ const resultArray = numberArray.mapValue((numberObject, rowIndex, columnIndex) => {+ const decimalsObject = decimalsArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (numberObject.isError()) {+ return numberObject;+ }++ if (decimalsObject.isError()) {+ return decimalsObject;+ }++ return this._handleSingleObject(numberObject, decimalsObject);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(number: BaseValueObject, decimals: BaseValueObject): BaseValueObject {+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(number, decimals);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [numberObject, decimalsObject] = variants as BaseValueObject[];++ let numberValue = +numberObject.getValue();+ let decimalsValue = Math.trunc(+decimalsObject.getValue());++ if (decimalsValue > 127) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (decimalsValue < 0) {+ if (`${numberValue}`.length < Math.abs(decimalsValue)) {+ numberValue = 0;+ } else {+ numberValue = numberValue < 0 ? -round(Math.abs(numberValue), decimalsValue) : round(numberValue, decimalsValue);+ }++ decimalsValue = 0;+ }++ const result = applyCurrencyFormat(this.getLocale(), numberValue, decimalsValue);++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/exact/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/exact/__test__/index.spec.tsnew file mode 100644index 0000000000..fd256fb35d--- /dev/null+++ b/packages/engine-formula/src/functions/text/exact/__test__/index.spec.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 { describe, expect, it } from 'vitest';++import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Exact } from '../index';++describe('Test exact function', () => {+ const testFunction = new Exact(FUNCTION_NAMES_TEXT.EXACT);++ describe('Exact', () => {+ it('Value is normal', () => {+ const text1 = StringValueObject.create('univer');+ const text2 = StringValueObject.create('univer');+ const result = testFunction.calculate(text1, text2);+ expect(getObjectValue(result)).toStrictEqual(true);+ });++ it('Value is normal string, but different case', () => {+ const text1 = StringValueObject.create('univer');+ const text2 = StringValueObject.create('Univer');+ const result = testFunction.calculate(text1, text2);+ expect(getObjectValue(result)).toStrictEqual(false);++ const text3 = StringValueObject.create('u niver');+ const result2 = testFunction.calculate(text1, text3);+ expect(getObjectValue(result2)).toStrictEqual(false);+ });++ it('Value is number and number string', () => {+ const text1 = NumberValueObject.create(123);+ const text2 = StringValueObject.create('123');+ const result = testFunction.calculate(text1, text2);+ expect(getObjectValue(result)).toStrictEqual(true);+ });++ it('Value is boolean', () => {+ const text1 = BooleanValueObject.create(true);+ const text2 = BooleanValueObject.create(false);+ const result = testFunction.calculate(text1, text2);+ expect(getObjectValue(result)).toStrictEqual(false);++ const text3 = StringValueObject.create('true');+ const result2 = testFunction.calculate(text1, text3);+ expect(getObjectValue(result2)).toStrictEqual(false);++ const text4 = StringValueObject.create('TRUE');+ const result3 = testFunction.calculate(text1, text4);+ expect(getObjectValue(result3)).toStrictEqual(true);+ });++ it('Value is error', () => {+ const text1 = ErrorValueObject.create(ErrorType.NAME);+ const text2 = StringValueObject.create('univer');+ const result = testFunction.calculate(text1, text2);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const text3 = StringValueObject.create('univer');+ const text4 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(text3, text4);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);+ });++ it('Value is array', () => {+ const text1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const text2 = NullValueObject.create();+ const result = testFunction.calculate(text1, text2);+ expect(getObjectValue(result)).toStrictEqual([+ [false, false, false, false, false, true],+ [false, false, false, false, false, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/exact/index.ts b/packages/engine-formula/src/functions/text/exact/index.tsnew file mode 100644index 0000000000..149e35d9a5--- /dev/null+++ b/packages/engine-formula/src/functions/text/exact/index.ts@@ -0,0 +1,86 @@+/**+ * 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 { BooleanValueObject, NullValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';++export class Exact extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(text1: BaseValueObject, text2: BaseValueObject): BaseValueObject {+ const maxRowLength = Math.max(+ text1.isArray() ? (text1 as ArrayValueObject).getRowCount() : 1,+ text2.isArray() ? (text2 as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ text1.isArray() ? (text1 as ArrayValueObject).getColumnCount() : 1,+ text2.isArray() ? (text2 as ArrayValueObject).getColumnCount() : 1+ );++ const text1Array = expandArrayValueObject(maxRowLength, maxColumnLength, text1, NullValueObject.create());+ const text2Array = expandArrayValueObject(maxRowLength, maxColumnLength, text2, NullValueObject.create());++ const resultArray = text1Array.mapValue((text1Object, rowIndex, columnIndex) => {+ const text2Object = text2Array.get(rowIndex, columnIndex) as BaseValueObject;++ if (text1Object.isError()) {+ return text1Object;+ }++ if (text2Object.isError()) {+ return text2Object;+ }++ return this._handleSingleObject(text1Object, text2Object);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(text1: BaseValueObject, text2: BaseValueObject): BaseValueObject {+ if (text1.isNull() || text2.isNull()) {+ const result = text1.isNull() && text2.isNull();++ return BooleanValueObject.create(result);+ }++ let text1Value = `${text1.getValue()}`;++ if (text1.isBoolean()) {+ text1Value = text1Value.toLocaleUpperCase();+ }++ let text2Value = `${text2.getValue()}`;++ if (text2.isBoolean()) {+ text2Value = text2Value.toLocaleUpperCase();+ }++ const result = text1Value === text2Value;++ return BooleanValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/fixed/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/fixed/__test__/index.spec.tsnew file mode 100644index 0000000000..d713a8280d--- /dev/null+++ b/packages/engine-formula/src/functions/text/fixed/__test__/index.spec.ts@@ -0,0 +1,134 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Fixed } from '../index';++describe('Test fixed function', () => {+ const testFunction = new Fixed(FUNCTION_NAMES_TEXT.FIXED);++ describe('Fixed', () => {+ it('Value is normal', () => {+ const number = NumberValueObject.create(1234.567);+ const decimals = NullValueObject.create();+ const noCommas = NullValueObject.create();+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual('1,234.57');+ });++ it('Value is negative', () => {+ const number = NumberValueObject.create(-1234.567);+ const decimals = NullValueObject.create();+ const noCommas = NullValueObject.create();+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual('-1,234.57');+ });++ it('Decimals value test', () => {+ const number = NumberValueObject.create(1234.567);+ const decimals = NumberValueObject.create(-2);+ const noCommas = NullValueObject.create();+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual('1,200');++ const decimals2 = NumberValueObject.create(-4);+ const result2 = testFunction.calculate(number, decimals2, noCommas);+ expect(getObjectValue(result2)).toStrictEqual('0');++ const decimals3 = NumberValueObject.create(4);+ const result3 = testFunction.calculate(number, decimals3, noCommas);+ expect(getObjectValue(result3)).toStrictEqual('1,234.5670');++ const decimals4 = NumberValueObject.create(128);+ const result4 = testFunction.calculate(number, decimals4, noCommas);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);++ const decimals5 = NumberValueObject.create(-10);+ const result5 = testFunction.calculate(number, decimals5, noCommas);+ expect(getObjectValue(result5)).toStrictEqual('0');+ });++ it('NoCommas value test', () => {+ const number = NumberValueObject.create(1234.567);+ const decimals = NullValueObject.create();+ const noCommas = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual('1234.57');+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const decimals = NullValueObject.create();+ const noCommas = NullValueObject.create();+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = BooleanValueObject.create(true);+ const decimals = NullValueObject.create();+ const noCommas = NullValueObject.create();+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual('1.00');+ });++ it('Value is error', () => {+ const number = NumberValueObject.create(1234.567);+ const decimals = ErrorValueObject.create(ErrorType.NAME);+ const noCommas = NullValueObject.create();+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const number2 = ErrorValueObject.create(ErrorType.NAME);+ const decimals2 = NumberValueObject.create(2);+ const result2 = testFunction.calculate(number2, decimals2, noCommas);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.NAME);++ const noCommas2 = ErrorValueObject.create(ErrorType.NAME);+ const result3 = testFunction.calculate(number, decimals2, noCommas2);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const decimals = NullValueObject.create();+ const noCommas = NullValueObject.create();+ const result = testFunction.calculate(number, decimals, noCommas);+ expect(getObjectValue(result)).toStrictEqual([+ ['1.00', ErrorType.VALUE, '1.23', '1.00', '0.00', '0.00'],+ ['0.00', '100.00', '2.34', ErrorType.VALUE, '-3.00', ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/fixed/index.ts b/packages/engine-formula/src/functions/text/fixed/index.tsnew file mode 100644index 0000000000..d8c7806368--- /dev/null+++ b/packages/engine-formula/src/functions/text/fixed/index.ts@@ -0,0 +1,125 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../basics/error-type';+import { getFormatPreview } from '../../../basics/format';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { round } from '../../../engine/utils/math-kit';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Fixed extends BaseFunction {+ override minParams = 1;++ override maxParams = 3;++ override calculate(number: BaseValueObject, decimals?: BaseValueObject, noCommas?: BaseValueObject): BaseValueObject {+ let _decimals = decimals ?? NumberValueObject.create(2);++ if (_decimals.isNull()) {+ _decimals = NumberValueObject.create(2);+ }++ let _noCommas = noCommas ?? BooleanValueObject.create(false);++ if (_noCommas.isNull()) {+ _noCommas = BooleanValueObject.create(false);+ }++ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ _decimals.isArray() ? (_decimals as ArrayValueObject).getRowCount() : 1,+ _noCommas.isArray() ? (_noCommas as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ _decimals.isArray() ? (_decimals as ArrayValueObject).getColumnCount() : 1,+ _noCommas.isArray() ? (_noCommas as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const decimalsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _decimals, ErrorValueObject.create(ErrorType.NA));+ const noCommasArray = expandArrayValueObject(maxRowLength, maxColumnLength, _noCommas, ErrorValueObject.create(ErrorType.NA));++ const resultArray = numberArray.mapValue((numberObject, rowIndex, columnIndex) => {+ const decimalsObject = decimalsArray.get(rowIndex, columnIndex) as BaseValueObject;+ const noCommasObject = noCommasArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (numberObject.isError()) {+ return numberObject;+ }++ if (decimalsObject.isError()) {+ return decimalsObject;+ }++ if (noCommasObject.isError()) {+ return noCommasObject;+ }++ return this._handleSingleObject(numberObject, decimalsObject, noCommasObject);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(number: BaseValueObject, decimals: BaseValueObject, noCommas: BaseValueObject): BaseValueObject {+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(number, decimals, noCommas);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [numberObject, decimalsObject, noCommasObject] = variants as BaseValueObject[];++ let numberValue = +numberObject.getValue();+ let decimalsValue = Math.trunc(+decimalsObject.getValue());+ const noCommasValue = +noCommasObject.getValue();++ if (decimalsValue > 127) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (decimalsValue < 0) {+ if (`${numberValue}`.length < Math.abs(decimalsValue)) {+ numberValue = 0;+ } else {+ numberValue = numberValue < 0 ? -round(Math.abs(numberValue), decimalsValue) : round(numberValue, decimalsValue);+ }++ decimalsValue = 0;+ }++ let pattern = noCommasValue ? '###0' : '#,##0';++ if (decimalsValue > 0) {+ pattern += `.${'0'.repeat(decimalsValue)}`;+ }++ const result = getFormatPreview(pattern, numberValue);++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/function-map.ts b/packages/engine-formula/src/functions/text/function-map.tsindex bd1f549037..611df6df11 100644--- a/packages/engine-formula/src/functions/text/function-map.ts+++ b/packages/engine-formula/src/functions/text/function-map.ts@@ -14,8 +14,18 @@* limitations under the License.*/+import { Arraytotext } from './arraytotext';+import { Asc } from './asc';+import { Bahttext } from './bahttext';+import { Char } from './char';+import { Clean } from './clean';+import { Code } from './code';import { Concat } from './concat';import { Concatenate } from './concatenate';+import { Dbcs } from './dbcs';+import { Dollar } from './dollar';+import { Exact } from './exact';+import { Fixed } from './fixed';import { FUNCTION_NAMES_TEXT } from './function-names';import { Leftb } from './leftb';import { Len } from './len';@@ -25,15 +35,36 @@ import { Mid } from './mid';import { Regexextract } from './regexextract';import { Regexmatch } from './regexmatch';import { Regexreplace } from './regexreplace';+import { Numbervalue } from './numbervalue';+import { Proper } from './proper';import { Rept } from './rept';+import { Right } from './right';+import { Rightb } from './rightb';+import { Substitute } from './substitute';+import { T } from './t';import { Text } from './text';import { Textafter } from './textafter';import { Textbefore } from './textbefore';import { Textsplit } from './textsplit';+import { Unichar } from './unichar';+import { Unicode } from './unicode';+import { Value } from './value';+import { Valuetotext } from './valuetotext';export const functionText = [+ [Asc, FUNCTION_NAMES_TEXT.ASC],+ [Arraytotext, FUNCTION_NAMES_TEXT.ARRAYTOTEXT],+ [Bahttext, FUNCTION_NAMES_TEXT.BAHTTEXT],+ [Char, FUNCTION_NAMES_TEXT.CHAR],+ [Clean, FUNCTION_NAMES_TEXT.CLEAN],+ [Code, FUNCTION_NAMES_TEXT.CODE],[Concat, FUNCTION_NAMES_TEXT.CONCAT],[Concatenate, FUNCTION_NAMES_TEXT.CONCATENATE],+ [Dbcs, FUNCTION_NAMES_TEXT.DBCS],+ [Dollar, FUNCTION_NAMES_TEXT.DOLLAR],+ [Exact, FUNCTION_NAMES_TEXT.EXACT],+ [Fixed, FUNCTION_NAMES_TEXT.FIXED],+ [Leftb, FUNCTION_NAMES_TEXT.LEFTB],[Len, FUNCTION_NAMES_TEXT.LEN],[Lenb, FUNCTION_NAMES_TEXT.LENB],[Lower, FUNCTION_NAMES_TEXT.LOWER],@@ -41,10 +72,19 @@ export const functionText = [[Regexextract, FUNCTION_NAMES_TEXT.REGEXEXTRACT],[Regexmatch, FUNCTION_NAMES_TEXT.REGEXMATCH],[Regexreplace, FUNCTION_NAMES_TEXT.REGEXREPLACE],+ [Numbervalue, FUNCTION_NAMES_TEXT.NUMBERVALUE],+ [Proper, FUNCTION_NAMES_TEXT.PROPER],[Rept, FUNCTION_NAMES_TEXT.REPT],+ [Right, FUNCTION_NAMES_TEXT.RIGHT],+ [Rightb, FUNCTION_NAMES_TEXT.RIGHTB],+ [Substitute, FUNCTION_NAMES_TEXT.SUBSTITUTE],+ [T, FUNCTION_NAMES_TEXT.T],[Text, FUNCTION_NAMES_TEXT.TEXT],[Textafter, FUNCTION_NAMES_TEXT.TEXTAFTER],[Textbefore, FUNCTION_NAMES_TEXT.TEXTBEFORE],[Textsplit, FUNCTION_NAMES_TEXT.TEXTSPLIT],- [Leftb, FUNCTION_NAMES_TEXT.LEFTB],+ [Unichar, FUNCTION_NAMES_TEXT.UNICHAR],+ [Unicode, FUNCTION_NAMES_TEXT.UNICODE],+ [Value, FUNCTION_NAMES_TEXT.VALUE],+ [Valuetotext, FUNCTION_NAMES_TEXT.VALUETOTEXT],];diff --git a/packages/engine-formula/src/functions/text/leftb/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/leftb/__test__/index.spec.tsindex e179b7574c..191a9f2c3a 100644--- a/packages/engine-formula/src/functions/text/leftb/__test__/index.spec.ts+++ b/packages/engine-formula/src/functions/text/leftb/__test__/index.spec.ts@@ -17,8 +17,9 @@import { describe, expect, it } from 'vitest';import { ErrorType } from '../../../../basics/error-type';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';import { FUNCTION_NAMES_TEXT } from '../../function-names';import { Leftb } from '../index';@@ -31,40 +32,40 @@ describe('Test LEFTB function', () => {const text = StringValueObject.create('Hello World');const numBytes = NumberValueObject.create(5);const result = leftbFunction.calculate(text, numBytes);- expect(transformToValue(result.getArrayValue())).toStrictEqual([['Hello']]);+ expect(getObjectValue(result)).toStrictEqual('Hello');});it('Should return full text if byte length exceeds text length', () => {const text = StringValueObject.create('Hello');const numBytes = NumberValueObject.create(10); // Exceeding text lengthconst result = leftbFunction.calculate(text, numBytes);- expect(transformToValue(result.getArrayValue())).toStrictEqual([['Hello']]);+ expect(getObjectValue(result)).toStrictEqual('Hello');});it('Should handle zero byte length correctly', () => {const text = StringValueObject.create('Hello');const numBytes = NumberValueObject.create(0); // Zero byte lengthconst result = leftbFunction.calculate(text, numBytes);- expect(transformToValue(result.getArrayValue())).toStrictEqual([['']]);+ expect(getObjectValue(result)).toStrictEqual('');});it('Should return ErrorType.VALUE for negative byte length', () => {const text = StringValueObject.create('Hello');const numBytes = NumberValueObject.create(-1); // Negative byte lengthconst result = leftbFunction.calculate(text, numBytes);- expect(transformToValue(result.getArrayValue())).toStrictEqual([[ErrorType.VALUE]]);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);});it('Should handle emojis and byte length correctly', () => {const text = StringValueObject.create('😊Hello');- const numBytes = NumberValueObject.create(1); // Bytes needed to capture '😊'+ const numBytes = NumberValueObject.create(3); // Bytes needed to capture '😊'const result = leftbFunction.calculate(text, numBytes);- expect(transformToValue(result.getArrayValue())).toStrictEqual([['😊']]);+ expect(getObjectValue(result)).toStrictEqual('😊');});});it('Extracts characters from array by specifying single numChar', () => {- const textArray = new ArrayValueObject({+ const text = new ArrayValueObject({calculateValueList: transformToValueObject([['Hello'],['World'],@@ -78,17 +79,18 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const numChars = NumberValueObject.create(3);- const result = leftbFunction.calculate(textArray, numChars);- expect(transformToValue(result.getArrayValue())).toStrictEqual([+ const numBytes = NumberValueObject.create(3);+ const result = leftbFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual([['Hel'], // First character of 'Hello'['Wor'], // First two characters of 'World'['New'], // First three characters of 'Test'['Exa'], // First four characters of 'Example']);});+it('Extracts characters from array', () => {- const textArray = new ArrayValueObject({+ const text = new ArrayValueObject({calculateValueList: transformToValueObject([['Hello'],['World'],@@ -102,7 +104,7 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const numCharsArray = new ArrayValueObject({+ const numBytes = new ArrayValueObject({calculateValueList: transformToValueObject([[1],[2],@@ -116,8 +118,8 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const result = leftbFunction.calculate(textArray, numCharsArray);- expect(transformToValue(result.getArrayValue())).toStrictEqual([+ const result = leftbFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual([['H'], // First character of 'Hello'['Wo'], // First two characters of 'World'['Tes'], // First three characters of 'Test'@@ -126,7 +128,7 @@ describe('Test LEFTB function', () => {});it('Handles numChars not provided for array', () => {- const textArray = new ArrayValueObject({+ const text = new ArrayValueObject({calculateValueList: transformToValueObject([['Hello'],['World'],@@ -140,30 +142,31 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const result = leftbFunction.calculate(textArray);- expect(transformToValue(result.getArrayValue())).toStrictEqual([+ const result = leftbFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([['H'], // Default to first character of 'Hello'['W'], // Default to first character of 'World'['T'], // Default to first character of 'Test'['E'], // Default to first character of 'Example']);});+it('Handles extracting from text with emojis', () => {const text = StringValueObject.create('Hello 😊 World');- const numChars = NumberValueObject.create(7);- const result = leftbFunction.calculate(text, numChars);- expect(transformToValue(result.getArrayValue())).toStrictEqual([['Hello 😊']]);+ const numBytes = NumberValueObject.create(9);+ const result = leftbFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual('Hello 😊');});it('Handles extracting with numChars as zero', () => {const text = StringValueObject.create('Hello');- const numChars = NumberValueObject.create(0);- const result = leftbFunction.calculate(text, numChars);- expect(transformToValue(result.getArrayValue())).toStrictEqual([['']]);+ const numBytes = NumberValueObject.create(0);+ const result = leftbFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual('');});it('Handles extracting CJK, first byte', () => {- const textArray = new ArrayValueObject({+ const text = new ArrayValueObject({calculateValueList: transformToValueObject([['销售额'],['から'],@@ -176,16 +179,16 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const result = leftbFunction.calculate(textArray);- expect(transformToValue(result.getArrayValue())).toStrictEqual([- [''],- [''],- [''],+ const result = leftbFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ ['销'],+ ['か'],+ ['이'],]);});it('Handles extracting CJK, first character', () => {- const textArray = new ArrayValueObject({+ const text = new ArrayValueObject({calculateValueList: transformToValueObject([['销售额'],['から'],@@ -198,15 +201,17 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const result = leftbFunction.calculate(textArray, NumberValueObject.create(2));- expect(transformToValue(result.getArrayValue())).toStrictEqual([+ const numBytes = NumberValueObject.create(2);+ const result = leftbFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual([['销'],['か'],['이'],]);});+it('Handles extracting multiple languages', () => {- const textArray = new ArrayValueObject({+ const text = new ArrayValueObject({calculateValueList: transformToValueObject([['销售额'],['uから'],@@ -220,16 +225,18 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const result = leftbFunction.calculate(textArray, NumberValueObject.create(3));- expect(transformToValue(result.getArrayValue())).toStrictEqual([- ['销'],+ const numBytes = NumberValueObject.create(3);+ const result = leftbFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual([+ ['销售'],['uか'],['이u'],- ['이'],+ ['이트'],]);});+it('Text is array, numBytes is array', () => {- const textArray = new ArrayValueObject({+ const text = new ArrayValueObject({calculateValueList: transformToValueObject([[1, ' ', 1.23, true, false, null, 0, '100', '2.34', 'test', -3, ErrorType.NAME],]),@@ -240,7 +247,7 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const numCharsArray = new ArrayValueObject({+ const numBytes = new ArrayValueObject({calculateValueList: transformToValueObject([[1],[' '],@@ -262,8 +269,21 @@ describe('Test LEFTB function', () => {row: 0,column: 0,});- const result = leftbFunction.calculate(textArray, numCharsArray);- expect(transformToValue(result.getArrayValue())).toStrictEqual([['1', ' ', '1', 'T', 'F', '', '0', '1', '2', 't', '-', ErrorType.NAME], [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME], ['1', ' ', '1', 'T', 'F', '', '0', '1', '2', 't', '-', ErrorType.NAME], ['1', ' ', '1', 'T', 'F', '', '0', '1', '2', 't', '-', ErrorType.NAME], ['', '', '', '', '', '', '', '', '', '', '', ErrorType.NAME], ['', '', '', '', '', '', '', '', '', '', '', ErrorType.NAME], ['', '', '', '', '', '', '', '', '', '', '', ErrorType.NAME], ['1', ' ', '1.23', 'TRUE', 'FALSE', '', '0', '100', '2.34', 'test', '-3', ErrorType.NAME], ['1', ' ', '1.', 'TR', 'FA', '', '0', '10', '2.', 'te', '-3', ErrorType.NAME], [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME], [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME], [ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME]]);+ const result = leftbFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual([+ ['1', ' ', '1', 'T', 'F', '', '0', '1', '2', 't', '-', ErrorType.NAME],+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ ['1', ' ', '1', 'T', 'F', '', '0', '1', '2', 't', '-', ErrorType.NAME],+ ['1', ' ', '1', 'T', 'F', '', '0', '1', '2', 't', '-', ErrorType.NAME],+ ['', '', '', '', '', '', '', '', '', '', '', ErrorType.NAME],+ ['', '', '', '', '', '', '', '', '', '', '', ErrorType.NAME],+ ['', '', '', '', '', '', '', '', '', '', '', ErrorType.NAME],+ ['1', ' ', '1.23', 'TRUE', 'FALSE', '', '0', '100', '2.34', 'test', '-3', ErrorType.NAME],+ ['1', ' ', '1.', 'TR', 'FA', '', '0', '10', '2.', 'te', '-3', ErrorType.NAME],+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ [ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME, ErrorType.NAME],+ ]);});});});diff --git a/packages/engine-formula/src/functions/text/leftb/index.ts b/packages/engine-formula/src/functions/text/leftb/index.tsindex 20a3f903bd..76eb7950a0 100644--- a/packages/engine-formula/src/functions/text/leftb/index.ts+++ b/packages/engine-formula/src/functions/text/leftb/index.ts@@ -14,99 +14,92 @@* limitations under the License.*/+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';import { ErrorType } from '../../../basics/error-type';import { expandArrayValueObject } from '../../../engine/utils/array-object';-import { charLenByte } from '../../../engine/utils/char-kit';+import { getCharLenByteInText } from '../../../engine/utils/char-kit';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';-import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { NullValueObject, NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';export class Leftb extends BaseFunction {override minParams = 1;override maxParams = 2;- override calculate(text: BaseValueObject, numBytes?: BaseValueObject) {- if (text.isError()) {- return text;- }-- if (numBytes?.isError()) {- return numBytes;- }-- const _numBytes = numBytes || NumberValueObject.create(1);+ override calculate(text: BaseValueObject, numBytes?: BaseValueObject): BaseValueObject {+ const _numBytes = numBytes ?? NumberValueObject.create(1);const maxRowLength = Math.max(text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,- _numBytes && _numBytes.isArray() ? (_numBytes as ArrayValueObject).getRowCount() : 1+ _numBytes.isArray() ? (_numBytes as ArrayValueObject).getRowCount() : 1);const maxColumnLength = Math.max(text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,- _numBytes && _numBytes.isArray() ? (_numBytes as ArrayValueObject).getColumnCount() : 1+ _numBytes.isArray() ? (_numBytes as ArrayValueObject).getColumnCount() : 1);- const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text);- const numBytesArray = expandArrayValueObject(maxRowLength, maxColumnLength, _numBytes);+ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, NullValueObject.create());+ const numBytesArray = expandArrayValueObject(maxRowLength, maxColumnLength, _numBytes, NullValueObject.create());- return textArray.map((textValue, rowIndex, columnIndex) => {- return this._handleSingleText(textValue, rowIndex, columnIndex, numBytesArray);- });- }+ const resultArray = textArray.mapValue((textObject, rowIndex, columnIndex) => {+ const numBytesObject = numBytesArray.get(rowIndex, columnIndex) as BaseValueObject;- private _handleSingleText(textValue: BaseValueObject, rowIndex: number, columnIndex: number, numBytesArray: ArrayValueObject) {- let numBytes = numBytesArray.get(rowIndex, columnIndex) || NumberValueObject.create(1);+ if (textObject.isError()) {+ return textObject;+ }- if (numBytes.isError()) {- return numBytes;- }+ if (numBytesObject.isError()) {+ return numBytesObject;+ }- let textValueString = textValue.getValue();+ return this._handleSingleObject(textObject, numBytesObject);+ });- if (textValue.isNull()) {- textValueString = '';+ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;}- if (textValue.isBoolean()) {- textValueString = textValueString ? 'TRUE' : 'FALSE';- }+ return resultArray;+ }- textValueString = `${textValueString}`;+ private _handleSingleObject(text: BaseValueObject, numBytes: BaseValueObject): BaseValueObject {+ let textValue = `${text.getValue()}`;- if (numBytes.isString() || numBytes.isBoolean() || numBytes.isNull()) {- numBytes = numBytes.convertToNumberObjectValue();+ if (text.isBoolean()) {+ textValue = textValue.toLocaleUpperCase();}- if (numBytes.isError()) {- return numBytes;+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(numBytes);++ if (isError) {+ return errorObject as BaseValueObject;}- const numBytesValueNumber = Math.floor(+numBytes.getValue());+ const [numBytesObject] = variants as BaseValueObject[];- if (numBytesValueNumber < 0) {+ const numBytesValue = Math.floor(+numBytesObject.getValue());++ if (numBytesValue < 0) {return ErrorValueObject.create(ErrorType.VALUE);}- return StringValueObject.create(this._sliceByBytes(textValueString, numBytesValueNumber));- }+ if (text.isNull() || numBytesValue === 0) {+ return StringValueObject.create('');+ }- private _sliceByBytes(text: string, numBytes: number) {- let byteCount = 0;- let sliceIndex = 0;+ let index = 0;+ let lenByte = 0;+ let result = '';- // Iterate over each Unicode character (correctly handling multi-byte characters and emoji)- for (let i = 0; i < text.length; i++) {- const char = text[i];- const charByteLength = charLenByte(char);- if (byteCount + charByteLength > numBytes) {- break;- }- byteCount += charByteLength;- sliceIndex++;+ while (lenByte < numBytesValue && index < textValue.length) {+ lenByte += getCharLenByteInText(textValue, index);+ result += textValue.charAt(index);+ index++;}- return [...text].slice(0, sliceIndex).join('');+ return StringValueObject.create(result);}}diff --git a/packages/engine-formula/src/functions/text/lenb/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/lenb/__test__/index.spec.tsindex 6e6b0b756a..36ec95a831 100644--- a/packages/engine-formula/src/functions/text/lenb/__test__/index.spec.ts+++ b/packages/engine-formula/src/functions/text/lenb/__test__/index.spec.ts@@ -16,11 +16,12 @@import { describe, expect, it } from 'vitest';+import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';import { FUNCTION_NAMES_TEXT } from '../../function-names';import { Lenb } from '../index';-import { StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';-import { ErrorType } from '../../../../basics/error-type';describe('Test lenb function', () => {const testFunction = new Lenb(FUNCTION_NAMES_TEXT.LENB);@@ -29,7 +30,7 @@ describe('Test lenb function', () => {it('Text is single cell', () => {const text = StringValueObject.create('Univer');const result = testFunction.calculate(text);- expect(result.getValue()).toStrictEqual(6);+ expect(getObjectValue(result)).toStrictEqual(6);});it('Text1 is array', () => {@@ -46,7 +47,7 @@ describe('Test lenb function', () => {column: 0,});const result = testFunction.calculate(text);- expect(transformToValue(result.getArrayValue())).toStrictEqual([+ expect(getObjectValue(result)).toStrictEqual([[1, 1, 4, 4, 5, 0, 26],[1, 3, 4, 4, 2, '#VALUE!', 0],]);@@ -68,6 +69,7 @@ describe('Test lenb function', () => {['𓀀'],['𐌰'],['♚'],+ [''],]),rowCount: 13,columnCount: 1,@@ -77,7 +79,31 @@ describe('Test lenb function', () => {column: 0,});const result = testFunction.calculate(text);- expect(transformToValue(result.getArrayValue())).toStrictEqual([[1], [1], [1], [1], [1], [2], [2], [2], [2], [8], [2], [2], [1]]);+ expect(getObjectValue(result)).toStrictEqual([+ [1],+ [1],+ [1],+ [1],+ [2],+ [2],+ [2],+ [4],+ [4],+ [16],+ [4],+ [4],+ [2],+ ]);+ });++ it('More test', () => {+ const text = StringValueObject.create(',。、;:{}');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(10);++ const text2 = StringValueObject.create('Hello中文o😊Wo😊rld');+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual(23);});});});diff --git a/packages/engine-formula/src/functions/text/lenb/index.ts b/packages/engine-formula/src/functions/text/lenb/index.tsindex 042a350a8c..0bcba656ba 100644--- a/packages/engine-formula/src/functions/text/lenb/index.ts+++ b/packages/engine-formula/src/functions/text/lenb/index.ts@@ -49,7 +49,7 @@ export class Lenb extends BaseFunction {}if (text.isString() || text.isBoolean() || text.isNumber()) {- const textValue = text.getValue().toString();+ const textValue = `${text.getValue()}`;const textByteLen = charLenByte(textValue);return NumberValueObject.create(textByteLen);diff --git a/packages/engine-formula/src/functions/text/numbervalue/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/numbervalue/__test__/index.spec.tsnew file mode 100644index 0000000000..55171597f3--- /dev/null+++ b/packages/engine-formula/src/functions/text/numbervalue/__test__/index.spec.ts@@ -0,0 +1,146 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Numbervalue } from '../index';++describe('Test numbervalue function', () => {+ const testFunction = new Numbervalue(FUNCTION_NAMES_TEXT.NUMBERVALUE);++ describe('Numbervalue', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('2.500,27');+ const decimalSeparator = StringValueObject.create(',');+ const groupSeparator = StringValueObject.create('.');+ const result = testFunction.calculate(text, decimalSeparator, groupSeparator);+ expect(getObjectValue(result)).toStrictEqual(2500.27);+ });++ it('Value is has percentage', () => {+ const text = StringValueObject.create('3.5%');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(0.035);+ });++ it('DecimalSeparator value test', () => {+ const text = StringValueObject.create('2.500,27');+ const decimalSeparator = ErrorValueObject.create(ErrorType.NAME);+ const groupSeparator = StringValueObject.create('.');+ const result = testFunction.calculate(text, decimalSeparator, groupSeparator);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const decimalSeparator2 = NullValueObject.create();+ const result2 = testFunction.calculate(text, decimalSeparator2, groupSeparator);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const decimalSeparator3 = StringValueObject.create('.');+ const result3 = testFunction.calculate(text, decimalSeparator3, groupSeparator);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);++ const decimalSeparator4 = BooleanValueObject.create(true);+ const result4 = testFunction.calculate(text, decimalSeparator4, groupSeparator);+ expect(getObjectValue(result4)).toStrictEqual(250027);+ });++ it('GroupSeparator value test', () => {+ const text = StringValueObject.create('2.500,27');+ const decimalSeparator = StringValueObject.create(',');+ const groupSeparator = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(text, decimalSeparator, groupSeparator);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);++ const groupSeparator2 = NullValueObject.create();+ const result2 = testFunction.calculate(text, decimalSeparator, groupSeparator2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const groupSeparator3 = StringValueObject.create(',');+ const result3 = testFunction.calculate(text, decimalSeparator, groupSeparator3);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);++ const groupSeparator4 = BooleanValueObject.create(true);+ const result4 = testFunction.calculate(text, decimalSeparator, groupSeparator4);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const text = BooleanValueObject.create(true);+ const decimalSeparator = StringValueObject.create(',');+ const groupSeparator = StringValueObject.create('.');+ const result = testFunction.calculate(text, decimalSeparator, groupSeparator);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is error', () => {+ const text = ErrorValueObject.create(ErrorType.NAME);+ const decimalSeparator = StringValueObject.create(',');+ const groupSeparator = StringValueObject.create('.');+ const result = testFunction.calculate(text, decimalSeparator, groupSeparator);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual([+ [1, 0, 1.23, ErrorType.VALUE, ErrorType.VALUE, 0],+ [0, 100, 2.34, ErrorType.VALUE, -3, ErrorType.NAME],+ ]);+ });++ it('More test', () => {+ const text = StringValueObject.create('2.50,0,27');+ const decimalSeparator = StringValueObject.create(',');+ const groupSeparator = StringValueObject.create('.');+ const result = testFunction.calculate(text, decimalSeparator, groupSeparator);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);++ const text2 = StringValueObject.create('2.50,027%');+ const decimalSeparator2 = StringValueObject.create('a');+ const result2 = testFunction.calculate(text2, decimalSeparator2, groupSeparator);+ expect(getObjectValue(result2)).toStrictEqual(2500.27);++ const text3 = StringValueObject.create('2a.50027%');+ const result3 = testFunction.calculate(text3, decimalSeparator, groupSeparator);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);++ const text4 = StringValueObject.create('2a.50,027%');+ const result4 = testFunction.calculate(text4, decimalSeparator, groupSeparator);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.VALUE);++ const text5 = StringValueObject.create('20%%');+ const result5 = testFunction.calculate(text5, decimalSeparator, groupSeparator);+ expect(getObjectValue(result5)).toStrictEqual(0.002);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/numbervalue/index.ts b/packages/engine-formula/src/functions/text/numbervalue/index.tsnew file mode 100644index 0000000000..33a91687f9--- /dev/null+++ b/packages/engine-formula/src/functions/text/numbervalue/index.ts@@ -0,0 +1,185 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Numbervalue extends BaseFunction {+ override minParams = 1;++ override maxParams = 3;++ override calculate(text: BaseValueObject, decimalSeparator?: BaseValueObject, groupSeparator?: BaseValueObject): BaseValueObject {+ const _decimalSeparator = decimalSeparator ?? StringValueObject.create('.');++ const maxRowLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,+ _decimalSeparator.isArray() ? (_decimalSeparator as ArrayValueObject).getRowCount() : 1,+ groupSeparator?.isArray() ? (groupSeparator as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,+ _decimalSeparator.isArray() ? (_decimalSeparator as ArrayValueObject).getColumnCount() : 1,+ groupSeparator?.isArray() ? (groupSeparator as ArrayValueObject).getColumnCount() : 1+ );++ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create(ErrorType.NA));+ const decimalSeparatorArray = expandArrayValueObject(maxRowLength, maxColumnLength, _decimalSeparator, ErrorValueObject.create(ErrorType.NA));+ const groupSeparatorArray = groupSeparator ? expandArrayValueObject(maxRowLength, maxColumnLength, groupSeparator, ErrorValueObject.create(ErrorType.NA)) : undefined;++ const resultArray = textArray.mapValue((textObject, rowIndex, columnIndex) => {+ const decimalSeparatorObject = decimalSeparatorArray.get(rowIndex, columnIndex) as BaseValueObject;+ const groupSeparatorObject = groupSeparator ? (groupSeparatorArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject : undefined;++ if (textObject.isError()) {+ return textObject;+ }++ if (decimalSeparatorObject.isError()) {+ return decimalSeparatorObject;+ }++ if (groupSeparatorObject?.isError()) {+ return groupSeparatorObject;+ }++ if (decimalSeparatorObject.isNull() || groupSeparatorObject?.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (textObject.isNull()) {+ return NumberValueObject.create(0);+ }++ return this._handleSingleObject(textObject, decimalSeparatorObject, groupSeparatorObject);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ // eslint-disable-next-line+ private _handleSingleObject(text: BaseValueObject, decimalSeparator: BaseValueObject, groupSeparator: BaseValueObject | undefined): BaseValueObject {+ let textValue = `${text.getValue()}`;+ textValue = textValue.replace(/\s+/g, '');++ let decimalSeparatorValue = `${decimalSeparator.getValue()}`;++ if (decimalSeparator.isBoolean()) {+ decimalSeparatorValue = decimalSeparatorValue.toLocaleUpperCase();+ }++ decimalSeparatorValue = decimalSeparatorValue.charAt(0);++ let groupSeparatorValue: string | undefined;++ if (groupSeparator) {+ groupSeparatorValue = `${groupSeparator.getValue()}`;++ if (groupSeparator.isBoolean()) {+ groupSeparatorValue = groupSeparatorValue.toLocaleUpperCase();+ }++ groupSeparatorValue = groupSeparatorValue.charAt(0);++ if (decimalSeparatorValue === groupSeparatorValue) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }+ }++ if (textValue.trim() === '') {+ return NumberValueObject.create(0);+ }++ if (!textValue.match(/^\s*[+-]?\s*(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?[ \t]*/)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const splitText = textValue.split(decimalSeparatorValue);++ if (splitText.length > 2) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let integerPart = splitText[0].replace(/,/g, '');++ if (groupSeparator) {+ integerPart = integerPart.split(groupSeparatorValue as string).join('');+ }++ let result = 0;++ if (splitText.length === 1) {+ if (decimalSeparatorValue === ',') {+ integerPart = integerPart.replace(/\./g, '');+ }++ let percentageCount = 0;++ while (integerPart.endsWith('%')) {+ integerPart = integerPart.slice(0, -1);+ percentageCount++;+ }++ if (percentageCount > 0) {+ result = +integerPart / (100 ** percentageCount);+ } else {+ result = +integerPart;+ }+ } else {+ if (!isRealNum(integerPart)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let decimalPart = splitText[1];++ let percentageCount = 0;++ while (decimalPart.endsWith('%')) {+ decimalPart = decimalPart.slice(0, -1);+ percentageCount++;+ }++ const resultText = `${integerPart}.${decimalPart}`;++ if (!isRealNum(resultText)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (percentageCount > 0) {+ result = +resultText / (100 ** percentageCount);+ } else {+ result = +resultText;+ }+ }++ if (Number.isNaN(result)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/proper/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/proper/__test__/index.spec.tsnew file mode 100644index 0000000000..6c6f5db8fa--- /dev/null+++ b/packages/engine-formula/src/functions/text/proper/__test__/index.spec.ts@@ -0,0 +1,70 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Proper } from '../index';++describe('Test proper function', () => {+ const testFunction = new Proper(FUNCTION_NAMES_TEXT.PROPER);++ describe('Proper', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('univer');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual('Univer');+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 'this is a TITLE', true, false, null],+ [0, '100', '2.34', '2-way street', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ [1, ' ', 'This Is A Title', true, false, 0],+ [0, 100, 2.34, '2-Way Street', -3, ErrorType.NAME],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['76BudGet'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual('76Budget');+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/proper/index.ts b/packages/engine-formula/src/functions/text/proper/index.tsnew file mode 100644index 0000000000..56cfd3300f--- /dev/null+++ b/packages/engine-formula/src/functions/text/proper/index.ts@@ -0,0 +1,52 @@+/**+ * 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 { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';++export class Proper extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError() || text.isNull() || text.isBoolean() || text.isNumber()) {+ return text;+ }++ const textValue = text.getValue().toLocaleString();++ const result = textValue.toLocaleLowerCase().replace(/(^|\b|\W|\d|_)[a-z]/g, (txt) => txt.toLocaleUpperCase());++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/rept/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/rept/__test__/index.spec.tsindex ec093fc95c..386a3414bc 100644--- a/packages/engine-formula/src/functions/text/rept/__test__/index.spec.ts+++ b/packages/engine-formula/src/functions/text/rept/__test__/index.spec.ts@@ -16,11 +16,13 @@import { describe, expect, it } from 'vitest';+import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';import { FUNCTION_NAMES_TEXT } from '../../function-names';import { Rept } from '../index';-import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';-import { ErrorType } from '../../../../basics/error-type';describe('Test rept function', () => {const testFunction = new Rept(FUNCTION_NAMES_TEXT.REPT);@@ -30,41 +32,53 @@ describe('Test rept function', () => {const text = StringValueObject.create('*-');const numberTimes = NumberValueObject.create(3);const result = testFunction.calculate(text, numberTimes);- expect(result.getValue()).toBe('*-*-*-');+ expect(getObjectValue(result)).toBe('*-*-*-');});it('Value is number', () => {const text = NumberValueObject.create(1);const numberTimes = NumberValueObject.create(3);const result = testFunction.calculate(text, numberTimes);- expect(result.getValue()).toBe('111');+ expect(getObjectValue(result)).toBe('111');});it('Value is boolean', () => {const text = BooleanValueObject.create(true);const numberTimes = BooleanValueObject.create(true);const result = testFunction.calculate(text, numberTimes);- expect(result.getValue()).toBe('TRUE');+ expect(getObjectValue(result)).toBe('TRUE');const numberTimes2 = BooleanValueObject.create(false);const result2 = testFunction.calculate(text, numberTimes2);- expect(result2.getValue()).toBe('');+ expect(getObjectValue(result2)).toBe('');});it('Value is blank cell', () => {const text = StringValueObject.create('abc');const numberTimes = NullValueObject.create();const result = testFunction.calculate(text, numberTimes);- expect(result.getValue()).toBe('');+ expect(getObjectValue(result)).toBe('');+ });++ it('Value is error', () => {+ const text = StringValueObject.create('abc');+ const numberTimes = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(text, numberTimes);+ expect(getObjectValue(result)).toBe(ErrorType.NAME);++ const text2 = ErrorValueObject.create(ErrorType.NAME);+ const numberTimes2 = NumberValueObject.create(3);+ const result2 = testFunction.calculate(text2, numberTimes2);+ expect(getObjectValue(result2)).toBe(ErrorType.NAME);});it('Value is array', () => {const text = new ArrayValueObject({calculateValueList: transformToValueObject([- [1, true, false, null, 'test'],+ [1, true, false, null, 'test', ErrorType.NAME],]),rowCount: 1,- columnCount: 5,+ columnCount: 6,unitId: '',sheetId: '',row: 0,@@ -87,13 +101,13 @@ describe('Test rept function', () => {column: 0,});const result = testFunction.calculate(text, numberTimes);- expect(transformToValue(result.getArrayValue())).toStrictEqual([- ['11', 'TRUETRUE', 'FALSEFALSE', '', 'testtest'],- ['1', 'TRUE', 'FALSE', '', 'test'],- ['', '', '', '', ''],- ['', '', '', '', ''],- [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE],- [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE],+ expect(getObjectValue(result)).toStrictEqual([+ ['11', 'TRUETRUE', 'FALSEFALSE', '', 'testtest', ErrorType.NAME],+ ['1', 'TRUE', 'FALSE', '', 'test', ErrorType.NAME],+ ['', '', '', '', '', ErrorType.NAME],+ ['', '', '', '', '', ErrorType.NAME],+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],]);});});diff --git a/packages/engine-formula/src/functions/text/rept/index.ts b/packages/engine-formula/src/functions/text/rept/index.tsindex cabe703537..d94e97d56c 100644--- a/packages/engine-formula/src/functions/text/rept/index.ts+++ b/packages/engine-formula/src/functions/text/rept/index.ts@@ -14,9 +14,9 @@* limitations under the License.*/+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';import { ErrorType } from '../../../basics/error-type';import { expandArrayValueObject } from '../../../engine/utils/array-object';-import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';import { StringValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';diff --git a/packages/engine-formula/src/functions/text/right/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/right/__test__/index.spec.tsnew file mode 100644index 0000000000..026c70bc77--- /dev/null+++ b/packages/engine-formula/src/functions/text/right/__test__/index.spec.ts@@ -0,0 +1,95 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Right } from '../index';++describe('Test right function', () => {+ const testFunction = new Right(FUNCTION_NAMES_TEXT.RIGHT);++ describe('Right', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('Univer');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual('r');+ });++ it('NumChars value test', () => {+ const text = StringValueObject.create('Univer');+ const numChars = NumberValueObject.create(-2);+ const result = testFunction.calculate(text, numChars);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);++ const numChars2 = BooleanValueObject.create(false);+ const result2 = testFunction.calculate(text, numChars2);+ expect(getObjectValue(result2)).toStrictEqual('');++ const numChars3 = NumberValueObject.create(6);+ const result3 = testFunction.calculate(text, numChars3);+ expect(getObjectValue(result3)).toStrictEqual('Univer');++ const numChars4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(text, numChars4);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);++ const numChars5 = StringValueObject.create('test');+ const result5 = testFunction.calculate(text, numChars5);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文测试', true, false, null],+ [0, '100', '2.34', '2-way street', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numChars = NumberValueObject.create(2);+ const result = testFunction.calculate(text, numChars);+ expect(getObjectValue(result)).toStrictEqual([+ ['1', ' ', '测试', 'UE', 'SE', ''],+ ['0', '00', '34', 'et', '-3', ErrorType.NAME],+ ]);+ });++ it('More test', () => {+ const text = StringValueObject.create(',。、;:{}');+ const numChars = NumberValueObject.create(4);+ const result = testFunction.calculate(text, numChars);+ expect(getObjectValue(result)).toStrictEqual(';:{}');++ const text2 = StringValueObject.create('Hello中文o😊Wo😊rld');+ const numChars2 = ArrayValueObject.create('{3,5,7,9,15}');+ const result2 = testFunction.calculate(text2, numChars2);+ expect(getObjectValue(result2)).toStrictEqual([+ ['rld', '😊rld', 'Wo😊rld', '😊Wo😊rld', 'llo中文o😊Wo😊rld'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/right/index.ts b/packages/engine-formula/src/functions/text/right/index.tsnew file mode 100644index 0000000000..2571505228--- /dev/null+++ b/packages/engine-formula/src/functions/text/right/index.ts@@ -0,0 +1,100 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NullValueObject, NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Right extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(text: BaseValueObject, numChars?: BaseValueObject): BaseValueObject {+ const _numChars = numChars ?? NumberValueObject.create(1);++ const maxRowLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,+ _numChars.isArray() ? (_numChars as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,+ _numChars.isArray() ? (_numChars as ArrayValueObject).getColumnCount() : 1+ );++ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, NullValueObject.create());+ const numCharsArray = expandArrayValueObject(maxRowLength, maxColumnLength, _numChars, NullValueObject.create());++ const resultArray = textArray.mapValue((textObject, rowIndex, columnIndex) => {+ const numCharsObject = numCharsArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (textObject.isError()) {+ return textObject;+ }++ if (numCharsObject.isError()) {+ return numCharsObject;+ }++ return this._handleSingleObject(textObject, numCharsObject);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(text: BaseValueObject, numChars: BaseValueObject): BaseValueObject {+ let textValue = `${text.getValue()}`;++ if (text.isBoolean()) {+ textValue = textValue.toLocaleUpperCase();+ }++ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(numChars);++ if (isError) {+ return errorObject as BaseValueObject;+ }++ const [numCharsObject] = variants as BaseValueObject[];++ const numCharsValue = Math.floor(+numCharsObject.getValue());++ if (numCharsValue < 0) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (text.isNull() || numCharsValue === 0) {+ return StringValueObject.create('');+ }++ if (numCharsValue >= textValue.length) {+ return StringValueObject.create(textValue);+ }++ const result = textValue.substring(textValue.length - numCharsValue);++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/rightb/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/rightb/__test__/index.spec.tsnew file mode 100644index 0000000000..951ac3758a--- /dev/null+++ b/packages/engine-formula/src/functions/text/rightb/__test__/index.spec.ts@@ -0,0 +1,102 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Rightb } from '../index';++describe('Test rightb function', () => {+ const testFunction = new Rightb(FUNCTION_NAMES_TEXT.RIGHTB);++ describe('Rightb', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('Univer');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual('r');+ });++ it('NumBytes value test', () => {+ const text = StringValueObject.create('Univer');+ const numBytes = NumberValueObject.create(-2);+ const result = testFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);++ const numBytes2 = BooleanValueObject.create(false);+ const result2 = testFunction.calculate(text, numBytes2);+ expect(getObjectValue(result2)).toStrictEqual('');++ const numBytes3 = NumberValueObject.create(6);+ const result3 = testFunction.calculate(text, numBytes3);+ expect(getObjectValue(result3)).toStrictEqual('Univer');++ const numBytes4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(text, numBytes4);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);++ const numBytes5 = StringValueObject.create('test');+ const result5 = testFunction.calculate(text, numBytes5);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文测试', true, false, null],+ [0, '100', '2.34', '2-way street', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numBytes = NumberValueObject.create(2);+ const result = testFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual([+ ['1', ' ', '试', 'UE', 'SE', ''],+ ['0', '00', '34', 'et', '-3', ErrorType.NAME],+ ]);++ const numBytes2 = NumberValueObject.create(3);+ const result2 = testFunction.calculate(text, numBytes2);+ expect(getObjectValue(result2)).toStrictEqual([+ ['1', ' ', '测试', 'RUE', 'LSE', ''],+ ['0', '100', '.34', 'eet', '-3', ErrorType.NAME],+ ]);+ });++ it('More test', () => {+ const text = StringValueObject.create(',。、;:{}');+ const numBytes = NumberValueObject.create(4);+ const result = testFunction.calculate(text, numBytes);+ expect(getObjectValue(result)).toStrictEqual(';:{}');++ const text2 = StringValueObject.create('Hello中文o😊Wo😊rld');+ const numBytes2 = ArrayValueObject.create('{3,6,7,8,15}');+ const result2 = testFunction.calculate(text2, numBytes2);+ expect(getObjectValue(result2)).toStrictEqual([+ ['rld', '😊rld', '😊rld', 'o😊rld', '文o😊Wo😊rld'],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/rightb/index.ts b/packages/engine-formula/src/functions/text/rightb/index.tsnew file mode 100644index 0000000000..cf99ab0f0a--- /dev/null+++ b/packages/engine-formula/src/functions/text/rightb/index.ts@@ -0,0 +1,105 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { getCharLenByteInText } from '../../../engine/utils/char-kit';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NullValueObject, NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Rightb extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(text: BaseValueObject, numBytes?: BaseValueObject): BaseValueObject {+ const _numBytes = numBytes ?? NumberValueObject.create(1);++ const maxRowLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,+ _numBytes.isArray() ? (_numBytes as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,+ _numBytes.isArray() ? (_numBytes as ArrayValueObject).getColumnCount() : 1+ );++ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, NullValueObject.create());+ const numBytesArray = expandArrayValueObject(maxRowLength, maxColumnLength, _numBytes, NullValueObject.create());++ const resultArray = textArray.mapValue((textObject, rowIndex, columnIndex) => {+ const numBytesObject = numBytesArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (textObject.isError()) {+ return textObject;+ }++ if (numBytesObject.isError()) {+ return numBytesObject;+ }++ return this._handleSingleObject(textObject, numBytesObject);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(text: BaseValueObject, numBytes: BaseValueObject): BaseValueObject {+ let textValue = `${text.getValue()}`;++ if (text.isBoolean()) {+ textValue = textValue.toLocaleUpperCase();+ }++ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(numBytes);++ if (isError) {+ return errorObject as BaseValueObject;+ }++ const [numBytesObject] = variants as BaseValueObject[];++ const numBytesValue = Math.floor(+numBytesObject.getValue());++ if (numBytesValue < 0) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (text.isNull() || numBytesValue === 0) {+ return StringValueObject.create('');+ }++ let index = textValue.length - 1;+ let lenByte = 0;+ let result = '';++ while (lenByte < numBytesValue && index >= 0) {+ lenByte += getCharLenByteInText(textValue, index, 'rtl');+ result = textValue.charAt(index) + result;+ index--;+ }++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/substitute/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/substitute/__test__/index.spec.tsnew file mode 100644index 0000000000..f7c2f6d029--- /dev/null+++ b/packages/engine-formula/src/functions/text/substitute/__test__/index.spec.ts@@ -0,0 +1,126 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Substitute } from '../index';++describe('Test substitute function', () => {+ const testFunction = new Substitute(FUNCTION_NAMES_TEXT.SUBSTITUTE);++ describe('Substitute', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('Hello Univer');+ const oldText = StringValueObject.create('Hello');+ const newText = StringValueObject.create('Hi');+ const result = testFunction.calculate(text, oldText, newText);+ expect(getObjectValue(result)).toStrictEqual('Hi Univer');+ });++ it('OldText value test', () => {+ const text = StringValueObject.create('Hello Univer');+ const oldText = NullValueObject.create();+ const newText = StringValueObject.create('Hi');+ const result = testFunction.calculate(text, oldText, newText);+ expect(getObjectValue(result)).toStrictEqual('Hello Univer');++ const oldText2 = BooleanValueObject.create(true);+ const result2 = testFunction.calculate(text, oldText2, newText);+ expect(getObjectValue(result2)).toStrictEqual('Hello Univer');++ const oldText3 = ErrorValueObject.create(ErrorType.NAME);+ const result3 = testFunction.calculate(text, oldText3, newText);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.NAME);+ });++ it('NewText value test', () => {+ const text = StringValueObject.create('Hello Univer');+ const oldText = StringValueObject.create('Hello');+ const newText = NullValueObject.create();+ const result = testFunction.calculate(text, oldText, newText);+ expect(getObjectValue(result)).toStrictEqual(' Univer');++ const newText2 = BooleanValueObject.create(true);+ const result2 = testFunction.calculate(text, oldText, newText2);+ expect(getObjectValue(result2)).toStrictEqual('TRUE Univer');++ const newText3 = ErrorValueObject.create(ErrorType.NAME);+ const result3 = testFunction.calculate(text, oldText, newText3);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.NAME);+ });++ it('InstanceNum value test', () => {+ const text = StringValueObject.create('Hello Univer');+ const oldText = StringValueObject.create('Hello');+ const newText = StringValueObject.create('Hi');+ const instanceNum = NullValueObject.create();+ const result = testFunction.calculate(text, oldText, newText, instanceNum);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);++ const instanceNum2 = BooleanValueObject.create(true);+ const result2 = testFunction.calculate(text, oldText, newText, instanceNum2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);++ const instanceNum3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(text, oldText, newText, instanceNum3);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);++ const instanceNum4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(text, oldText, newText, instanceNum4);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);++ const instanceNum5 = NumberValueObject.create(2.5);+ const result5 = testFunction.calculate(text, oldText, newText, instanceNum5);+ expect(getObjectValue(result5)).toStrictEqual('Hello Univer');++ const instanceNum6 = NumberValueObject.create(-1);+ const result6 = testFunction.calculate(text, oldText, newText, instanceNum6);+ expect(getObjectValue(result6)).toStrictEqual(ErrorType.VALUE);++ const instanceNum7 = NumberValueObject.create(1);+ const result7 = testFunction.calculate(text, oldText, newText, instanceNum7);+ expect(getObjectValue(result7)).toStrictEqual('Hi Univer');+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文测试', true, false, null],+ [0, '100', '2.34', ' 1 11 111', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const oldText = StringValueObject.create(' ');+ const newText = BooleanValueObject.create(true);+ const result = testFunction.calculate(text, oldText, newText);+ expect(getObjectValue(result)).toStrictEqual([+ ['1', 'TRUE', '中文测试', 'TRUE', 'FALSE', ''],+ ['0', '100', '2.34', 'TRUE1TRUE11TRUE111', '-3', ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/substitute/index.ts b/packages/engine-formula/src/functions/text/substitute/index.tsnew file mode 100644index 0000000000..749b173311--- /dev/null+++ b/packages/engine-formula/src/functions/text/substitute/index.ts@@ -0,0 +1,153 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Substitute extends BaseFunction {+ override minParams = 3;++ override maxParams = 4;++ override calculate(text: BaseValueObject, oldText: BaseValueObject, newText: BaseValueObject, instanceNum?: BaseValueObject): BaseValueObject {+ const maxRowLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,+ oldText.isArray() ? (oldText as ArrayValueObject).getRowCount() : 1,+ newText.isArray() ? (newText as ArrayValueObject).getRowCount() : 1,+ instanceNum?.isArray() ? (instanceNum as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,+ oldText.isArray() ? (oldText as ArrayValueObject).getColumnCount() : 1,+ newText.isArray() ? (newText as ArrayValueObject).getColumnCount() : 1,+ instanceNum?.isArray() ? (instanceNum as ArrayValueObject).getColumnCount() : 1+ );++ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create(ErrorType.NA));+ const oldTextArray = expandArrayValueObject(maxRowLength, maxColumnLength, oldText, ErrorValueObject.create(ErrorType.NA));+ const newTextArray = expandArrayValueObject(maxRowLength, maxColumnLength, newText, ErrorValueObject.create(ErrorType.NA));+ const instanceNumArray = instanceNum ? expandArrayValueObject(maxRowLength, maxColumnLength, instanceNum, ErrorValueObject.create(ErrorType.NA)) : undefined;++ const resultArray = textArray.mapValue((textObject, rowIndex, columnIndex) => {+ const oldTextObject = oldTextArray.get(rowIndex, columnIndex) as BaseValueObject;+ const newTextObject = newTextArray.get(rowIndex, columnIndex) as BaseValueObject;+ let instanceNumObject = instanceNum ? (instanceNumArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject : undefined;++ if (textObject.isError()) {+ return textObject;+ }++ if (oldTextObject.isError()) {+ return oldTextObject;+ }++ if (newTextObject.isError()) {+ return newTextObject;+ }++ if (instanceNumObject?.isError()) {+ return instanceNumObject;+ }++ if (instanceNumObject?.isNull() || instanceNumObject?.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (instanceNumObject?.isString()) {+ instanceNumObject = instanceNumObject.convertToNumberObjectValue();+ }++ if (instanceNumObject?.isError()) {+ return instanceNumObject;+ }++ return this._handleSingleObject(textObject, oldTextObject, newTextObject, instanceNumObject as NumberValueObject | undefined);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(text: BaseValueObject, oldText: BaseValueObject, newText: BaseValueObject, instanceNum: NumberValueObject | undefined): BaseValueObject {+ const textValue = this._getObjectString(text);+ const oldTextValue = this._getObjectString(oldText);+ const newTextValue = this._getObjectString(newText);+ const instanceNumValue = instanceNum ? Math.floor(+instanceNum.getValue()) : undefined;++ if (instanceNum && (instanceNumValue as number) <= 0) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (oldTextValue === '') {+ return StringValueObject.create(textValue);+ }++ let result = '';+ let num = 0;++ for (let i = 0; i < textValue.length; i++) {+ const str = textValue.substr(i, oldTextValue.length);++ if (str === oldTextValue || (str.length === oldTextValue.length && str.trim() === oldTextValue.trim())) {+ num++;++ if (num === instanceNumValue) {+ result = textValue.substr(0, i) + newTextValue + textValue.substr(i + oldTextValue.length);+ break;+ }++ if (instanceNumValue === undefined) {+ result += newTextValue;+ }++ i += oldTextValue.length - 1;+ } else {+ if (instanceNumValue === undefined) {+ result += textValue[i];+ }+ }+ }++ if (instanceNumValue && num < instanceNumValue) {+ result = textValue;+ }++ return StringValueObject.create(result);+ }++ private _getObjectString(variant: BaseValueObject): string {+ let value = `${variant.getValue()}`;++ if (variant.isNull()) {+ value = '';+ }++ if (variant.isBoolean()) {+ value = value.toLocaleUpperCase();+ }++ return value;+ }+}diff --git a/packages/engine-formula/src/functions/text/t/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/t/__test__/index.spec.tsnew file mode 100644index 0000000000..a350017152--- /dev/null+++ b/packages/engine-formula/src/functions/text/t/__test__/index.spec.ts@@ -0,0 +1,72 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { T } from '../index';++describe('Test t function', () => {+ const testFunction = new T(FUNCTION_NAMES_TEXT.T);++ describe('T', () => {+ it('Value is normal', () => {+ const value = StringValueObject.create('Univer');+ const result = testFunction.calculate(value);+ expect(getObjectValue(result)).toStrictEqual('Univer');+ });++ it('Value is number or boolean or null or error', () => {+ const value = NumberValueObject.create(123);+ const result = testFunction.calculate(value);+ expect(getObjectValue(result)).toStrictEqual('');++ const value2 = BooleanValueObject.create(true);+ const result2 = testFunction.calculate(value2);+ expect(getObjectValue(result2)).toStrictEqual('');++ const value3 = NullValueObject.create();+ const result3 = testFunction.calculate(value3);+ expect(getObjectValue(result3)).toStrictEqual('');++ const value4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(value4);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);+ });++ it('Value is array', () => {+ const value = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文测试', true, false, null],+ [0, '100', '2.34', '2-way street', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(value);+ expect(getObjectValue(result)).toStrictEqual('');+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/t/index.ts b/packages/engine-formula/src/functions/text/t/index.tsnew file mode 100644index 0000000000..1e19b8686a--- /dev/null+++ b/packages/engine-formula/src/functions/text/t/index.ts@@ -0,0 +1,44 @@+/**+ * 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 { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';++export class T extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(value: BaseValueObject): BaseValueObject {+ let _value = value;++ if (value.isArray()) {+ _value = (value as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (_value.isError()) {+ return _value;+ }++ if (_value.isNull() || _value.isBoolean() || _value.isNumber()) {+ return StringValueObject.create('');+ }++ return _value;+ }+}diff --git a/packages/engine-formula/src/functions/text/unichar/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/unichar/__test__/index.spec.tsnew file mode 100644index 0000000000..ad3c3bfd32--- /dev/null+++ b/packages/engine-formula/src/functions/text/unichar/__test__/index.spec.ts@@ -0,0 +1,86 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { NumberValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Unichar } from '../index';++describe('Test unichar function', () => {+ const testFunction = new Unichar(FUNCTION_NAMES_TEXT.UNICHAR);++ describe('Unichar', () => {+ it('Value is normal', () => {+ const number = NumberValueObject.create(123.45);+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual('{');+ });++ it('Number is negative', () => {+ const number = NumberValueObject.create(-2.34);+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.VALUE);+ });++ it('Number is big number', () => {+ const number = NumberValueObject.create(1114111);+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual(ErrorType.NA);++ const number2 = NumberValueObject.create(1114112);+ const result2 = testFunction.calculate(number2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number);+ expect(getObjectValue(result)).toStrictEqual([+ ['', ErrorType.VALUE, '', '', ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.VALUE, 'd', '', ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ ]);++ const number2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1234567890],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(number2);+ expect(getObjectValue(result2)).toStrictEqual(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/unichar/index.ts b/packages/engine-formula/src/functions/text/unichar/index.tsnew file mode 100644index 0000000000..95d5f679b5--- /dev/null+++ b/packages/engine-formula/src/functions/text/unichar/index.ts@@ -0,0 +1,89 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { DataStreamTreeTokenType } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++// special case for some characters causing doc stream issues+const filterCodeArray = Object.values(DataStreamTreeTokenType).filter((value) => {+ return [+ DataStreamTreeTokenType.TABLE_START,+ DataStreamTreeTokenType.TABLE_ROW_START,+ DataStreamTreeTokenType.TABLE_CELL_START,+ DataStreamTreeTokenType.TABLE_CELL_END,+ DataStreamTreeTokenType.TABLE_ROW_END,+ DataStreamTreeTokenType.TABLE_END,+ DataStreamTreeTokenType.CUSTOM_RANGE_START,+ DataStreamTreeTokenType.CUSTOM_RANGE_END,+ DataStreamTreeTokenType.CUSTOM_BLOCK,+ ].includes(value as DataStreamTreeTokenType);+});++export class Unichar extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject): BaseValueObject {+ if (number.isArray()) {+ const resultArray = (number as ArrayValueObject).mapValue((numberObject) => this._handleSingleObject(numberObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(number);+ }++ private _handleSingleObject(number: BaseValueObject): BaseValueObject {+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(number);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [numberObject] = variants as BaseValueObject[];++ const numberValue = Math.floor(+numberObject.getValue());++ if (numberValue < 1 || numberValue > 1114111) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ // for excel+ if (numberValue === 1114111 || numberValue === 1114110) {+ return ErrorValueObject.create(ErrorType.NA);+ }++ let result = String.fromCharCode(numberValue);++ // special case for some characters causing doc stream issues+ if (filterCodeArray.some((value) => value === result)) {+ result = String.fromCharCode(1);+ }++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/unicode/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/unicode/__test__/index.spec.tsnew file mode 100644index 0000000000..f7385a5d9c--- /dev/null+++ b/packages/engine-formula/src/functions/text/unicode/__test__/index.spec.ts@@ -0,0 +1,70 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Unicode } from '../index';++describe('Test unicode function', () => {+ const testFunction = new Unicode(FUNCTION_NAMES_TEXT.UNICODE);++ describe('Unicode', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('A');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(65);+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文', true, false, null],+ [0, 'ABC', '!', 'ÿ', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ [49, 32, 20013, 84, 70, ErrorType.VALUE],+ [48, 65, 33, 255, 45, ErrorType.NAME],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['หนึ่งบาทถ้วน'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual(3627);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/unicode/index.ts b/packages/engine-formula/src/functions/text/unicode/index.tsnew file mode 100644index 0000000000..bcb2d58c6d--- /dev/null+++ b/packages/engine-formula/src/functions/text/unicode/index.ts@@ -0,0 +1,61 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';++export class Unicode extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError()) {+ return text;+ }++ if (text.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let textValue = text.getValue().toLocaleString();++ if (text.isBoolean()) {+ textValue = textValue.toLocaleUpperCase();+ }++ const result = textValue.charCodeAt(0);++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/text/value/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/value/__test__/index.spec.tsnew file mode 100644index 0000000000..3de1cec4c6--- /dev/null+++ b/packages/engine-formula/src/functions/text/value/__test__/index.spec.ts@@ -0,0 +1,88 @@+/**+ * 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 { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject, ValueObjectFactory } from '../../../../engine/value-object/array-value-object';+import { StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Value } from '../index';++describe('Test value function', () => {+ const testFunction = new Value(FUNCTION_NAMES_TEXT.VALUE);++ describe('Value', () => {+ it('Value is normal', () => {+ const text = StringValueObject.create('123');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(123);+ });++ it('Value is array', () => {+ const text = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文', true, false, null],+ [0, '100', '2.34', 'ÿ', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual([+ [1, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, 0],+ [0, 100, 2.34, ErrorType.VALUE, -3, ErrorType.NAME],+ ]);++ const text2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2.34'],+ ]),+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual(2.34);+ });++ it('More test', () => {+ const text = ValueObjectFactory.create('20%');+ const result = testFunction.calculate(text);+ expect(getObjectValue(result)).toStrictEqual(0.2);++ const text2 = ValueObjectFactory.create('$1000');+ const result2 = testFunction.calculate(text2);+ expect(getObjectValue(result2)).toStrictEqual(1000);++ const text3 = ValueObjectFactory.create('16:48:00');+ const result3 = testFunction.calculate(text3);+ expect(getObjectValue(result3)).toStrictEqual(0.7);++ const text4 = ValueObjectFactory.create('2012-12-12');+ const result4 = testFunction.calculate(text4);+ expect(getObjectValue(result4)).toStrictEqual(41255);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/value/index.ts b/packages/engine-formula/src/functions/text/value/index.tsnew file mode 100644index 0000000000..8ccaf51bc3--- /dev/null+++ b/packages/engine-formula/src/functions/text/value/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 type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Value extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(text: BaseValueObject): BaseValueObject {+ if (text.isArray()) {+ const resultArray = (text as ArrayValueObject).mapValue((textObject) => this._handleSingleObject(textObject));++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ return this._handleSingleObject(text);+ }++ private _handleSingleObject(text: BaseValueObject): BaseValueObject {+ if (text.isError()) {+ return text;+ }++ if (text.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let _text = text;++ if (text.isString()) {+ _text = _text.convertToNumberObjectValue();++ if (_text.isError()) {+ return _text;+ }+ }++ const textValue = +_text.getValue();++ return NumberValueObject.create(textValue);+ }+}diff --git a/packages/engine-formula/src/functions/text/valuetotext/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/valuetotext/__test__/index.spec.tsnew file mode 100644index 0000000000..5ccebfb139--- /dev/null+++ b/packages/engine-formula/src/functions/text/valuetotext/__test__/index.spec.ts@@ -0,0 +1,82 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { getObjectValue } from '../../../__tests__/create-function-test-bed';+import { FUNCTION_NAMES_TEXT } from '../../function-names';+import { Valuetotext } from '../index';++describe('Test valuetotext function', () => {+ const testFunction = new Valuetotext(FUNCTION_NAMES_TEXT.VALUETOTEXT);++ describe('Valuetotext', () => {+ it('Value is normal', () => {+ const value = StringValueObject.create('Univer');+ const format = NumberValueObject.create(1);+ const result = testFunction.calculate(value, format);+ expect(getObjectValue(result)).toStrictEqual('"Univer"');+ });++ it('Format value test', () => {+ const value = StringValueObject.create('Univer');+ const format = NullValueObject.create();+ const result = testFunction.calculate(value, format);+ expect(getObjectValue(result)).toStrictEqual('Univer');++ const format2 = BooleanValueObject.create(true);+ const result2 = testFunction.calculate(value, format2);+ expect(getObjectValue(result2)).toStrictEqual('"Univer"');++ const format3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(value, format3);+ expect(getObjectValue(result3)).toStrictEqual(ErrorType.VALUE);++ const format4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(value, format4);+ expect(getObjectValue(result4)).toStrictEqual(ErrorType.NAME);++ const format5 = NumberValueObject.create(2);+ const result5 = testFunction.calculate(value, format5);+ expect(getObjectValue(result5)).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is array', () => {+ const value = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', '中文', true, false, null],+ [0, '100', '2.34', 'ÿ', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const format = NumberValueObject.create(1);+ const result = testFunction.calculate(value, format);+ expect(getObjectValue(result)).toStrictEqual([+ [1, '" "', '"中文"', true, false, ''],+ [0, 100, 2.34, '"ÿ"', -3, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/valuetotext/index.ts b/packages/engine-formula/src/functions/text/valuetotext/index.tsnew file mode 100644index 0000000000..643cd7bcfd--- /dev/null+++ b/packages/engine-formula/src/functions/text/valuetotext/index.ts@@ -0,0 +1,98 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { checkVariantsErrorIsStringToNumber } from '../../../engine/utils/check-variant-error';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Valuetotext extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(value: BaseValueObject, format?: BaseValueObject): BaseValueObject {+ const _format = format ?? NumberValueObject.create(0);++ const maxRowLength = Math.max(+ value.isArray() ? (value as ArrayValueObject).getRowCount() : 1,+ _format.isArray() ? (_format as ArrayValueObject).getRowCount() : 1+ );++ const maxColumnLength = Math.max(+ value.isArray() ? (value as ArrayValueObject).getColumnCount() : 1,+ _format.isArray() ? (_format as ArrayValueObject).getColumnCount() : 1+ );++ const valueArray = expandArrayValueObject(maxRowLength, maxColumnLength, value, ErrorValueObject.create(ErrorType.NA));+ const formatArray = expandArrayValueObject(maxRowLength, maxColumnLength, _format, ErrorValueObject.create(ErrorType.NA));++ const resultArray = valueArray.mapValue((valueObject, rowIndex, columnIndex) => {+ const formatObject = formatArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (valueObject.isError()) {+ return valueObject;+ }++ if (formatObject.isError()) {+ return formatObject;+ }++ return this._handleSingleObject(valueObject, formatObject);+ });++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return (resultArray as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(value: BaseValueObject, format: BaseValueObject): BaseValueObject {+ const { isError, errorObject, variants } = checkVariantsErrorIsStringToNumber(format);++ if (isError) {+ return errorObject as ErrorValueObject;+ }++ const [formatObject] = variants as BaseValueObject[];++ const formatValue = Math.floor(+formatObject.getValue());++ if (formatValue < 0 || formatValue > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (value.isNull()) {+ return StringValueObject.create('');+ }++ if (value.isBoolean()) {+ return value;+ }++ if (value.isNumber()) {+ return NumberValueObject.create(value.getValue() as number);+ }++ const result = formatValue ? `"${value.getValue()}"` : `${value.getValue()}`;++ return StringValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.tsindex 55d3edceba..f8a7a03a2b 100644--- a/packages/engine-formula/src/services/current-data.service.ts+++ b/packages/engine-formula/src/services/current-data.service.ts@@ -14,7 +14,10 @@* limitations under the License.*/-import type { IUnitRange, Nullable, Workbook } from '@univerjs/core';+import { createIdentifier, Disposable, Inject, IUniverInstanceService, LocaleService, ObjectMatrix, UniverInstanceType } from '@univerjs/core';+import type { IUnitRange, LocaleType, Nullable, Workbook } from '@univerjs/core';++import { convertUnitDataToRuntime } from '../basics/runtime';import type {IArrayFormulaRangeType,IDirtyUnitFeatureMap,@@ -32,9 +35,6 @@ import type {IUnitStylesData,} from '../basics/common';-import { createIdentifier, Disposable, IUniverInstanceService, ObjectMatrix, UniverInstanceType } from '@univerjs/core';-import { convertUnitDataToRuntime } from '../basics/runtime';-export interface IFormulaDirtyData {forceCalculation: boolean;dirtyRanges: IUnitRange[];@@ -96,6 +96,8 @@ export interface IFormulaCurrentConfigService {getDirtyData(): IFormulaDirtyData;getClearDependencyTreeCache(): IDirtyUnitSheetNameMap;++ getLocale(): LocaleType;}export class FormulaCurrentConfigService extends Disposable implements IFormulaCurrentConfigService {@@ -132,7 +134,10 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCprivate _executeUnitId: Nullable<string> = '';private _executeSubUnitId: Nullable<string> = '';- constructor(@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService) {+ constructor(+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,+ @Inject(LocaleService) private readonly _localeService: LocaleService+ ) {super();}@@ -232,6 +237,10 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCreturn this._clearDependencyTreeCache;}+ getLocale() {+ return this._localeService.getCurrentLocale();+ }+load(config: IFormulaDatasetConfig) {if (config.allUnitData && config.unitSheetNameMap && config.unitStylesData) {this._unitData = config.allUnitData;diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.tsindex 1fc391e581..5380ec94f6 100644--- a/packages/engine-formula/src/services/runtime.service.ts+++ b/packages/engine-formula/src/services/runtime.service.ts@@ -30,7 +30,7 @@ import { isInDirtyRange } from '../basics/dirty';import { ErrorType } from '../basics/error-type';import { CELL_INVERTED_INDEX_CACHE } from '../basics/inverted-index-cache';import { getRuntimeFeatureCell } from '../engine/utils/get-runtime-feature-cell';-import { clearNumberFormatTypeCache } from '../engine/utils/numfmt-kit';+import { clearNumberFormatTypeCache, clearStringToNumberPatternCache } from '../engine/utils/numfmt-kit';import { clearReferenceToRangeCache } from '../engine/utils/reference';import { objectValueToCellValue } from '../engine/utils/value-object';import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';@@ -370,6 +370,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeclearReferenceAndNumberformatCache() {clearNumberFormatTypeCache();+ clearStringToNumberPatternCache();clearReferenceToRangeCache();}diff --git a/packages/sheets-formula-ui/src/locale/function-list/math/en-US.ts b/packages/sheets-formula-ui/src/locale/function-list/math/en-US.tsindex 04bb071caf..ef425f1562 100644--- a/packages/sheets-formula-ui/src/locale/function-list/math/en-US.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/math/en-US.ts@@ -107,8 +107,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'A string enclosed in quotation marks, an empty string (""), or a reference to a cell containing text.' },},},ASIN: {@@ -800,8 +799,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The Arabic numeral you want converted.' },+ form: { name: 'form', detail: 'A number specifying the type of roman numeral you want. The roman numeral style ranges from Classic to Simplified, becoming more concise as the value of form increases.' },},},ROUND: {diff --git a/packages/sheets-formula-ui/src/locale/function-list/math/ja-JP.ts b/packages/sheets-formula-ui/src/locale/function-list/math/ja-JP.tsindex cece45811a..5b6883c6b9 100644--- a/packages/sheets-formula-ui/src/locale/function-list/math/ja-JP.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/math/ja-JP.ts@@ -107,8 +107,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '半角の二重引用符で囲んだ文字列、空の文字列 ("")、または文字列を含むセルへの参照を指定します。' },},},ASIN: {@@ -800,8 +799,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '変換するアラビア数字を指定します。' },+ form: { name: '書式', detail: 'ローマ数字の書式を数値で指定します。 ローマ数字の書式には正式な形式から簡略化した形式まであり、書式の値が大きくなるほど、簡略化した形式で表示されます。' },},},ROUND: {diff --git a/packages/sheets-formula-ui/src/locale/function-list/math/vi-VN.ts b/packages/sheets-formula-ui/src/locale/function-list/math/vi-VN.tsindex 6f31cb06dd..961ddbccb0 100644--- a/packages/sheets-formula-ui/src/locale/function-list/math/vi-VN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/math/vi-VN.ts@@ -80,6 +80,19 @@ export default {number: { name: 'số', detail: 'Giá trị tuyệt đối của Số phải lớn hơn 1.' },},},+ ARABIC: {+ description: '将罗马数字转换为阿拉伯数字',+ abstract: '将罗马数字转换为阿拉伯数字',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/arabic-%E5%87%BD%E6%95%B0-9a8da418-c17b-4ef9-a657-9370a30a674f',+ },+ ],+ functionParameter: {+ text: { name: 'bản văn', detail: 'Một chuỗi nằm trong dấu ngoặc kép, một chuỗi trống ("") hoặc một tham chiếu đến ô có chứa văn bản.' },+ },+ },ASIN: {description: 'Trả về arcsin, hayine nghịch đảo của một số.',abstract: 'Trả về arcsin, hayine nghịch đảo của một số.',@@ -731,6 +744,20 @@ export default {top: { name: 'giá trị tối đa', detail: 'Số nguyên lớn nhất mà sẽ trả về.' },},},+ ROMAN: {+ description: 'Chuyển đổi số Ả-rập thành số La Mã, dạng văn bản.',+ abstract: 'Chuyển đổi số Ả-rập thành số La Mã, dạng văn bản.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/roman-%E5%87%BD%E6%95%B0-d6b0b99e-de46-4704-a518-b45a0f8b56f5',+ },+ ],+ functionParameter: {+ number: { name: 'số', detail: 'Số Ả-rập mà bạn muốn chuyển đổi.' },+ form: { name: 'hình thức', detail: 'Một số xác định kiểu chữ số La Mã bạn muốn. Kiểu chữ số La Mã bao gồm từ kiểu Cổ điển đến kiểu Giản thể, trở nên ngắn gọn hơn khi giá trị của biểu mẫu tăng lên.' },+ },+ },ROUND: {description: 'làm tròn một số tới một số chữ số đã xác định.',abstract: 'làm tròn một số tới một số chữ số đã xác định.',diff --git a/packages/sheets-formula-ui/src/locale/function-list/math/zh-CN.ts b/packages/sheets-formula-ui/src/locale/function-list/math/zh-CN.tsindex 3ca9da61f3..36cbe47b13 100644--- a/packages/sheets-formula-ui/src/locale/function-list/math/zh-CN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/math/zh-CN.ts@@ -106,8 +106,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '用引号括起来的字符串、 ("") 的空字符串或对包含文本的单元格的引用。' },},},ASIN: {@@ -799,8 +798,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '需要转换的阿拉伯数字。' },+ form: { name: '形式', detail: '指定所需罗马数字类型的数字。 罗马数字样式的范围从经典到简化,随着形式值的增加,会变得更加简洁。' },},},ROUND: {diff --git a/packages/sheets-formula-ui/src/locale/function-list/math/zh-TW.ts b/packages/sheets-formula-ui/src/locale/function-list/math/zh-TW.tsindex 9549225aae..2dc2056939 100644--- a/packages/sheets-formula-ui/src/locale/function-list/math/zh-TW.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/math/zh-TW.ts@@ -106,8 +106,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '以引弧括住的字串、空字串 (“) ,或包含文字的單元格參照。' },},},ASIN: {@@ -798,8 +797,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要轉換的阿拉伯數字。' },+ form: { name: '形式', detail: '這是指定所需羅馬數字類型的數字。羅馬數位風格從經典到簡化,隨著形式值的增加而變得更加簡潔。' },},},ROUND: {diff --git a/packages/sheets-formula-ui/src/locale/function-list/text/en-US.ts b/packages/sheets-formula-ui/src/locale/function-list/text/en-US.tsindex 3c1e247695..74ee3a2a4a 100644--- a/packages/sheets-formula-ui/src/locale/function-list/text/en-US.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/text/en-US.ts@@ -25,8 +25,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text or a reference to a cell that contains the text you want to change. If text does not contain any full-width letters, text is not changed.' },},},ARRAYTOTEXT: {@@ -39,8 +38,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: 'array', detail: 'The array to return as text.' },+ format: { name: 'format', detail: 'The format of the returned data. It can be one of two values: \n0 Default. Concise format that is easy to read. \n1 Strict format that includes escape characters and row delimiters. Generates a string that can be parsed when entered into the formula bar. Encapsulates returned strings in quotes except for Booleans, Numbers and Errors.' },},},BAHTTEXT: {@@ -53,8 +52,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'A number you want to convert to text, or a reference to a cell containing a number, or a formula that evaluates to a number.' },},},CHAR: {@@ -67,8 +65,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'A number between 1 and 255 specifying which character you want. The character is from the character set used by your computer.' },},},CLEAN: {@@ -81,8 +78,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'Any worksheet information from which you want to remove nonprintable characters.' },},},CODE: {@@ -95,8 +91,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text for which you want the code of the first character.' },},},CONCAT: {@@ -137,13 +132,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text or a reference to a cell that contains the text you want to change. If text does not contain any half-width English letters or katakana, text is not changed.' },},},DOLLAR: {- description: 'Converts a number to text, using the $ (dollar) currency format',- abstract: 'Converts a number to text, using the $ (dollar) currency format',+ description: 'Converts a number to text using currency format',+ abstract: 'Converts a number to text using currency format',links: [{title: 'Instruction',@@ -151,8 +145,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'A number, a reference to a cell containing a number, or a formula that evaluates to a number.' },+ decimals: { name: 'decimals', detail: 'The number of digits to the right of the decimal point. If this is negative, the number is rounded to the left of the decimal point. If you omit decimals, it is assumed to be 2.' },},},EXACT: {@@ -165,8 +159,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text1: { name: 'text1', detail: 'The first text string.' },+ text2: { name: 'text2', detail: 'The second text string.' },},},FIND: {@@ -207,8 +201,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The number you want to round and convert to text.' },+ decimals: { name: 'decimals', detail: 'The number of digits to the right of the decimal point. If this is negative, the number is rounded to the left of the decimal point. If you omit decimals, it is assumed to be 2.' },+ noCommas: { name: 'no_commas', detail: 'A logical value that, if TRUE, prevents FIXED from including commas in the returned text.' },},},LEFT: {@@ -320,8 +315,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text to convert to a number.' },+ decimalSeparator: { name: 'decimal_separator', detail: 'The character used to separate the integer and fractional part of the result.' },+ groupSeparator: { name: 'group_separator', detail: 'The character used to separate groupings of numbers.' },},},PHONETIC: {@@ -348,8 +344,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'Text enclosed in quotation marks, a formula that returns text, or a reference to a cell containing the text you want to partially capitalize.' },},},REGEXEXTRACT: {@@ -447,8 +442,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text string containing the characters you want to extract.' },+ numChars: { name: 'num_chars', detail: 'Specifies the number of characters you want RIGHT to extract.' },},},RIGHTB: {@@ -461,8 +456,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text string containing the characters you want to extract.' },+ numBytes: { name: 'num_bytes', detail: 'Specifies the number of characters you want RIGHTB to extract, based on bytes.' },},},SEARCH: {@@ -503,8 +498,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text or the reference to a cell containing text for which you want to substitute characters.' },+ oldText: { name: 'old_text', detail: 'The text you want to replace.' },+ newText: { name: 'new_text', detail: 'The text you want to replace old_text with.' },+ instanceNum: { name: 'instance_num', detail: 'Specifies which occurrence of old_text you want to replace with new_text. If you specify instance_num, only that instance of old_text is replaced. Otherwise, every occurrence of old_text in text is changed to new_text.' },},},T: {@@ -517,8 +514,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: 'value', detail: 'The value you want to test.' },},},TEXT: {@@ -627,8 +623,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'Number is the Unicode number that represents the character.' },},},UNICODE: {@@ -641,8 +636,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'Text is the character for which you want the Unicode value.' },},},UPPER: {@@ -669,8 +663,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The text enclosed in quotation marks or a reference to a cell containing the text you want to convert.' },},},VALUETOTEXT: {@@ -683,8 +676,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: 'value', detail: 'The value to return as text.' },+ format: { name: 'format', detail: 'The format of the returned data. It can be one of two values: \n0 Default. Concise format that is easy to read. \n1 Strict format that includes escape characters and row delimiters. Generates a string that can be parsed when entered into the formula bar. Encapsulates returned strings in quotes except for Booleans, Numbers and Errors.' },},},CALL: {diff --git a/packages/sheets-formula-ui/src/locale/function-list/text/ja-JP.ts b/packages/sheets-formula-ui/src/locale/function-list/text/ja-JP.tsindex 4d822b457d..f2c830b60c 100644--- a/packages/sheets-formula-ui/src/locale/function-list/text/ja-JP.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/text/ja-JP.ts@@ -25,8 +25,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '文字列または変換する文字列を含むセルの参照を指定します。 文字列に全角文字が含まれない場合は、文字列は変換されません。' },},},ARRAYTOTEXT: {@@ -39,8 +38,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '配列', detail: '文字列として返す配列。' },+ format: { name: '書式', detail: '返されるデータの形式。次の 2 つの値のいずれかを指定できます。\n0 既定。 読みやすい簡潔な形式。 \n1 エスケープ文字と行の区切り文字を含む厳格なフォーマット。 数式バーに入力したときに解析できる文字列を生成します。 返された文字列は、ブーリアン、数値、エラーを除き、引用符でカプセル化されます。' },},},BAHTTEXT: {@@ -53,8 +52,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '文字列に変換する数値、数値を含むセルの参照、または戻り値が数値となる数式を指定します。' },},},CHAR: {@@ -67,8 +65,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '変換する文字を表す 1 ~ 255 の範囲内の数値を指定します。 文字は、コンピューターで使用されている文字セットから返されます。' },},},CLEAN: {@@ -81,8 +78,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '印刷できない文字を削除するワークシートの文字データを指定します。' },},},CODE: {@@ -95,8 +91,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '先頭文字のコード番号を調べる文字列を指定します。' },},},CONCAT: {@@ -137,14 +132,13 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '文字列または変換する文字列を含むセルの参照を指定します。 文字列に半角の英数カナ文字が含まれない場合は、文字列は変更されません。' },},},DOLLAR: {aliasFunctionName: 'YEN',- description: '数値を四捨五入し、通貨書式を設定した文字列に変換します。DOLLARでは、ドル ($) 通貨書式が設定されます。YENでは、円 (\\) 通貨書式が設定されます。',- abstract: '数値を四捨五入し、通貨書式を設定した文字列に変換します。DOLLARでは、ドル ($) 通貨書式が設定されます。YENでは、円 (\\) 通貨書式が設定されます。',+ description: '通貨形式を使用して数値をテキストに変換します',+ abstract: '通貨形式を使用して数値をテキストに変換します',links: [{title: '指導',@@ -152,8 +146,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '数値、数値を含むセルの参照、または結果が数値になる数式を指定します。' },+ decimals: { name: '桁数', detail: '小数点以下の桁数を指定します。 負の値の場合、数値は小数点の左側に丸められます。 桁数を省略すると、2 を指定したと見なされます。' },},},EXACT: {@@ -166,8 +160,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text1: { name: '文字列1', detail: '一方の文字列を指定します。' },+ text2: { name: '文字列2', detail: 'もう一方の文字列を指定します。' },},},FIND: {@@ -208,8 +202,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '四捨五入して文字列に変換する数値を指定します。' },+ decimals: { name: '桁数', detail: '小数点以下の桁数を指定します。 負の値の場合、数値は小数点の左側に丸められます。 桁数を省略すると、2 を指定したと見なされます。' },+ noCommas: { name: '桁区切り', detail: '返される文字列をカンマ (,) で桁区切りするかどうかを論理値で指定します。TRUE を指定すると、桁区切りは行われません。' },},},LEFT: {@@ -321,8 +316,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '数値に変換するテキスト。' },+ decimalSeparator: { name: '小数点区切り文字', detail: '結果の整数部分と小数部を区切るために使用される文字。' },+ groupSeparator: { name: 'グループ区切り文字', detail: 'の数値のグループを区切るために使用される文字。' },},},PHONETIC: {@@ -349,8 +345,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '引用符で囲まれたテキスト、テキストを返す数式、または部分的に大文字にするテキストを含むセルへの参照。' },},},REGEXEXTRACT: {@@ -448,8 +443,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '取り出す文字を含む文字列を指定します。' },+ numChars: { name: '文字数', detail: '取り出す文字数 (文字列の末尾からの文字数) を指定します。' },},},RIGHTB: {@@ -462,8 +457,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '取り出す文字を含む文字列を指定します。' },+ numBytes: { name: 'バイト数', detail: '取り出す文字数をバイト数で指定します。' },},},SEARCH: {@@ -504,8 +499,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '文字を置き換えるテキストを含むセルへのテキストまたは参照。' },+ oldText: { name: '検索文字列', detail: '置換する文字列を指定します。' },+ newText: { name: '置換文字列', detail: '検索文字列を検索して置き換える文字列を指定します。' },+ instanceNum: { name: '置換対象を指定', detail: '検索文字列に含まれるどの文字列を置換文字列と置き換えるかを指定します。 置換対象を指定した場合、検索文字列中の置換対象文字列だけが置き換えられます。 指定しない場合、検索文字列中のすべての文字列が置換文字列に置き換えられます。' },},},T: {@@ -518,8 +515,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: '値', detail: 'テストする値を指定します。' },},},TEXT: {@@ -628,8 +624,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '文字に対応する Unicode 番号を指定します。' },},},UNICODE: {@@ -642,8 +637,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: 'Unicode 値を求める文字を指定します。' },},},UPPER: {@@ -670,8 +664,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '文字列を半角の二重引用符 (") で囲んで指定するか、または変換する文字列を含むセル参照を指定します。' },},},VALUETOTEXT: {@@ -684,8 +677,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: '値', detail: '文字列として返す値。' },+ format: { name: '書式', detail: '返されるデータの形式。次の 2 つの値のいずれかを指定できます。\n0 既定。 読みやすい簡潔な形式。 \n1 エスケープ文字と行の区切り文字を含む厳格なフォーマット。 数式バーに入力したときに解析できる文字列を生成します。 返された文字列は、ブーリアン、数値、エラーを除き、引用符でカプセル化されます。' },},},CALL: {diff --git a/packages/sheets-formula-ui/src/locale/function-list/text/vi-VN.ts b/packages/sheets-formula-ui/src/locale/function-list/text/vi-VN.tsindex 4fa3802540..c8bf25ce4f 100644--- a/packages/sheets-formula-ui/src/locale/function-list/text/vi-VN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/text/vi-VN.ts@@ -25,8 +25,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'bản văn', detail: 'Văn bản hoặc tham chiếu tới một ô có chứa văn bản mà bạn muốn thay đổi. Nếu văn bản không chứa chữ nào có độ rộng toàn phần, thì văn bản không thay đổi.' },},},ARRAYTOTEXT: {@@ -39,8 +38,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: 'mảng', detail: 'Mảng cần trả về dưới dạng văn bản.' },+ format: { name: 'Định dạng của dữ', detail: 'Định dạng của dữ liệu trả về. Nó có thể là một trong hai giá trị: \n0 Mặc định. Định dạng ngắn gọn dễ đọc.\n1 Định dạng nghiêm ngặt bao gồm ký tự thoát và dấu tách hàng. Tạo một chuỗi có thể được phân tích khi nhập vào thanh công thức. Đóng gói các chuỗi trả về trong dấu ngoặc kép, ngoại trừ Booleans, Numbers và Errors.' },},},BAHTTEXT: {@@ -53,8 +52,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'số', detail: 'Là số mà bạn muốn chuyển sang văn bản hoặc tham chiếu đến ô có chứa số, hay công thức định trị thành số.' },},},CHAR: {@@ -67,8 +65,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'số', detail: 'Số từ 1 đến 255 xác định bạn muốn ký tự nào. Ký tự này nằm trong bộ ký tự mà máy tính của bạn dùng.' },},},CLEAN: {@@ -81,8 +78,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'bản văn', detail: 'Bất kỳ thông tin trang tính nào bạn muốn loại bỏ ký tự không in được khỏi đó.' },},},CODE: {@@ -95,8 +91,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'bản văn', detail: 'Văn bản mà bạn muốn mã của ký tự đầu tiên cho văn bản đó.' },},},CONCAT: {@@ -137,13 +132,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'bản văn', detail: 'Văn bản hoặc tham chiếu tới một ô có chứa văn bản mà bạn muốn thay đổi. Nếu văn bản không chứa chữ Tiếng Anh có độ rộng bán phần hay katakana nào, thì văn bản không đổi.' },},},DOLLAR: {- description: 'Chuyển đổi số thành văn bản bằng định dạng tiền tệ Nhân dân tệ (RMB)',- abstract: 'Chuyển đổi số thành văn bản bằng định dạng tiền tệ Nhân dân tệ (RMB)',+ description: 'Chuyển đổi một số thành văn bản bằng cách dùng định dạng tiền tệ',+ abstract: 'Chuyển đổi một số thành văn bản bằng cách dùng định dạng tiền tệ',links: [{title: 'Hướng dẫn',@@ -151,8 +145,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'số', detail: 'Số, tham chiếu đến ô chứa số hoặc công thức sẽ trả về số.' },+ decimals: { name: 'số chữ thập phân', detail: 'Số chữ số nằm bên phải dấu thập phân. Nếu đây là số âm, thì số được làm tròn sang bên trái dấu thập phân. Nếu bạn bỏ qua đối số decimals, nó được giả định là bằng 2.' },},},EXACT: {@@ -165,8 +159,8 @@ export default {},],functionParameter: {- text1: { name: 'bản văn 1', detail: 'Chuỗi văn bản đầu tiên' },- text2: { name: 'bản văn 2', detail: 'Chuỗi văn bản thứ hai' },+ text1: { name: 'bản văn 1', detail: 'Chuỗi văn bản đầu tiên.' },+ text2: { name: 'bản văn 2', detail: 'Chuỗi văn bản thứ hai.' },},},FIND: {@@ -194,9 +188,9 @@ export default {},],functionParameter: {- number: { name: 'number', detail: 'Số mà bạn muốn làm tròn và chuyển đổi thành văn bản.' },- decimals: { name: 'decimals', detail: 'Số lượng chữ số ở bên phải của dấu thập phân.' },- no_commas: { name: 'no_commas', detail: 'Giá trị logic chỉ định liệu trả về văn bản có bao gồm dấu phẩy hay không.' },+ number: { name: 'số', detail: 'Số bạn muốn làm tròn và chuyển đổi thành văn bản.' },+ decimals: { name: 'số chữ thập phân', detail: 'Số chữ số nằm bên phải dấu thập phân. Nếu đây là số âm, thì số được làm tròn sang bên trái dấu thập phân. Nếu bạn bỏ qua đối số decimals, nó được giả định là bằng 2.' },+ noCommas: { name: 'tắt dấu phân cách', detail: 'Giá trị logic, nếu ĐÚNG, sẽ ngăn FIXED đưa dấu phẩy vào văn bản trả về.' },},},LEFT: {@@ -267,6 +261,21 @@ export default {num_chars: { name: 'num_chars', detail: 'Bắt buộc đối với hàm MID. Chỉ rõ số ký tự mà bạn muốn hàm MID trả về từ văn bản.\nNếu số ký tự là số âm, thì hàm MID trả về giá trị lỗi #VALUE! .' },},},+ NUMBERVALUE: {+ description: 'Chuyển văn bản sang số, theo cách độc lập vị trí.',+ abstract: 'Chuyển văn bản sang số, theo cách độc lập vị trí.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/numbervalue-%E5%87%BD%E6%95%B0-1b05c8cf-2bfa-4437-af70-596c7ea7d879',+ },+ ],+ functionParameter: {+ text: { name: 'bản văn', detail: 'Văn bản chuyển sang số.' },+ decimalSeparator: { name: 'dấu phân cách thập phân', detail: 'Ký tự dùng để tách số nguyên và phần phân số của kết quả.' },+ groupSeparator: { name: 'dấu phân cách nhóm', detail: 'Ký tự dùng để tách các nhóm số.' },+ },+ },PHONETIC: {description: 'Trả về chuỗi Furigana từ chuỗi văn bản',abstract: 'Trả về chuỗi Furigana từ chuỗi văn bản',@@ -291,7 +300,7 @@ export default {},],functionParameter: {- text: { name: 'text', detail: 'Chuỗi văn bản mà bạn muốn chuyển đổi chữ cái đầu tiên của mỗi từ thành chữ hoa và tất cả các chữ cái khác thành chữ thường.' },+ text: { name: 'bản văn', detail: 'Văn bản được đặt trong dấu ngoặc kép, công thức trả về văn bản hoặc tham chiếu đến ô chứa văn bản mà bạn muốn viết hoa một phần.' },},},REGEXEXTRACT: {@@ -377,8 +386,22 @@ export default {},],functionParameter: {- text: { name: 'text', detail: 'Chuỗi văn bản có chứa các ký tự bạn muốn trích xuất.' },- num_chars: { name: 'num_chars', detail: 'Số lượng ký tự mà bạn muốn trích xuất.' },+ text: { name: 'bản văn', detail: 'Chuỗi văn bản chứa các ký tự bạn muốn trích xuất.' },+ numChars: { name: 'số ký tự', detail: 'Chỉ định số ký tự bạn muốn RIGHT trích xuất.' },+ },+ },+ RIGHTB: {+ description: 'Trả về một số ký tự cụ thể từ cuối của chuỗi văn bản',+ abstract: 'Trả về một số ký tự cụ thể từ cuối của chuỗi văn bản',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/right-rightb-%E5%87%BD%E6%95%B0-240267ee-9afa-4639-a02b-f19e1786cf2f',+ },+ ],+ functionParameter: {+ text: { name: 'bản văn', detail: 'Chuỗi văn bản chứa các ký tự bạn muốn trích xuất.' },+ numBytes: { name: 'số Byte', detail: 'Chỉ rõ số ký tự mà bạn muốn hàm RIGHTB trích xuất, dựa trên byte.' },},},SEARCH: {@@ -422,10 +445,23 @@ export default {},],functionParameter: {- text: { name: 'text', detail: 'Chuỗi văn bản ban đầu.' },- old_text: { name: 'old_text', detail: 'Văn bản bạn muốn thay thế.' },- new_text: { name: 'new_text', detail: 'Văn bản thay thế.' },- instance_num: { name: 'instance_num', detail: 'Số lần xuất hiện của old_text mà bạn muốn thay thế.' },+ text: { name: 'bản văn', detail: 'Văn bản hoặc tham chiếu đến ô chứa văn bản mà bạn muốn thay thế bằng ký tự.' },+ oldText: { name: 'tìm kiếm văn bản', detail: 'Văn bản bạn muốn thay thế.' },+ newText: { name: 'văn bản thay thế', detail: 'Văn bản bạn muốn thay thế old_text.' },+ instanceNum: { name: 'chỉ định đối tượng thay thế', detail: 'Chỉ định trường hợp nào của old_text bạn muốn thay thế bằng new_text. Nếu bạn chỉ định instance_num, chỉ trường hợp đó của old_text được thay thế. Nếu không, mọi trường hợp của old_text trong text sẽ được thay đổi thành new_text.' },+ },+ },+ T: {+ description: 'Chuyển đổi tham số thành văn bản',+ abstract: 'Chuyển đổi tham số thành văn bản',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/t-%E5%87%BD%E6%95%B0-fb83aeec-45e7-4924-af95-53e073541228',+ },+ ],+ functionParameter: {+ value: { name: 'giá trị', detail: 'Giá trị mà bạn muốn kiểm tra.' },},},TEXT: {@@ -535,7 +571,7 @@ export default {},],functionParameter: {- number: { name: 'number', detail: 'Số Unicode đại diện cho ký tự.' },+ number: { name: 'số', detail: 'Số là số Unicode biểu diễn ký tự.' },},},UNICODE: {@@ -548,7 +584,7 @@ export default {},],functionParameter: {- text: { name: 'text', detail: 'Chuỗi văn bản đại diện cho ký tự Unicode.' },+ text: { name: 'bản văn', detail: 'Văn bản là ký tự mà bạn muốn có giá trị Unicode.' },},},UPPER: {@@ -574,7 +610,21 @@ export default {},],functionParameter: {- text: { name: 'text', detail: 'Chuỗi văn bản mà bạn muốn chuyển đổi thành số.' },+ text: { name: 'bản văn', detail: 'Văn bản được đặt trong dấu ngoặc kép hoặc tham chiếu đến ô chứa văn bản bạn muốn chuyển đổi.' },+ },+ },+ VALUETOTEXT: {+ description: 'Trả về văn bản từ bất kỳ giá trị nào được chỉ định.',+ abstract: 'Trả về văn bản từ bất kỳ giá trị nào được chỉ định.',+ links: [+ {+ title: 'Hướng dẫn',+ url: 'https://support.microsoft.com/vi-vn/office/valuetotext-%E5%87%BD%E6%95%B0-5fff61a2-301a-4ab2-9ffa-0a5242a08fea',+ },+ ],+ functionParameter: {+ value: { name: 'giá trị', detail: 'Giá trị cần trả về dưới dạng văn bản.' },+ format: { name: 'Định dạng của dữ', detail: 'Định dạng của dữ liệu trả về. Nó có thể là một trong hai giá trị: \n0 Mặc định. Định dạng ngắn gọn dễ đọc.\n1 Định dạng nghiêm ngặt bao gồm ký tự thoát và dấu tách hàng. Tạo một chuỗi có thể được phân tích khi nhập vào thanh công thức. Đóng gói các chuỗi trả về trong dấu ngoặc kép, ngoại trừ Booleans, Numbers và Errors.' },},},};diff --git a/packages/sheets-formula-ui/src/locale/function-list/text/zh-CN.ts b/packages/sheets-formula-ui/src/locale/function-list/text/zh-CN.tsindex 0163ac142e..8b29e4dcfd 100644--- a/packages/sheets-formula-ui/src/locale/function-list/text/zh-CN.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/text/zh-CN.ts@@ -25,8 +25,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '文本或对包含要更改文本的单元格的引用。 如果文本不包含任何全角字母,则不会对文本进行转换。' },},},ARRAYTOTEXT: {@@ -39,8 +38,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '数组', detail: '要返回为文本的数组。' },+ format: { name: '数据格式', detail: '返回的数据的格式。它可以是两个值之一:\n0 默认。 易于阅读的简明格式。\n1 包含转义字符和行定界符的严格格式。 生成一条可在输入编辑栏时被解析的字符串。 将返回的字符串(布尔值、数字和错误除外)封装在引号中。' },},},BAHTTEXT: {@@ -53,8 +52,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要转换成文本的数字、对包含数字的单元格的引用或结果为数字的公式。' },},},CHAR: {@@ -67,8 +65,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '介于 1 到 255 之间的数字,指定所需的字符。 使用的是当前计算机字符集中的字符。' },},},CLEAN: {@@ -81,8 +78,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '要从中删除非打印字符的任何工作表信息。' },},},CODE: {@@ -95,8 +91,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '要为其获取第一个字符的代码的文本。' },},},CONCAT: {@@ -137,13 +132,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '文本或包含要转换的文本的单元格的引用。 如果文本中不包含任何半角英文字母或片假名,则不会对文本进行转换。' },},},DOLLAR: {- description: '使用 ¥(人民币)货币格式将数字转换为文本',- abstract: '使用 ¥(人民币)货币格式将数字转换为文本',+ description: '使用货币格式将数字转换为文本',+ abstract: '使用货币格式将数字转换为文本',links: [{title: '教学',@@ -151,8 +145,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '数字、对包含数字的单元格的引用或是计算结果为数字的公式。' },+ decimals: { name: '小数位数', detail: '小数点右边的位数。 如果这是负数,则数字将舍入到小数点的左侧。 如果省略 decimals,则假设其值为 2。' },},},EXACT: {@@ -165,8 +159,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text1: { name: '文本1', detail: '第一个文本字符串。' },+ text2: { name: '文本2', detail: '第二个文本字符串。' },},},FIND: {@@ -207,8 +201,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要进行舍入并转换为文本的数字。' },+ decimals: { name: '小数位数', detail: '小数点右边的位数。 如果这是负数,则数字将舍入到小数点的左侧。 如果省略 decimals,则假设其值为 2。' },+ noCommas: { name: '禁用分隔符', detail: '一个逻辑值,如果为 TRUE,则会禁止 FIXED 在返回的文本中包含逗号。' },},},LEFT: {@@ -320,8 +315,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '要转换为数字的文本。' },+ decimalSeparator: { name: '小数分隔符', detail: '用于分隔结果的整数和小数部分的字符。' },+ groupSeparator: { name: '分组分隔符', detail: '用于分隔数字分组的字符。' },},},PHONETIC: {@@ -348,8 +344,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '用引号括起来的文本、返回文本值的公式,或者对包含要进行部分大写转换文本的单元格的引用。' },},},REGEXEXTRACT: {@@ -447,8 +442,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '包含要提取字符的文本字符串。' },+ numChars: { name: '字符数', detail: '指定希望 RIGHT 提取的字符数。' },},},RIGHTB: {@@ -461,8 +456,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '包含要提取字符的文本字符串。' },+ numBytes: { name: '字节数', detail: '按字节指定要由 RIGHTB 提取的字符的数量。' },},},SEARCH: {@@ -503,8 +498,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '需要替换其中字符的文本,或对含有文本(需要替换其中字符)的单元格的引用。' },+ oldText: { name: '搜索文本', detail: '需要替换的文本。' },+ newText: { name: '替换文本', detail: '用于替换 old_text 的文本。' },+ instanceNum: { name: '指定替换对象', detail: '指定要将第几个 old_text 替换为 new_text。 如果指定了 instance_num,则只有满足要求的 old_text 被替换。 否则,文本中出现的所有 old_text 都会更改为 new_text。' },},},T: {@@ -517,8 +514,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: '值', detail: '要测试的值。' },},},TEXT: {@@ -627,8 +623,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '是表示字符的 Unicode 编号。' },},},UNICODE: {@@ -641,8 +636,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '是需要 Unicode 值的字符。' },},},UPPER: {@@ -669,8 +663,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '用引号括起来的文本或包含要转换文本的单元格的引用。' },},},VALUETOTEXT: {@@ -683,8 +676,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: '值', detail: '以文本形式返回的值。' },+ format: { name: '数据格式', detail: '返回的数据的格式。它可以是两个值之一:\n0 默认。 易于阅读的简明格式。\n1 包含转义字符和行定界符的严格格式。 生成一条可在输入编辑栏时被解析的字符串。 将返回的字符串(布尔值、数字和错误除外)封装在引号中。' },},},CALL: {diff --git a/packages/sheets-formula-ui/src/locale/function-list/text/zh-TW.ts b/packages/sheets-formula-ui/src/locale/function-list/text/zh-TW.tsindex 6ad7a42515..7f37fc4d95 100644--- a/packages/sheets-formula-ui/src/locale/function-list/text/zh-TW.ts+++ b/packages/sheets-formula-ui/src/locale/function-list/text/zh-TW.ts@@ -25,8 +25,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是文字或儲存格參照,其中包含所要變更的文字。 如果文字中不包含任何全形字母,則文字不會變更。' },},},ARRAYTOTEXT: {@@ -39,8 +38,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array: { name: '陣列', detail: '要傳回做為文字的陣列。' },+ format: { name: '資料格式', detail: '傳回資料的格式。它可以是兩個值的其中之一:\n0 預設。 易於閱讀的精簡格式。\n1 包含逸出字元和列分隔符號的限定格式。 產生可在輸入至資料編輯列時進行剖析的字串。 封裝會以引號傳回字串,除了布林值、數字和錯誤以外。' },},},BAHTTEXT: {@@ -53,8 +52,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '為要轉換成文字的數字,或包含數字的儲存格參照,或結果為數字的公式。' },},},CHAR: {@@ -67,8 +65,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是介於 1 和 255 之間的數字,用以指定您所需的字元。 此字元來自您電腦所使用的字元集。' },},},CLEAN: {@@ -81,8 +78,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是要從中移除無法列印之字元的任何工作表資訊。' },},},CODE: {@@ -95,8 +91,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是欲求其第一個字元代碼的文字。' },},},CONCAT: {@@ -137,13 +132,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是文字或儲存格參照,其中包含所要變更的文字。 如果文字中不包含任何半形英文字母或片假名,文字就不會變更。' },},},DOLLAR: {- description: '使用 ¥(人民幣)貨幣格式將數字轉換為文本',- abstract: '使用 ¥(人民幣)貨幣格式將數字轉換為文本',+ description: '使用貨幣格式將數字轉換為文本',+ abstract: '使用貨幣格式將數字轉換為文本',links: [{title: '教導',@@ -151,8 +145,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是一個數字、一個含有數字之儲存格的參照,或一個評估為數字的公式。' },+ decimals: { name: '小數位數', detail: '這是小數點右邊的小數位數。 如果這是負數,則會將數位四捨五入到小數點的左邊。 如果您省略 decimals,則假設為 2。' },},},EXACT: {@@ -165,8 +159,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text1: { name: '文字1', detail: '這是第一個文字字串。' },+ text2: { name: '文字2', detail: '這是第二個文字字串。' },},},FIND: {@@ -207,8 +201,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要四捨五入並轉換為文字的數字。' },+ decimals: { name: '小數位數', detail: '這是小數點右邊的小數位數。 如果這是負數,則會將數位四捨五入到小數點的左邊。 如果您省略 decimals,則假設為 2。' },+ noCommas: { name: '禁用分隔符', detail: '這是邏輯值,如果為 TRUE,會阻止 FIXED 在傳回的文字中包含逗號。' },},},LEFT: {@@ -319,8 +314,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '要轉換成數位的文字。' },+ decimalSeparator: { name: '小數分隔符', detail: '用來分隔結果整數和小數部分的字元。' },+ groupSeparator: { name: '群組分隔符', detail: '用來分隔數位群組的字元。' },},},PHONETIC: {@@ -347,8 +343,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是以引號括住的文字、傳回文字的公式,或包含要將部分變為大寫之文字的儲存格參照。' },},},REGEXEXTRACT: {@@ -446,8 +441,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是包含您想擷取之字元的文字字串。' },+ numChars: { name: '字元數', detail: '這會指定您要 RIGHT 擷取的字元數目。' },},},RIGHTB: {@@ -460,8 +455,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是包含您想擷取之字元的文字字串。' },+ numBytes: { name: '字節數', detail: '這會指定要 RIGHTB 擷取的字元數目,以位元組為單位。' },},},SEARCH: {@@ -502,8 +497,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '這是包含要以字元取代文字的文字或參照。' },+ oldText: { name: '搜尋文字', detail: '這是要取代的文字。' },+ newText: { name: '取代文字', detail: '這是要用來取代 old_text 的文字。' },+ instanceNum: { name: '指定取代對象', detail: '指定要將第幾個 old_text 取代為 new_text。 如果您指定 instance_num,則只會取代該 old_text。 否則,text 中的每一個 old_text 都會變更為 new_text。' },},},T: {@@ -516,8 +513,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: '值', detail: '這是要檢定的值。' },},},TEXT: {@@ -626,8 +622,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '是代表字元的 Unicode 數位。' },},},UNICODE: {@@ -640,8 +635,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '是您要使用 Unicode 值的字元。' },},},UPPER: {@@ -668,8 +662,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字', detail: '以引號括住的文字或包含要轉換之文字的儲存格參照。' },},},VALUETOTEXT: {@@ -682,8 +675,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ value: { name: '值', detail: '要以文字格式返回的值。' },+ format: { name: '資料格式', detail: '傳回資料的格式。它可以是兩個值的其中之一:\n0 預設。 易於閱讀的精簡格式。\n1 包含逸出字元和列分隔符號的限定格式。 產生可在輸入至資料編輯列時進行剖析的字串。 封裝會以引號傳回字串,除了布林值、數字和錯誤以外。' },},},CALL: {diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.tsindex 75f9f2749e..6b6ca9a261 100644--- a/packages/sheets-formula/src/services/function-list/math.ts+++ b/packages/sheets-formula/src/services/function-list/math.ts@@ -122,16 +122,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.ARABIC.abstract',functionParameter: [{- name: 'formula.functionList.ARABIC.functionParameter.number1.name',- detail: 'formula.functionList.ARABIC.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.ARABIC.functionParameter.number2.name',- detail: 'formula.functionList.ARABIC.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.ARABIC.functionParameter.text.name',+ detail: 'formula.functionList.ARABIC.functionParameter.text.detail',+ example: '"LVII"',require: 1,repeat: 0,},@@ -1097,17 +1090,17 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.ROMAN.abstract',functionParameter: [{- name: 'formula.functionList.ROMAN.functionParameter.number1.name',- detail: 'formula.functionList.ROMAN.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.ROMAN.functionParameter.number.name',+ detail: 'formula.functionList.ROMAN.functionParameter.number.detail',+ example: '499',require: 1,repeat: 0,},{- name: 'formula.functionList.ROMAN.functionParameter.number2.name',- detail: 'formula.functionList.ROMAN.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.ROMAN.functionParameter.form.name',+ detail: 'formula.functionList.ROMAN.functionParameter.form.detail',+ example: '0',+ require: 0,repeat: 0,},],diff --git a/packages/sheets-formula/src/services/function-list/text.ts b/packages/sheets-formula/src/services/function-list/text.tsindex d10c3f1f2a..5d00bb92e9 100644--- a/packages/sheets-formula/src/services/function-list/text.ts+++ b/packages/sheets-formula/src/services/function-list/text.ts@@ -24,16 +24,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.ASC.abstract',functionParameter: [{- name: 'formula.functionList.ASC.functionParameter.number1.name',- detail: 'formula.functionList.ASC.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.ASC.functionParameter.number2.name',- detail: 'formula.functionList.ASC.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.ASC.functionParameter.text.name',+ detail: 'formula.functionList.ASC.functionParameter.text.detail',+ example: '"Univer"',require: 1,repeat: 0,},@@ -46,17 +39,17 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.ARRAYTOTEXT.abstract',functionParameter: [{- name: 'formula.functionList.ARRAYTOTEXT.functionParameter.number1.name',- detail: 'formula.functionList.ARRAYTOTEXT.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.ARRAYTOTEXT.functionParameter.array.name',+ detail: 'formula.functionList.ARRAYTOTEXT.functionParameter.array.detail',+ example: 'A2:B4',require: 1,repeat: 0,},{- name: 'formula.functionList.ARRAYTOTEXT.functionParameter.number2.name',- detail: 'formula.functionList.ARRAYTOTEXT.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.ARRAYTOTEXT.functionParameter.format.name',+ detail: 'formula.functionList.ARRAYTOTEXT.functionParameter.format.detail',+ example: '0',+ require: 0,repeat: 0,},],@@ -68,16 +61,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.BAHTTEXT.abstract',functionParameter: [{- name: 'formula.functionList.BAHTTEXT.functionParameter.number1.name',- detail: 'formula.functionList.BAHTTEXT.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.BAHTTEXT.functionParameter.number2.name',- detail: 'formula.functionList.BAHTTEXT.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.BAHTTEXT.functionParameter.number.name',+ detail: 'formula.functionList.BAHTTEXT.functionParameter.number.detail',+ example: '1234',require: 1,repeat: 0,},@@ -90,16 +76,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.CHAR.abstract',functionParameter: [{- name: 'formula.functionList.CHAR.functionParameter.number1.name',- detail: 'formula.functionList.CHAR.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.CHAR.functionParameter.number2.name',- detail: 'formula.functionList.CHAR.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.CHAR.functionParameter.number.name',+ detail: 'formula.functionList.CHAR.functionParameter.number.detail',+ example: '65',require: 1,repeat: 0,},@@ -112,16 +91,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.CLEAN.abstract',functionParameter: [{- name: 'formula.functionList.CLEAN.functionParameter.number1.name',- detail: 'formula.functionList.CLEAN.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.CLEAN.functionParameter.number2.name',- detail: 'formula.functionList.CLEAN.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.CLEAN.functionParameter.text.name',+ detail: 'formula.functionList.CLEAN.functionParameter.text.detail',+ example: 'CHAR(1)&"Univer"',require: 1,repeat: 0,},@@ -134,16 +106,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.CODE.abstract',functionParameter: [{- name: 'formula.functionList.CODE.functionParameter.number1.name',- detail: 'formula.functionList.CODE.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.CODE.functionParameter.number2.name',- detail: 'formula.functionList.CODE.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.CODE.functionParameter.text.name',+ detail: 'formula.functionList.CODE.functionParameter.text.detail',+ example: '"Univer"',require: 1,repeat: 0,},@@ -200,16 +165,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.DBCS.abstract',functionParameter: [{- name: 'formula.functionList.DBCS.functionParameter.number1.name',- detail: 'formula.functionList.DBCS.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.DBCS.functionParameter.number2.name',- detail: 'formula.functionList.DBCS.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.DBCS.functionParameter.text.name',+ detail: 'formula.functionList.DBCS.functionParameter.text.detail',+ example: '"Univer"',require: 1,repeat: 0,},@@ -222,17 +180,17 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.DOLLAR.abstract',functionParameter: [{- name: 'formula.functionList.DOLLAR.functionParameter.number1.name',- detail: 'formula.functionList.DOLLAR.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.DOLLAR.functionParameter.number.name',+ detail: 'formula.functionList.DOLLAR.functionParameter.number.detail',+ example: '1234.567',require: 1,repeat: 0,},{- name: 'formula.functionList.DOLLAR.functionParameter.number2.name',- detail: 'formula.functionList.DOLLAR.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.DOLLAR.functionParameter.decimals.name',+ detail: 'formula.functionList.DOLLAR.functionParameter.decimals.detail',+ example: '2',+ require: 0,repeat: 0,},],@@ -244,16 +202,16 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.EXACT.abstract',functionParameter: [{- name: 'formula.functionList.EXACT.functionParameter.number1.name',- detail: 'formula.functionList.EXACT.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.EXACT.functionParameter.text1.name',+ detail: 'formula.functionList.EXACT.functionParameter.text1.detail',+ example: '"Univer"',require: 1,repeat: 0,},{- name: 'formula.functionList.EXACT.functionParameter.number2.name',- detail: 'formula.functionList.EXACT.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.EXACT.functionParameter.text2.name',+ detail: 'formula.functionList.EXACT.functionParameter.text2.detail',+ example: '"univer"',require: 1,repeat: 0,},@@ -310,17 +268,24 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.FIXED.abstract',functionParameter: [{- name: 'formula.functionList.FIXED.functionParameter.number1.name',- detail: 'formula.functionList.FIXED.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.FIXED.functionParameter.number.name',+ detail: 'formula.functionList.FIXED.functionParameter.number.detail',+ example: '1234.567',require: 1,repeat: 0,},{- name: 'formula.functionList.FIXED.functionParameter.number2.name',- detail: 'formula.functionList.FIXED.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.FIXED.functionParameter.decimals.name',+ detail: 'formula.functionList.FIXED.functionParameter.decimals.detail',+ example: '2',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.FIXED.functionParameter.noCommas.name',+ detail: 'formula.functionList.FIXED.functionParameter.noCommas.detail',+ example: '0',+ require: 0,repeat: 0,},],@@ -472,17 +437,24 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.NUMBERVALUE.abstract',functionParameter: [{- name: 'formula.functionList.NUMBERVALUE.functionParameter.number1.name',- detail: 'formula.functionList.NUMBERVALUE.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.NUMBERVALUE.functionParameter.text.name',+ detail: 'formula.functionList.NUMBERVALUE.functionParameter.text.detail',+ example: '"2.500,27"',require: 1,repeat: 0,},{- name: 'formula.functionList.NUMBERVALUE.functionParameter.number2.name',- detail: 'formula.functionList.NUMBERVALUE.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.NUMBERVALUE.functionParameter.decimalSeparator.name',+ detail: 'formula.functionList.NUMBERVALUE.functionParameter.decimalSeparator.detail',+ example: '","',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.NUMBERVALUE.functionParameter.groupSeparator.name',+ detail: 'formula.functionList.NUMBERVALUE.functionParameter.groupSeparator.detail',+ example: '"."',+ require: 0,repeat: 0,},],@@ -516,16 +488,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.PROPER.abstract',functionParameter: [{- name: 'formula.functionList.PROPER.functionParameter.number1.name',- detail: 'formula.functionList.PROPER.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.PROPER.functionParameter.number2.name',- detail: 'formula.functionList.PROPER.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.PROPER.functionParameter.text.name',+ detail: 'formula.functionList.PROPER.functionParameter.text.detail',+ example: '"hello univer"',require: 1,repeat: 0,},@@ -677,17 +642,17 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.RIGHT.abstract',functionParameter: [{- name: 'formula.functionList.RIGHT.functionParameter.number1.name',- detail: 'formula.functionList.RIGHT.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.RIGHT.functionParameter.text.name',+ detail: 'formula.functionList.RIGHT.functionParameter.text.detail',+ example: '"Univer"',require: 1,repeat: 0,},{- name: 'formula.functionList.RIGHT.functionParameter.number2.name',- detail: 'formula.functionList.RIGHT.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.RIGHT.functionParameter.numChars.name',+ detail: 'formula.functionList.RIGHT.functionParameter.numChars.detail',+ example: '3',+ require: 0,repeat: 0,},],@@ -699,17 +664,17 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.RIGHTB.abstract',functionParameter: [{- name: 'formula.functionList.RIGHTB.functionParameter.number1.name',- detail: 'formula.functionList.RIGHTB.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.RIGHTB.functionParameter.text.name',+ detail: 'formula.functionList.RIGHTB.functionParameter.text.detail',+ example: '"Univer"',require: 1,repeat: 0,},{- name: 'formula.functionList.RIGHTB.functionParameter.number2.name',- detail: 'formula.functionList.RIGHTB.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.RIGHTB.functionParameter.numBytes.name',+ detail: 'formula.functionList.RIGHTB.functionParameter.numBytes.detail',+ example: '3',+ require: 0,repeat: 0,},],@@ -765,19 +730,33 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.SUBSTITUTE.abstract',functionParameter: [{- name: 'formula.functionList.SUBSTITUTE.functionParameter.number1.name',- detail: 'formula.functionList.SUBSTITUTE.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUBSTITUTE.functionParameter.text.name',+ detail: 'formula.functionList.SUBSTITUTE.functionParameter.text.detail',+ example: '"Hello Univer"',require: 1,repeat: 0,},{- name: 'formula.functionList.SUBSTITUTE.functionParameter.number2.name',- detail: 'formula.functionList.SUBSTITUTE.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUBSTITUTE.functionParameter.oldText.name',+ detail: 'formula.functionList.SUBSTITUTE.functionParameter.oldText.detail',+ example: '"Hello"',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.SUBSTITUTE.functionParameter.newText.name',+ detail: 'formula.functionList.SUBSTITUTE.functionParameter.newText.detail',+ example: '"Hi"',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.SUBSTITUTE.functionParameter.instanceNum.name',+ detail: 'formula.functionList.SUBSTITUTE.functionParameter.instanceNum.detail',+ example: '1',+ require: 0,+ repeat: 0,+ },],},{@@ -787,16 +766,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.T.abstract',functionParameter: [{- name: 'formula.functionList.T.functionParameter.number1.name',- detail: 'formula.functionList.T.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.T.functionParameter.number2.name',- detail: 'formula.functionList.T.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.T.functionParameter.value.name',+ detail: 'formula.functionList.T.functionParameter.value.detail',+ example: '"Univer"',require: 1,repeat: 0,},@@ -1025,16 +997,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.UNICHAR.abstract',functionParameter: [{- name: 'formula.functionList.UNICHAR.functionParameter.number1.name',- detail: 'formula.functionList.UNICHAR.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.UNICHAR.functionParameter.number2.name',- detail: 'formula.functionList.UNICHAR.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.UNICHAR.functionParameter.number.name',+ detail: 'formula.functionList.UNICHAR.functionParameter.number.detail',+ example: '65',require: 1,repeat: 0,},@@ -1047,16 +1012,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.UNICODE.abstract',functionParameter: [{- name: 'formula.functionList.UNICODE.functionParameter.number1.name',- detail: 'formula.functionList.UNICODE.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.UNICODE.functionParameter.number2.name',- detail: 'formula.functionList.UNICODE.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.UNICODE.functionParameter.text.name',+ detail: 'formula.functionList.UNICODE.functionParameter.text.detail',+ example: '"Univer"',require: 1,repeat: 0,},@@ -1091,16 +1049,9 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.VALUE.abstract',functionParameter: [{- name: 'formula.functionList.VALUE.functionParameter.number1.name',- detail: 'formula.functionList.VALUE.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.VALUE.functionParameter.number2.name',- detail: 'formula.functionList.VALUE.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.VALUE.functionParameter.text.name',+ detail: 'formula.functionList.VALUE.functionParameter.text.detail',+ example: '"123"',require: 1,repeat: 0,},@@ -1113,17 +1064,17 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.VALUETOTEXT.abstract',functionParameter: [{- name: 'formula.functionList.VALUETOTEXT.functionParameter.number1.name',- detail: 'formula.functionList.VALUETOTEXT.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.VALUETOTEXT.functionParameter.value.name',+ detail: 'formula.functionList.VALUETOTEXT.functionParameter.value.detail',+ example: '"Univer"',require: 1,repeat: 0,},{- name: 'formula.functionList.VALUETOTEXT.functionParameter.number2.name',- detail: 'formula.functionList.VALUETOTEXT.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.VALUETOTEXT.functionParameter.format.name',+ detail: 'formula.functionList.VALUETOTEXT.functionParameter.format.detail',+ example: '1',+ require: 0,repeat: 0,},],