幻灯片标题统一格式
统一设置演示文稿中所有幻灯片标题的格式,包括字体、字号、对齐方式和垂直对齐方式。
(function () {
// 标题格式配置对象
let titleConfig = {
font: "Arial",
fontSize: 100,
justification: "center",
textAlignment: "top",
};
function applyTitleFormatting(paragraph, config) {
paragraph.SetFontFamily(config.font);
paragraph.SetFontSize(config.fontSize);
paragraph.SetJc(config.justification);
}
function formatSlideTitle(slide, config) {
let shapes = slide.GetAllShapes();
if (shapes.length > 0) {
shapes[0].SetVerticalTextAlign(config.textAlignment);
let docContent = shapes[0].GetDocContent();
let paragraphs = docContent.GetAllParagraphs();
if (paragraphs.length > 0) {
applyTitleFormatting(paragraphs[0], config);
}
}
}
function formatTitlesInPresentation() {
let presentation = Api.GetPresentation();
let slideCount = presentation.GetSlidesCount();
for (let i = 0; i < slideCount; i++) {
let slide = presentation.GetSlideByIndex(i);
formatSlideTitle(slide, titleConfig);
}
}
formatTitlesInPresentation();
})();
使用方法: SetFontFamily, SetFontSize, SetJc, GetAllShapes, SetVerticalTextAlign, GetDocContent, GetPresentation, GetSlidesCount, GetSlideByIndex
结果
