问题
Say, I have a script nicely formatted in SSMS and it's annotated with all kinds of comments in different languages. But when I copy and paste this nice thingy into Word with syntax highlighted I will get a syntax-highlighted message with those comments garbled, as if reading the source text with one code page and pasting it using another code page. Very nasty kinda bug. Does anyone know how to solve this issue once and for all?
Thank you!
[Update]
[Solution]
Save → Save with Encoding... → Encoding : Unicode (UTF-8 with signature).
[Related forums]
- Need a way to set the default encoding for query files in SMSS. by ChrisMay @Microsoft Connect (Go and upvote this issue at Microsoft Connect)
- SQL Server Management Studio - File Encoding @SqlDev
- SSMS : Option to set default save as encoding for CSV by AaronBertrand @Microsoft Connect
回答1:
After some tests, I'm still unable to reproduce the issue. And I have no idea why copy-pasting text from one Unicode-compatible to another Unicode-compatible app can give such results.
There are several things you can try:
Inside SSMS, save the script as an Unicode file: Save → Save with Encoding... → Encoding : Unicode (UTF-8 with signature). You will then be able to open it probably correctly in Word. The problem is that syntax highlighting will be lost.
Save the script as an Unicode file, than reopen it and copy-paste. Maybe SSMS assume for some reasons that there is some fancy encoding by default, so this will force it to use UTF-8 instead.
Try to paste in different applications (for example the browser). Looking at the first line at your screenshot, I remember once seeing the same problem with some browser renderings described on Wikipedia (can't find the link).
Try copying the same text from Visual Studio (if installed). Copying source code from Visual Studio to Office programs preserve syntax highlighting, so if you observe the same issue, it may come from this syntax highlighting feature.
If nothing works, report the problem to Microsoft Connect, describing precisely the situation so the people at Microsoft will be able to reproduce this issue.
来源:https://stackoverflow.com/questions/3665168/how-to-copy-and-paste-script-text-from-ssms-to-outlook-or-word-without-garbling