GetAllParagraphs
从当前文档内容返回所有段落的数组。
语法
expression.GetAllParagraphs();
expression - 表示 ApiDocumentContent 类的变量。
参数
此方法没有任何参数。
返回值
示例
此示例返回文档内容中所有段落的数组。
const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();
const fill = Api.CreateSolidFill(Api.RGB(189, 215, 175));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('rect', Api.MillimetersToEmus(300), Api.MillimetersToEmus(130), fill, stroke);
shape.SetPosition(Api.MillimetersToEmus(20), Api.MillimetersToEmus(35));
const docContent = shape.GetContent();
const paragraph1 = docContent.GetElement(0);
paragraph1.AddText('Paragraph 1');
const paragraph2 = Api.CreateParagraph();
paragraph2.AddText('Paragraph 2');
docContent.Push(paragraph2);
const allParagraphs = docContent.GetAllParagraphs();
allParagraphs[0].SetBold(true);
const infoParagraph = Api.CreateParagraph();
infoParagraph.AddText('Total paragraphs: ' + allParagraphs.length);
docContent.Push(infoParagraph);
slide.AddObject(shape);