The following code shows how it is done. As in reading the styles, the first run of text is the cell style, and the ones after that are set especially by rts.applyFont.
It's important to create new fonts, though, and not re-use the same one for all runs. As you've discovered, not the font attributes are stored, but the font object itself. So if you use a single font object and change it later, then all styles get changed.
The logic seems straightforward. You'd go through the string left to right, one character at a time. You'd need to keep track of which styles are currently active (e.g. in 3 booleans), and where the current run of text starts. Whenever you encounter a closing tag, you'd append the current run of text to the rich text string, and apply a font based on the booleans to it.
A minor complication would be that you also need to keep track of whether the current run is the first run, in which case you'd change the cell style font instead of applying a font to the rich text string.
Didn't you like the approach I outlined before? It seems that it would need a lot fewer lines of code, and also be more stable (e.g. if there was whitespace between the HTML tags).
Originally posted by Ulf Dittmer: Didn't you like the approach I outlined before? It seems that it would need a lot fewer lines of code, and also be more stable (e.g. if there was whitespace between the HTML tags).