跳到主要内容

GetText

返回当前文档内容对象的内部文本。

语法

expression.GetText(options);

expression - 表示 ApiDocumentContent 类的变量。

参数

名称必需/可选数据类型默认值描述
options可选object返回文本的格式选项。
options.Numbering可选booleantrue定义结果字符串是否包含编号。
options.Math可选booleantrue定义结果字符串是否包含数学表达式。
options.TableCellSeparator可选string'\t'定义在结果字符串中如何指定表格单元格分隔符。可以使用任何符号。默认分隔符为 "\t"。
options.TableRowSeparator可选string'\r\n'定义在结果字符串中如何指定表格行分隔符。可以使用任何符号。默认分隔符为 "\r\n"。
options.ParaSeparator可选string'\r\n'定义在结果字符串中如何指定段落分隔符。可以使用任何符号。默认分隔符为 "\r\n"。
options.TabSymbol可选string'\t'定义在结果字符串中如何指定制表符。可以使用任何符号。默认符号为 "\t"。
options.NewLineSeparator可选string'\r'定义在结果字符串中如何指定行分隔符。可以使用任何符号。默认分隔符为 "\r"。

返回值

string

示例

此示例返回文档内容中的文本。

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const fill = Api.CreateSolidFill(Api.HexColor('#E8D5B7'));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('roundRect', Api.MillimetersToEmus(300), Api.MillimetersToEmus(130), fill, stroke);
shape.SetPosition(Api.MillimetersToEmus(20), Api.MillimetersToEmus(35));
const docContent = shape.GetContent();
const paragraph = docContent.GetElement(0);
paragraph.AddText('This is the shape content text.');
const text = docContent.GetText();
const infoParagraph = Api.CreateParagraph();
infoParagraph.AddText('Text from document content: ' + text);
docContent.Push(infoParagraph);
slide.AddObject(shape);