跳到主要内容

Format slide titles

Formats the title of each slide in a presentation. It sets the font, font size, justification, and vertical text alignment for the title.

(function () {
// Configuration object for title formatting
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();
})();

Methods used: SetFontFamily, SetFontSize, SetJc, GetAllShapes, SetVerticalTextAlign, GetDocContent, GetPresentation, GetSlidesCount, GetSlideByIndex

Result

FormatSlideTitles FormatSlideTitles