views:

3919

answers:

4

If i try to paste source code in word 2007 the spacing between the lines seems to get messed up as all new lines are spaced way apart compared to a programming text editor.

Can somebody tell me how to paste source code in word 2007 preserving the formatting and the spacing between lines?

+2  A: 

The problem is that each line is a paragraph, and often in Word, paragraphs have a certain amount of Space Before. If you choose a style that has 0 space before, and 0 space after, it should look fine.

Ned Batchelder
+1  A: 

As already mentioned, it's because of the paragraph spacing. Either chose a style with no spacing, or select the text and format paragraph and set the before and after spacing to 0. This was easy with earlier versions, but is presumably complicated now we have ribbon controls. :)

Richard A
+2  A: 

Try your IDE's (or editor's) "Export to Clipboard as HTML" or "Export to clipboard as RTF" function. Then paste in Word. Guess it should work. It works on Outlook (it even preserves the syntax coloring)

Satish Motwani
A: 

If you're using VIM you can use 2html.vim which comes bundled with VIM:

source $VIM/syntax/2html.vim

This will open a new buffer with the file in HTML that you can save or copy and paste any way you wish.

Nathan Fellman