问题
In my application you can copy data to the clipboard. The data is copied to the clipboard in HTML format so that format information is preserved when pasting to other applications that can handle HTML data from the clipboard (e.g. WinWord).
Example (4 words, the last 2 bold):
This is bold text
Result: The text is correctly pasted in WinWord and the format (bold) is preserved.
Example (5 spaces):
Result: Nothing is pasted in WinWord.
Question: How can I achieve that WinWord preserves the spaces in the second example?
I tried encoding them as but then WinWord shows them as a circle when paragraph marks are activated. And that looks kind of ugly.
解决方法
I solved this by adding the CSS value white-space:pre to the tags.
While white-space:pre-wrap seems to be the correct value, it is ignored by WinWord.
UPDATE:
I also analysed how WinWord creates its clipboard data. The HTML of several spaces looks like this:
Note:
The spaces are located in a separate tag with the style-attribute containing a custom key/value pair mso-spacerun:yes.
The HTML is UTF-8 encoded and the char code of the spaces is U+00A0 (no break space).