GetText
返回范围的文本内容。段落分隔符表示为 "\r"。
语法
expression.GetText(options);
expression - 表示 ApiTextRange 类的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 默认值 | 描述 |
|---|---|---|---|---|
| options | 可选 | object | 返回文本的格式选项。 | |
| options.Math | 可选 | boolean | true | 定义结果字符串是否包含数学表达式。 |
| options.NewLineSeparator | 可选 | string | '\r' | 定义在结果字符串中如何指定行分隔符。可以使用任何符号。默认分隔符为 “\r”。 |
| options.TableCellSeparator | 可选 | string | '\t' | 定义在结果字符串中如何指定表格单元格分隔符。可以使用任何符号。默认分隔符为 “\t”。 |
| options.TableRowSeparator | 可选 | string | '\r\n' | 定义在结果字符串中如何指定表格行分隔符。可以使用任何符号。默认分隔符为 “\r\n”。 |
| options.ParaSeparator | 可选 | string | '\r\n' | 定义在结果字符串中如何指定段落分隔符。可以使用任何符号。默认分隔符为 “\r\n”。 |
| options.TabSymbol | 可选 | string | '\t' | 定义在结果字符串中如何指定制表符(不适用于编号)。可以使用任何符号。默认符号为 “\t”。 |
返回值
string
示例
获取范围的文本内容并将其显示在第二个形状中。
// Useful for reading the text covered by a range without modifying it.
// Retrieve the text content of the range and show it on the slide.
const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();
const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("rect", 300 * 36000, 130 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
const docContent = shape.GetDocContent();
const paragraph = docContent.GetElement(0);
paragraph.AddText("Hello World");
slide.AddObject(shape);
const range = shape.GetTextRange();
const text = range.GetText();
const fill2 = Api.CreateSolidFill(Api.RGB(200, 230, 255));
const shape2 = Api.CreateShape("rect", 300 * 36000, 80 * 36000, fill2, stroke);
shape2.SetPosition(608400, 6000000);
const content2 = shape2.GetDocContent();
content2.GetElement(0).AddText("GetText result: " + JSON.stringify(text));
slide.AddObject(shape2);