跳到主要内容

加粗项目符号

自动将包含冒号(:)或破折号(——)的项目符号首单词加粗

(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);
}
}
}
});
});
})();

使用方法:获取演示文稿获取所有幻灯片获取所有形状获取文本内容获取左缩进获取元素数量移除所有元素添加文本设置加粗

结果

加粗项目符号 加粗项目符号