Reformat XML Results for Excel
One thing you may notice when you return web service results directly to Excel through an XML map is that mixed content is not automatically formatted. In other words, HTML formatting tags such as <b> and <i> appear as “<b>” and “<i>” rather than as bold and italic, as shown in Figure 24-13.

Figure 24-13. Excel does not automatically interpret HTML formatting
There’s no simple way to prevent this problem, but you can fix it using the automatic text formatting features of Excel. Excel automatically reformats HTML text pasted from the clipboard, so all you have to do is place the data in the clipboard as HTML, then paste that data back into cells on the spreadsheet.
In Excel, you access the clipboard using the DataObject object, so the following code puts the data from each cell of a worksheet into the clipboard as HTML, then pastes that data back, causing Excel to correctly interpret HTML formatting:
Sub TestReformat( )
' Call helper function to interpret HTML formatting codes.
ReformatHTML ActiveSheet.UsedRange
End Sub
Sub ReformatHTML(rng As Range)
Dim clip As New DataObject, cell As Range
For Each cell In rng
clip.SetText "<html>" & cell.Value & "<html>"
clip.PutInClipboard
cell.PasteSpecial
Next
End SubAfter you run TestReformat on a worksheet, Excel interprets the HTML formatting codes as if you cut/pasted them from a web page, as shown in Figure ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access