跳到主要内容

REPT

将文本重复指定的次数。使用此函数用文本字符串的多个实例填充单元格。

语法

expression.REPT(arg1, arg2);

expression - 表示 ApiWorksheetFunction 类的变量。

参数

名称必需/可选数据类型默认值描述
arg1必需ApiRange | ApiName | string将被重复的文本。
arg2必需ApiRange | ApiName | number指定重复文本次数的正数。

返回值

string

示例

在电子表格中将文本重复指定次数。使用此函数用多个文本字符串实例填充单元格。

// How to create an indicated number of copies in a spreadsheet.

// Use a function to repeat a text n times in a spreadsheet.

let worksheet = Api.GetActiveSheet();
let func = Api.WorksheetFunction;
worksheet.GetRange("A1").SetValue(func.REPT("Text", 3));