diff --git a/CHANGELOG.md b/CHANGELOG.md index dc18d39ab..b89bcd556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - 404 page - legacy version link - macros: added add comments and change cell colors in spreadsheet macro sample +- macros: added change font family and size in presentations macro sample ## 6.1.0 - docspace js sdk: react component diff --git a/site/assets/images/plugins/change-font-family-and-size.dark.png b/site/assets/images/plugins/change-font-family-and-size.dark.png new file mode 100644 index 000000000..25cd57126 Binary files /dev/null and b/site/assets/images/plugins/change-font-family-and-size.dark.png differ diff --git a/site/assets/images/plugins/change-font-family-and-size.png b/site/assets/images/plugins/change-font-family-and-size.png new file mode 100644 index 000000000..cc92fb98e Binary files /dev/null and b/site/assets/images/plugins/change-font-family-and-size.png differ diff --git a/site/pages/Docs/Plugin and Macros/Macros/Samples/Change font family and size/index.md b/site/pages/Docs/Plugin and Macros/Macros/Samples/Change font family and size/index.md new file mode 100644 index 000000000..5386553e0 --- /dev/null +++ b/site/pages/Docs/Plugin and Macros/Macros/Samples/Change font family and size/index.md @@ -0,0 +1,78 @@ +--- +order: +--- + +## Description + +Change font family and size on all slides in your presentation. + + + + + +```ts +(function () { + var oPresentation = Api.GetPresentation(); + for ( + var slideIndex = 0; + slideIndex < oPresentation.GetSlidesCount(); + slideIndex++ + ) { + var oSlide = oPresentation.GetSlideByIndex(slideIndex); + var aShape = oSlide.GetAllShapes(); + + for (var shapeIndex = 0; shapeIndex < aShape.length; shapeIndex++) { + var content = aShape[shapeIndex].GetDocContent(); + // Check if content is valid before proceeding + if (content) { + var count = content.GetElementsCount(); + for (var elementIndex = 0; elementIndex < count; elementIndex++) { + var element = content.GetElement(elementIndex); + // Check if element is valid before using it + if (element) { + element.SetFontSize(10); + element.SetFontFamily("Comic Sans"); + } + } + } + } + } +})(); +``` + +Methods used: GetPresentation, GetSlidesCount, GetSlideByIndex, GetAllShapes, GetDocContent, GetElementsCount, GetElement, SetFontSize, SetFontFamily + +## Reference Microsoft VBA macro code + + + +```vb +Sub ChangeFontOnAllSlides() + Dim slide As slide + Dim shape As shape + + ' Loop through each slide in the presentation + For Each slide In ActivePresentation.Slides + ' Loop through each shape on the slide + For Each shape In slide.Shapes + ' Check if the shape has text + If shape.HasTextFrame Then + If shape.TextFrame.HasText Then + With shape.TextFrame.TextRange + .Font.Name = "Arial" + .Font.Size = 20 + End With + End If + End If + Next shape + Next slide + + MsgBox "Font updated on all slides!", vbInformation +End Sub +``` + +## Result + + + +![Change font family and size](/assets/images/plugins/change-font-family-size.png) diff --git a/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md b/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md index a25f07778..1b137f1fb 100644 --- a/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md +++ b/site/pages/Docs/Plugin and Macros/Macros/Samples/index.md @@ -130,6 +130,10 @@ In this example we are adding comments and changing the background colors of sel [More](Add%20comments%20and%20change%20cell%20colors%20in%20spreadsheet/index.md) +## Change font family and size + +In this example we are changing font family and/or size in the presentation. + ## Support If you want to request a feature or report a bug regarding macros, use the issues section [on GitHub.](https://github.com/ONLYOFFICE/plugin-macros/issues)