Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 5 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.

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

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.

share|improve this answer

if you have Notepad ++, you dont have to insert an opendocument.text - You can paste the syntax highlighted text directly in the word document.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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