Syntax highlighting in Microsoft Office Word

33

15

Possible Duplicate:
How do I easily highlight the syntax of PHP code in Word?

I need to paste some code (ANSI C) in Microsoft Office Word, and I need some form of syntax highlighting (instead of simply changing the font to Lucida Console)

Is there some sort of addon maybe that will let me highlight code syntax in Microsoft Office Word ?

Andreas Grech

Posted 2009-10-26T10:47:46.990

Reputation: 3 522

Question was closed 2010-03-29T07:21:24.883

This is also a duplicate of http://superuser.com/questions/169010/word-syntax-highlighting

– Nathan Fellman – 2010-08-01T07:00:15.310

2

This was asked for PHP, solution is the same: http://superuser.com/questions/39571/how-do-i-easily-highlight-the-syntax-of-php-code-in-word

– T. Kaltnekar – 2009-10-26T11:05:00.823

@T. Kaltnekar: Excellent, exactly what I was looking for! – Andreas Grech – 2009-10-26T11:12:20.200

As a side note: you might want to disable the auto-change option that changes quotes into curly-quotes, and changes double-dashes into en/em-dashes. Otherwise just clicking in the code might actually change it... – Arjan – 2009-10-26T11:56:14.153

Answers

53

Taken from Breakthrough's answer for this question (thanks to T. Kaltnekar's comment)


You can use Notepad++ to accomplish this in three ways. Just so you know, Notepad++ is a more advanced version of Notepad, which supports syntax highlighting of different code files "out of the box" - PHP included!

Download & install it, fire it up, and load up your PHP file. You should automatically see it beautifully coloured (if not, because the file extension is something other than .php, go to Language -> PHP or Language -> P -> PHP).

If you need to change any of the colours, you can easily do so - just go to Settings -> Styler Configurator. From that menu, you can change the various highlighting and font options, to suit your needs - although the default usually suffices for most.

Then, go to Plugins -> NppExport. From there, you have three options you can consider:

  • Export to RTF
  • Export to HTML
  • Copy all formats to clipboard

Start with the last one - "Copy all formats to clipboard" - which will copy the entire file with the highlighted syntax to the clipboard. Once you click it, then open Microsoft Word, and just hit paste! You should see the beautifully syntax-highlighted code. If something goes wrong, then you can try one of the other options (export to RTF/HTML), although I've never had a problem with the clipboard method.

Andreas Grech

Posted 2009-10-26T10:47:46.990

Reputation: 3 522

8Love it! I even mapped this command to 'CTRL+SHIFT+C' keystroke. Makes it so easy to put colored code samples into an email! – jonathanconway – 2010-12-21T00:13:14.447

2

You can use notepad++ to export code to .rtf or .html and then use that in your document.

I have tried different Office plugins but they never worked nicely. Or I didn't find one.

Egon

Posted 2009-10-26T10:47:46.990

Reputation: 2 513

1

I'm not aware of any Office plugins that will do this, but if you have Visual Studio or Visual C++ Express Edition installed, you can copy and paste code (that will keep its formatting) from Visual Studio directly into Word.

Adam Maras

Posted 2009-10-26T10:47:46.990

Reputation: 111