Looking for a way to format my code in MS Word I found this question on Stack Overflow and combined the two high rated answers to create an openDocument with the code keeping its formatting:

  1. Go to "insert" tab, click "object" button (it's on the right)
  2. Choose "openDocument Text": it will open a new embedded word document
  3. Open code in Notepad++
  4. Select the programming language from the language menu
  5. In Notepad++ right click and select Plugin commands -> Copy Text with Syntax Highlighting
  6. Paste in to embedded word document
  7. save and close

This works good but I would like line numbers on the code, is there a way to do that?

link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

When the code is in Notepad++, you can use TextFX->TextFX Tools->Insert line numbers to put line numbers in front of all of the necessary lines. Then when you copy/paste, the line numbers will be there.

link|improve this answer
Thanks, worked nicely after running a replace of 000000 to remove the leading 0 form line numbers – Blem Jan 16 at 13:59
feedback

To avoid having to remove unnecessary leading zeros, you can use the column editor (Edit -> Column Editor or Alt+C) after you've done a column select at the first column. You'll get a window like this:

Column Editor Window

I like to use leading zeros, but you can just as well leave them out. Trailing spaces will be added instead. You will have to indent your code one extra time (or use a leading space), as this method won't automatically add one for you.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.