To insert two consecutive words in a TextBox in Google Slides with different text styles (such as different colors), you can use the insertText method along with the TextRange class to apply different styles to different parts of the text. Here's how you can do it:
javascriptfunction insertColoredWords() { // Get the presentation const presentation = SlidesApp.getActivePresentation(); // Get the first slide const firstSlide = presentation.getSlides()[0]; // Insert a TextBox const textBox = firstSlide.insertTextBox("first"); // Get the text range of the TextBox const textRange = textBox.getText(); // Insert the first word with the desired style textRange.insertText("first", 0); textRange.getRange(0, 5).getTextStyle().setForegroundColor(255, 0, 0); // Set color to red // Insert the second word with a different style textRange.insertText("second", 5); // Insert after the first word textRange.getRange(5, 11).getTextStyle().setForegroundColor(0, 0, 255); // Set color to blue }
In this code:
getTextStyle() method on the range from index 0 to 5 (exclusive).getTextStyle() method on the range from index 5 to 11 (exclusive).This way, both words will appear consecutively in the TextBox with different text colors. Adjust the colors and other styles as needed.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/9f093f3f-d8c4-40a9-b433-973aa2978fd0n%40googlegroups.com.