Created
November 3, 2019 10:01
-
-
Save dsottimano/20a50daded2128b4c86acb430cecba67 to your computer and use it in GitHub Desktop.
Google slides - change font for every slide using apps script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//script adapted by @dsottimano | |
//original from: https://stackoverflow.com/questions/52569689/clear-text-formatting-in-slides-using-apps-script | |
//credit to https://stackoverflow.com/users/7108653/tanaike | |
function onOpen() { | |
SlidesApp.getUi() | |
.createMenu('Custom Menu') | |
.addItem('Change Master Font', 'changeFont') | |
.addToUi(); | |
} | |
function getFont() { | |
var ui = SlidesApp.getUi(); | |
var result = ui.prompt( | |
'Replace all fonts', | |
'Please enter the exact name of the font you want to use on every slide:', | |
ui.ButtonSet.OK_CANCEL); | |
if (result.getSelectedButton() == ui.Button.OK) { | |
return result.getResponseText(); | |
} else { | |
return false | |
} | |
} | |
function toDefault(text,font) { | |
if (text.getRange(0,1).asString().charCodeAt(0) != 10) { | |
var style = text.getTextStyle(); | |
return style.setFontFamily(font); | |
} | |
return null; | |
} | |
function changeFont() { | |
var font = getFont(); | |
var slideDeck = SlidesApp.getActivePresentation(); | |
var pageElements = []; | |
var slide = slideDeck.getSlides().forEach(function(s) { | |
pageElements.push(s.getPageElements()); | |
}) | |
pageElements = pageElements.flat(Infinity); | |
pageElements.forEach(function(e) { | |
if (e.getPageElementType() == "SHAPE") { | |
var text = e.asShape().getText(); | |
toDefault(text,font); | |
} else if (e.getPageElementType() == "TABLE") { | |
var table = e.asTable(); | |
for (var row = 0; row < table.getNumRows(); row++) { | |
for (var col = 0; col < table.getNumColumns(); col++) { | |
var text = table.getCell(row, col).getText(); | |
toDefault(text,font); | |
} | |
} | |
} | |
}); | |
} | |
Array.prototype.flat || Object.defineProperty(Array.prototype, "flat", { | |
configurable: !0, | |
value: function r() { | |
var t = isNaN(arguments[0]) ? 1 : Number(arguments[0]); | |
return t ? Array.prototype.reduce.call(this, function (a, e) { | |
return Array.isArray(e) ? a.push.apply(a, r.call(e, t - 1)) : a.push(e), a | |
}, []) : Array.prototype.slice.call(this) | |
}, | |
writable: !0 | |
}), Array.prototype.flatMap || Object.defineProperty(Array.prototype, "flatMap", { | |
configurable: !0, | |
value: function (r) { | |
return Array.prototype.map.apply(this, arguments).flat() | |
}, | |
writable: !0 | |
}) |
Author
dsottimano
commented
Dec 14, 2021
via email
Interesting, do you have the fix?
ᐧ
…On Tue, Dec 14, 2021 at 6:00 AM tpetrzilkaCD ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
the script works but has a limit - merged table cells in slides raise
script exception = font in following slides is not updated
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/20a50daded2128b4c86acb430cecba67#gistcomment-3995081>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA3WPDIKEN7XUYT6SUEYEQDUQ4WWTANCNFSM5KAWG4AQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
*David Sottimano*
Independent Marketing Consultant
https://www.davidsottimano.com
***@***.***
see adjusted code (error handling for merged cells)> https://gist.github.com/tpetrzilkaCD/c2c990138d8924e22398da826cbaa910
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment