跳到主要内容

LEFT

从文本字符串的开头返回指定数量的字符。

语法

expression.LEFT(arg1, arg2);

expression - 表示 ApiWorksheetFunction 类的变量。

参数

名称必需/可选数据类型默认值描述
arg1必需ApiRange | ApiName | string包含要提取字符的文本字符串。
arg2可选ApiRange | ApiName | number子字符串的字符数。必须大于或等于 0。

返回值

string

示例

从电子表格中文本的开头提取字符。

// How do I get the first few letters or a prefix from a text string in a spreadsheet?

// Retrieve a specific number of characters counting from the left side of text in a spreadsheet.

let worksheet = Api.GetActiveSheet();
let func = Api.WorksheetFunction;
worksheet.GetRange("A1").SetValue(func.LEFT("Online Office", 6));