跳到主要内容

MID

根据起始位置和长度,返回文本字符串中间的字符。

语法

expression.MID(arg1, arg2, arg3);

expression - 表示 ApiWorksheetFunction 类的变量。

参数

名称必需/可选数据类型默认值描述
arg1必需ApiRange | ApiName | string要从中提取字符的文本字符串。
arg2必需ApiRange | ApiName | number要提取的第一个字符的位置。第一个文本字符是 1。
arg3必需ApiRange | ApiName | number要提取的字符数。

返回值

string

示例

从电子表格中字符串的中间位置开始提取文本。

// What characters can I pull from a text string in a spreadsheet?

// Get a substring from a specific position and length in a spreadsheet.

let worksheet = Api.GetActiveSheet();
let func = Api.WorksheetFunction;
worksheet.GetRange("A1").SetValue(func.MID("Online Office", 3, 4));