To display text in a FormattedTextView or a FormattedTextEdit, you have to provide the content that you want to display as type FormattedText. For the FormattedTextView, you can set the content to be displayed by choosing . For a string to be converted into FormattedText, it must contain a well-formed and valid XML document.
To create this type, use the WDFormattedTextFactory.
The WDFormattedTextFactory provides two methods to create a FormattedText from a string:
Use this method to create FormattedTextfrom a markup language-formatted string.
Use this method to create FormattedText from plain text. The following escape sequences will be ignored.
\b |
backspace |
\n |
newline |
\f |
formfeed |
\r |
carriage return |
\t |
horizontal tabulator |
wdDoInit() |
---|
String htmlText = "<strong>hello I'm bold!</strong>"; IWDFormattedText formattedText = WDFormattedTextFactory.valueOf(htmlText); wdContext.currentContextElement().setText(formattedText); |
The following screenshot illustrates the result: