I would like to know if it is possible in the current sheets api, or the google script for sheets, to find and replace rich text.
In my specific example, I have red text that I would like to remove in another cell.
The purpose of this is to create many results with different outputs. My example would be scaled to possibly hundreds of cells. and it would be nice to set different styles in a source cell to output different results in the ~100 cells.
I have looked in the text element api references, and it seems to only apply to documents, and not the sheets cells. and my attempts to script using those methods have failed.
Best Answer
The following isn't an answer to your question per se, but it is an exploration of the syntax surrounding TextStyle and RichTextValue. It may assist in understanding why
var x = A1.getRuns();
doesn't work, and how you might build code to analyse cells. Note the programmatic creation of RichText is another thing altogether.Spreadsheet Screenshot
Logger - Results
DEBUG: Cell content = black red blue black
i=0, Start Idx:0, End Idx:5, Text:black, Bold?: false, Color:#000000, Font:Calibri, Size:14, Italic?:: true, Strikethru?:false, Underline?:false
i=1, Start Idx:5, End Idx:6, Text: , Bold?: true, Color:#000000, Font:Open Sans, Size:10, Italic?:: false, Strikethru?:false, Underline?:false
i=2, Start Idx:6, End Idx:9, Text:red, Bold?: true, Color:#ff0000, Font:Comic Sans MS, Size:18, Italic?:: false, Strikethru?:false, Underline?:false
i=3, Start Idx:9, End Idx:10, Text: , Bold?: true, Color:#000000, Font:Open Sans, Size:10, Italic?:: false, Strikethru?:false, Underline?:false
i=4, Start Idx:10, End Idx:14, Text:blue, Bold?: false, Color:#4a86e8, Font:Roboto, Size:14, Italic?:: false, Strikethru?:true, Underline?:false
i=5, Start Idx:14, End Idx:15, Text: , Bold?: true, Color:#000000, Font:Open Sans, Size:10, Italic?:: false, Strikethru?:false, Underline?:false
i=6, Start Idx:15, End Idx:20, Text:black, Bold?: false, Color:#b6d7a8, Font:Trebuchet MS, Size:18, Italic?:: true, Strikethru?:false, Underline?:false