I'm trying to replace text inside a textbox of a slide while retaining the text formatting of the previous text. Is there a way for this to work using google apps scripts methods?
I tried converting the Google Slide to a PDF then to DOC to get the HTML value so that I can somehow retain the text formatting. While the conversions work, I'm stuck at the part where I have to replace the text within the TextBox while retaining the original text formatting.
So far this is what I have:
function replacePresentationContent(presentationCopyId, slideId, shapeId, content) {
var presentationCopy = SlidesApp.openById(presentationCopyId);
var slidesCopy = presentationCopy.getSlides();
for (var i = 0; i < this.getSlidesCount(presentationCopy); i++) {
var slideCopy = slidesCopy[i];
var slidesCopyId = slideCopy.getObjectId();
var shapesCopy = slideCopy.getShapes();
if (slidesCopyId === slideId) {
for (var j = 0; j < shapesCopy.length; j++) {
if (shapesCopy[j].getObjectId() === shapeId) {
var textRange = shapesCopy[j].getText();
textRange.setText(content);
}
}
}
}
}