I want to insert some C/C++ source code into a Microsoft Word document. I have no problem in copying the code from source file and pasting into Word. I can do fixed-width. But, in Word, I see the code in black-and-white format; I loose the syntax highlighting as I get in the source code editor (for me, gvim). So, my question is, is there any way to do syntax highlighting of C/C++ source code in MS Word?
问题:
回答1:
I found Notepad++ also can copy the code as .rtf file. Plugin/NppExport/Copy RTF to Clipboard, Then you can paste them into word with highlight and layout.
回答2:
I've found a tool similar to this found by darlinton, but having several different styles of colouring: http://tohtml.com/. I hope it would help.
回答3:
You can leverage the syntax highlighter that is in use at StackOverflow. I mean the text area where you add the content to be posted to the site :)
But for a more robust and configurable solution you could check out the syntax highlighter developed by Alex Gorbatchov (link). But well, installing it requires some knowledge of HTML and CSS. So, if I needed a quick solution to format my output, I would opt for planet.ca, as darlinton and ArunSaha.
回答4:
If you don't mind using a different editor for this job, you could load your code into SciTE, use the Edit / Copy as RTF command, and then paste into Word.
回答5:
If you have Eclipse CDT or Visual around they do it automatically for you when you paste code to Word (Or similiar). I assume it's not best solution for a gvim guy, but still. Just so you'll know.
回答6:
After some more searching, I also found Highlight 2.9. But that requires (a) installing an application, and (b) [subjective] aesthetically I like the output of planetb.ca 's output (the answer provided by darlinton)
回答7:
Under Linux, you can use the popular highlight package. It can output RTF file. You can copy-paste the result in Word or LibreOffice.