加粗项目符号
自动将包含冒号(:)或破折号(——)的项目符号首单词加粗。
(function () {
let presentation = Api.GetPresentation();
let slides = presentation.GetAllSlides();
slides.forEach(slide => {
let shapes = slide.GetAllShapes();
shapes.forEach(shape => {
let docContent = shape.GetDocContent();
let paragraphs = docContent.GetAllParagraphs();
for (let paragraph of paragraphs) {
let indLeft = paragraph.GetIndLeft();
if (indLeft !== 0) {
let text = paragraph.GetText();
let match = text.match(/^(\s*\S+\s*[:–\-])/);
if (match) {
let boldTextStr = match[1];
let restText = text.substring(boldTextStr.length);
paragraph.RemoveAllElements();
let boldPart = paragraph.AddText(boldTextStr);
boldPart.SetBold(true);
if (restText) paragraph.AddText(restText);
}
}
}
});
});
})();
使用方法:获取演示文稿,获取所有幻灯片,获取所有形状,获取文本内容,获取左缩进,获取元素数量,移除所有元素,添加文本,设置加粗
结果