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 function mid (#3417)
Dushusir32fb95e5cded
diff --git a/packages/engine-formula/src/functions/text/function-map.ts b/packages/engine-formula/src/functions/text/function-map.tsindex d7f9281277..d5d0e33f28 100644--- a/packages/engine-formula/src/functions/text/function-map.ts+++ b/packages/engine-formula/src/functions/text/function-map.ts@@ -21,6 +21,7 @@ import { Leftb } from './leftb';import { Len } from './len';import { Lenb } from './lenb';import { Lower } from './lower';+import { Mid } from './mid';import { Rept } from './rept';import { Text } from './text';import { Textafter } from './textafter';@@ -33,6 +34,7 @@ export const functionText = [[Len, FUNCTION_NAMES_TEXT.LEN],[Lenb, FUNCTION_NAMES_TEXT.LENB],[Lower, FUNCTION_NAMES_TEXT.LOWER],+ [Mid, FUNCTION_NAMES_TEXT.MID],[Rept, FUNCTION_NAMES_TEXT.REPT],[Text, FUNCTION_NAMES_TEXT.TEXT],[Textafter, FUNCTION_NAMES_TEXT.TEXTAFTER],diff --git a/packages/engine-formula/src/functions/text/mid/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/mid/__test__/index.spec.tsnew file mode 100644index 0000000000..2036d660d6--- /dev/null+++ b/packages/engine-formula/src/functions/text/mid/__test__/index.spec.ts@@ -0,0 +1,203 @@+/**+ * 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, 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_TEXT } from '../../function-names';+import { Mid } from '../index';++describe('Test mid function', () => {+ const midFunction = new Mid(FUNCTION_NAMES_TEXT.MID);++ describe('Mid', () => {+ it('Extract substring from single cell', () => {+ const withinText = StringValueObject.create('Hello Univer');+ const startNum = NumberValueObject.create(7);+ const numChars = NumberValueObject.create(6);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([['Univer']]);+ });++ it('Extract substring with start position beyond string length', () => {+ const withinText = StringValueObject.create('Hello');+ const startNum = NumberValueObject.create(10);+ const numChars = NumberValueObject.create(5);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([['']]);+ });++ it('Extract substring with blank cell', () => {+ const withinText = NullValueObject.create();+ const startNum = NumberValueObject.create(7);+ const numChars = NumberValueObject.create(8);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([['']]);+ });++ it('Extract substring with boolean', () => {+ const withinText = BooleanValueObject.create(true);+ const startNum = NumberValueObject.create(2);+ const numChars = NumberValueObject.create(1);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([['R']]);+ });++ it('Extract substring with number', () => {+ const withinText = NumberValueObject.create(12345);+ const startNum = NumberValueObject.create(2);+ const numChars = NumberValueObject.create(2);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([['23']]);+ });++ it('Extract substring with error', () => {+ const withinText = ErrorValueObject.create(ErrorType.NAME);+ const startNum = NumberValueObject.create(2);+ const numChars = NumberValueObject.create(2);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Extract substring with numChars exceeding string length', () => {+ const withinText = StringValueObject.create('Hello');+ const startNum = NumberValueObject.create(1);+ const numChars = NumberValueObject.create(10);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([['Hello']]);+ });++ it('Extract substring in array', () => {+ const withinText = new ArrayValueObject({+ calculateValueList: transformToValueObject([+ ['Hello Univer'],+ ['Hello World'],+ ['This is a Test'],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const startNum = new ArrayValueObject({+ calculateValueList: transformToValueObject([+ [7],+ [7],+ [6],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numChars = new ArrayValueObject({+ calculateValueList: transformToValueObject([+ [5],+ [5],+ [5],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ ['Unive'],+ ['World'],+ ['is a '],+ ]);+ });++ it('Extract substring with array start positions and lengths', () => {+ const withinText = new ArrayValueObject({+ calculateValueList: transformToValueObject([[1, ' ', 1.23, true, false, null, 0, '100', '2.34', 'test', -3, ErrorType.NAME]]),+ rowCount: 1,+ columnCount: 12,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const startNum = new ArrayValueObject({+ calculateValueList: transformToValueObject([+ [1],+ [' '],+ [1.23],+ [true],+ [false],+ [null],+ [0],+ ['100'],+ ['2.34'],+ ['test'],+ [-3],+ [ErrorType.NAME],+ ]),+ rowCount: 12,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numChars = NumberValueObject.create(1);+ const result = midFunction.calculate(withinText, startNum, numChars);+ 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.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.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], ['', '', '.', 'R', 'A', '', '', '0', '.', 'e', '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]]);+ });++ it('Extract substring with emoji', () => {+ const withinText = StringValueObject.create('Hello😊World');+ const startNum = NumberValueObject.create(6);+ const numChars = NumberValueObject.create(2);+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([['😊']]);+ });++ it('Extract substring with invalid start position', () => {+ const withinText = StringValueObject.create('Hello World');+ const startNum = new ArrayValueObject({+ calculateValueList: transformToValueObject([[-1, 0, 0.5, 1]]),+ rowCount: 1,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numChars = new ArrayValueObject({+ calculateValueList: transformToValueObject([[-1], [0], [0.5], [1]]),+ rowCount: 4,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = midFunction.calculate(withinText, startNum, numChars);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([[ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE], [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ''], [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ''], [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, 'H']]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/text/mid/index.ts b/packages/engine-formula/src/functions/text/mid/index.tsnew file mode 100644index 0000000000..c1edc0df12--- /dev/null+++ b/packages/engine-formula/src/functions/text/mid/index.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 { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NullValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';++export class Mid extends BaseFunction {+ override minParams = 3;++ override maxParams = 3;++ override calculate(withinText: BaseValueObject, startNum: BaseValueObject, numChars: BaseValueObject) {+ if (withinText.isError()) {+ return withinText;+ }++ if (startNum.isError()) {+ return startNum;+ }++ if (numChars.isError()) {+ return numChars;+ }++ // get max row length+ const maxRowLength = Math.max(+ withinText.isArray() ? (withinText as ArrayValueObject).getRowCount() : 1,+ startNum.isArray() ? (startNum as ArrayValueObject).getRowCount() : 1,+ numChars.isArray() ? (numChars as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ withinText.isArray() ? (withinText as ArrayValueObject).getColumnCount() : 1,+ startNum.isArray() ? (startNum as ArrayValueObject).getColumnCount() : 1,+ numChars.isArray() ? (numChars as ArrayValueObject).getColumnCount() : 1+ );++ const withinTextArray = expandArrayValueObject(maxRowLength, maxColumnLength, withinText);+ const startNumArray = expandArrayValueObject(maxRowLength, maxColumnLength, startNum);+ const numCharsArray = expandArrayValueObject(maxRowLength, maxColumnLength, numChars);++ return withinTextArray.map((withinTextValue, rowIndex, columnIndex) => {+ return this._handleSingleText(withinTextValue, rowIndex, columnIndex, startNumArray, numCharsArray);+ });+ }++ private _handleSingleText(withinTextValue: BaseValueObject, rowIndex: number, columnIndex: number, startNumArray: ArrayValueObject, numCharsArray: ArrayValueObject) {+ let startNumValue = startNumArray.get(rowIndex, columnIndex) || NullValueObject.create();+ let numCharsValue = numCharsArray.get(rowIndex, columnIndex) || NullValueObject.create();++ if (startNumValue.isError()) {+ return startNumValue;+ }++ if (numCharsValue.isError()) {+ return numCharsValue;+ }++ let withinTextValueString = withinTextValue.getValue();++ if (withinTextValue.isNull()) {+ withinTextValueString = '';+ }++ if (withinTextValue.isBoolean()) {+ withinTextValueString = withinTextValueString ? 'TRUE' : 'FALSE';+ }++ withinTextValueString = `${withinTextValueString}`;++ if (startNumValue.isString() || startNumValue.isBoolean() || startNumValue.isNull()) {+ startNumValue = startNumValue.convertToNumberObjectValue();+ }++ if (startNumValue.isError()) {+ return startNumValue;+ }++ if (numCharsValue.isString() || numCharsValue.isBoolean() || numCharsValue.isNull()) {+ numCharsValue = numCharsValue.convertToNumberObjectValue();+ }++ if (numCharsValue.isError()) {+ return numCharsValue;+ }++ const startNumValueNumber = Math.floor(+startNumValue.getValue()) - 1;+ const numCharsValueNumber = numCharsValue.getValue() as number;++ if (startNumValueNumber < 0 || numCharsValueNumber < 0) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return StringValueObject.create(withinTextValueString.substring(startNumValueNumber, startNumValueNumber + numCharsValueNumber));+ }+}+diff --git a/packages/engine-formula/src/functions/text/text/__test__/index.spec.ts b/packages/engine-formula/src/functions/text/text/__test__/index.spec.tsindex e7b03e4504..293edded8c 100644--- a/packages/engine-formula/src/functions/text/text/__test__/index.spec.ts+++ b/packages/engine-formula/src/functions/text/text/__test__/index.spec.ts@@ -16,10 +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 { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';import { FUNCTION_NAMES_TEXT } from '../../function-names';import { Text } from '../index';-import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';-import { transformToValue } from '../../../../engine/value-object/array-value-object';describe('Test text function', () => {const testFunction = new Text(FUNCTION_NAMES_TEXT.TEXT);@@ -32,5 +33,49 @@ describe('Test text function', () => {const resultArray = result.getArrayValue();expect(transformToValue(resultArray)).toStrictEqual([['$111.00']]);});++ it('Text is single cell, format text number string', () => {+ const text1 = StringValueObject.create('12345');+ const formatText = StringValueObject.create('0000年00月00日');+ const result = testFunction.calculate(text1, formatText);+ const resultArray = result.getArrayValue();+ expect(transformToValue(resultArray)).toStrictEqual([['0001年23月45日']]);+ });++ it('Text is array, format text is array', () => {+ const text1 = new ArrayValueObject({+ calculateValueList: transformToValueObject([[1, ' ', 1.23, true, false, null, 0, '100', '2.34', 'test', -3, ErrorType.NAME]]),+ rowCount: 1,+ columnCount: 12,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const formatText = new ArrayValueObject({+ calculateValueList: transformToValueObject([+ [1],+ ['YYYY-MM-DD'],+ [true],+ [false],+ [null],+ [0],+ ['100'],+ ['test'],+ [-3],+ [ErrorType.NAME],+ ]),+ rowCount: 10,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(text1, formatText);+ const resultArray = result.getArrayValue();+ // =TEXT(-3,"test") => t18990t, match Google Sheets+ expect(transformToValue(resultArray)).toStrictEqual([['1', ' ', '1', true, false, '1', '1', '1', '1', 'test', '-1', ErrorType.NAME], ['1900-01-01', ' ', '1900-01-01', true, false, '1900-01-00', '1900-01-00', '1900-04-09', '1900-01-02', 'test', '1899-12-27', 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], ['', ' ', '', true, false, '', '', '', '', 'test', '-', ErrorType.NAME], ['1', ' ', '1', true, false, '0', '0', '100', '2', 'test', '-3', ErrorType.NAME], ['101', ' ', '101', true, false, '100', '100', '1100', '102', 'test', '-103', ErrorType.NAME], ['t19000t', ' ', 't190012t', true, false, 't19000t', 't19000t', 't19000t', 't190036t', 'test', 't18990t', ErrorType.NAME], ['-3', ' ', '-3', true, false, '-3', '-3', '-3', '-3', 'test', '--3', 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/text/index.ts b/packages/engine-formula/src/functions/text/text/index.tsindex 54c6b79042..600b101bb9 100644--- a/packages/engine-formula/src/functions/text/text/index.ts+++ b/packages/engine-formula/src/functions/text/text/index.ts@@ -14,13 +14,14 @@* limitations under the License.*/+import { isRealNum } from '@univerjs/core';import { ErrorType } from '../../../basics/error-type';import { getFormatPreview } from '../../../basics/format';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';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';export class Text extends BaseFunction {override minParams = 2;@@ -52,7 +53,7 @@ export class Text extends BaseFunction {const formatTextArray = expandArrayValueObject(maxRowLength, maxColumnLength, formatText);return textArray.map((textValue, rowIndex, columnIndex) => {- if (textValue.isError() || textValue.isString() || textValue.isBoolean()) {+ if (textValue.isError()) {return textValue;}@@ -66,21 +67,33 @@ export class Text extends BaseFunction {return ErrorValueObject.create(ErrorType.VALUE);}- if (formatTextValue.isNull()) {- formatTextValue = StringValueObject.create(' ');+ if (textValue.isBoolean()) {+ return textValue;}- const formatTextValueString = `${formatTextValue.getValue()}`;-let textValueNumber = textValue.getValue() as number;if (textValue.isNull()) {textValueNumber = 0;}+ if (textValue.isString()) {+ if (!isRealNum(textValueNumber)) {+ return textValue;+ }++ textValueNumber = Number(textValueNumber);+ }++ if (formatTextValue.isNull()) {+ formatTextValue = StringValueObject.create(' ');+ }++ const formatTextValueString = `${formatTextValue.getValue()}`;+const previewText = getFormatPreview(formatTextValueString, textValueNumber);- return StringValueObject.create(previewText);+ return StringValueObject.create(formatTextValueString === ' ' ? previewText.trimEnd() : previewText);});}}diff --git a/packages/sheets-formula/src/locale/function-list/text/en-US.ts b/packages/sheets-formula/src/locale/function-list/text/en-US.tsindex bfd56f8d1d..0e50467f46 100644--- a/packages/sheets-formula/src/locale/function-list/text/en-US.ts+++ b/packages/sheets-formula/src/locale/function-list/text/en-US.ts@@ -282,7 +282,7 @@ export default {},},MID: {- description: 'Returns a specific number of characters from a text string starting at the position you specify',+ description: 'Returns a specific number of characters from a text string starting at the position you specify.',abstract: 'Returns a specific number of characters from a text string starting at the position you specify',links: [{@@ -291,8 +291,9 @@ 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.' },+ startNum: { name: 'start_num', detail: 'The position of the first character you want to extract in text. The first character in text has start_num 1, and so on.\nIf start_num is greater than the length of text, MID/MIDB returns "" (empty text).\nIf start_num is less than the length of text, but start_num plus num_chars exceeds the length of text, MID/MIDB returns the characters up to the end of text.\nIf start_num is less than 1, MID/MIDB returns the #VALUE! error value.' },+ numChars: { name: 'num_chars', detail: 'Specifies the number of characters you want MID to return from text.\nIf num_chars is negative, MID returns the #VALUE! error value.' },},},MIDB: {diff --git a/packages/sheets-formula/src/locale/function-list/text/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/text/ja-JP.tsindex 2e77d098d9..fcc8db1c79 100644--- a/packages/sheets-formula/src/locale/function-list/text/ja-JP.ts+++ b/packages/sheets-formula/src/locale/function-list/text/ja-JP.ts@@ -284,7 +284,7 @@ export default {},MID: {description: '文字列の任意の位置から指定された文字数の文字を返します。',- abstract: '文字列の任意の位置から指定された文字数の文字を返します。',+ abstract: '文字列の任意の位置から指定された文字数の文字を返します',links: [{title: '指導',@@ -292,8 +292,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '取り出す文字を含む文字列を指定します。' },+ startNum: { name: '開始位置', detail: '文字列から取り出す先頭文字の位置を数値で指定します。 文字列の先頭文字の位置が 1 になります。\nstart_numがテキストの長さより大きい場合、MID/MIDB は "" (空のテキスト) を返します。\nstart_numがテキストの長さより小さいが、start_numとnum_charsがテキストの長さを超える場合、MID/MIDB はテキストの末尾まで文字を返します。\nstart_numが 1 未満の場合、MID/MIDB は #VALUE を返します。 エラー値。' },+ numChars: { name: '文字数', detail: '取り出す文字数を指定します。\n文字数に負の数を指定すると、エラー値 #VALUE! が返されます。' },},},MIDB: {diff --git a/packages/sheets-formula/src/locale/function-list/text/ru-RU.ts b/packages/sheets-formula/src/locale/function-list/text/ru-RU.tsindex 00fa3eef1e..5a4dd25515 100644--- a/packages/sheets-formula/src/locale/function-list/text/ru-RU.ts+++ b/packages/sheets-formula/src/locale/function-list/text/ru-RU.ts@@ -291,8 +291,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'первый' },- number2: { name: 'number2', detail: 'второй' },+ text: { name: 'Текст', detail: 'Текстовая строка, содержащая символы, которые требуется извлечь.' },+ startNum: { name: 'Начальная_позиция', detail: 'Позиция первого знака, извлекаемого из текста. Первый знак в тексте имеет начальную позицию 1 и так далее.\nЕсли start_num больше длины текста, функция MID/MIDB возвращает значение "" (пустой текст).\nЕсли start_num меньше длины текста, но start_num плюс num_chars превышает длину текста, функция MID/MIDB возвращает символы до конца текста.\nЕсли start_num меньше 1, MID/MIDB возвращает #VALUE! (значение ошибки).' },+ numChars: { name: 'Количество_знаков', detail: 'Указывает, сколько знаков должна вернуть функция ПСТР.\nЕсли значение "число_знаков" отрицательно, функция ПСТР возвращает значение ошибки #ЗНАЧ!.' },},},MIDB: {diff --git a/packages/sheets-formula/src/locale/function-list/text/vi-VN.ts b/packages/sheets-formula/src/locale/function-list/text/vi-VN.tsindex 1fdbed7f31..e57e636135 100644--- a/packages/sheets-formula/src/locale/function-list/text/vi-VN.ts+++ b/packages/sheets-formula/src/locale/function-list/text/vi-VN.ts@@ -258,13 +258,13 @@ export default {links: [{title: 'Hướng dẫn',- url: 'https://support.microsoft.com/vi-vn/office/mid-midb-%E5%87%BD%E6%95%B0-52757e16-38f2-4729-872c-657e3a4a7a73',+ url: 'https://support.microsoft.com/vi-vn/office/mid-midb-ha%CC%80m-mid-midb-d5f9e25c-d7d6-472e-b568-4ecb12433028',},],functionParameter: {- text: { name: 'text', detail: 'Chuỗi văn bản có chứa các ký tự mà bạn muốn trích xuất.' },- start_num: { name: 'start_num', detail: 'Vị trí của ký tự đầu tiên bạn muốn trích xuất từ chuỗi văn bản.' },- num_chars: { name: 'num_chars', detail: 'Số lượng ký tự bạn muốn trích xuất từ chuỗi văn bản.' },+ text: { name: 'text', detail: 'Chuỗi văn bản có chứa các ký tự mà bạn muốn trích xuất.' },+ start_num: { name: 'start_num', detail: 'Ví trí của ký tự thứ nhất mà bạn muốn trích xuất trong văn bản. Ký tự thứ nhất trong chuỗi văn bản có số bắt đầu là 1, và v.v.\nNếu start_num văn bản lớn hơn, thì hàm MID/MIDB trả về "" (văn bản trống).\nNếu start_num độ dài văn bản nhỏ hơn nhưng start_num cộng num_chars vượt quá độ dài văn bản, thì hàm MID/MIDB trả về các ký tự đến cuối văn bản.\nNếu start_num nhỏ hơn 1, thì hàm MID/MIDB trả về giá #VALUE! .' },+ 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! .' },},},PHONETIC: {diff --git a/packages/sheets-formula/src/locale/function-list/text/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/text/zh-CN.tsindex 2a74df4209..e11fbd96ed 100644--- a/packages/sheets-formula/src/locale/function-list/text/zh-CN.ts+++ b/packages/sheets-formula/src/locale/function-list/text/zh-CN.ts@@ -291,8 +291,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文本', detail: '包含要提取字符的文本字符串。' },+ startNum: { name: '开始位置', detail: '文本中要提取的第一个字符的位置。 文本中第一个字符的 start_num 为 1,以此类推。\n如果start_num大于文本长度,则 MID/MIDB 将返回“” (空文本) 。\n如果start_num小于文本长度,但start_num加num_chars超过文本长度,则 MID/MIDB 将返回字符到文本末尾。\n如果start_num小于 1,则 MID/MIDB 返回 #VALUE! 。' },+ numChars: { name: '字符数', detail: '指定希望 MID 从文本中返回字符的个数。\n如果num_chars为负数,则 MID 返回 #VALUE! 。' },},},MIDB: {diff --git a/packages/sheets-formula/src/locale/function-list/text/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/text/zh-TW.tsindex 2c8cde1a1b..110300e4fb 100644--- a/packages/sheets-formula/src/locale/function-list/text/zh-TW.ts+++ b/packages/sheets-formula/src/locale/function-list/text/zh-TW.ts@@ -291,8 +291,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: '這是包含您想擷取之字元的文字字串。' },+ startNum: { name: 'start_num', detail: ' 這是要在文字中擷取之第一個字元的位置。 文字中的第一個字元start_num 1,依此類文字。\n如果start_num大於文字的長度,MID/MIDB 會傳回 “” (空白文字) 。\n如果start_num小於文字的長度,但start_num加上num_chars超過文字的長度,MID/MIDB 會傳回文字結尾的字元。\n如果 start_num 小於 1,MID/MIDB 會傳回 #VALUE! 錯誤值。' },+ numChars: { name: 'num_chars', detail: '指定您要 MID 從文字傳回的字元數。\n如果 num_chars 為負數,MID 會傳回 #VALUE! 的錯誤值。' },},},MIDB: {diff --git a/packages/sheets-formula/src/services/function-list/text.ts b/packages/sheets-formula/src/services/function-list/text.tsindex ff96fae5a3..d4feb01a16 100644--- a/packages/sheets-formula/src/services/function-list/text.ts+++ b/packages/sheets-formula/src/services/function-list/text.ts@@ -421,16 +421,23 @@ export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [abstract: 'formula.functionList.MID.abstract',functionParameter: [{- name: 'formula.functionList.MID.functionParameter.number1.name',- detail: 'formula.functionList.MID.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.MID.functionParameter.text.name',+ detail: 'formula.functionList.MID.functionParameter.text.detail',+ example: '"Hello Univer"',require: 1,repeat: 0,},{- name: 'formula.functionList.MID.functionParameter.number2.name',- detail: 'formula.functionList.MID.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.MID.functionParameter.startNum.name',+ detail: 'formula.functionList.MID.functionParameter.startNum.detail',+ example: '1',+ require: 1,+ repeat: 0,+ },+ {+ name: 'formula.functionList.MID.functionParameter.numChars.name',+ detail: 'formula.functionList.MID.functionParameter.numChars.detail',+ example: '1',require: 1,repeat: 0,},