5

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?

6 Answers 6

4

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)

2

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.

1

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. :)

1

As noted above, when cutting and pasting code directly into Word 2007, each line of code is treated as a paragraph. The problem with using paragraph properties to set the space before and space after to 0 is that you will have to add a spurious empty paragraph before or after the code so that there is a gap between the code and the preceding or following paragraph. An alternative solution that does not exhibit this problem is to make Word 2007 treat a chunk of code as a single paragraph by replacing each paragraph break with a manual line break (shift + enter). This way, the space before and space properties after apply to the whole chunk of code and can be left consistent with normal body text.

0

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.

0

(For MS Word) I use Lucida console, colour black,
10 points high (to get about 80 chars on before wrapping)
line spacing set to 0 before and 12 after (using 0 after also looks ok)
Set the border to "box" to get a rectangle around your paragraph. Unfortunately you will not get colorized text, unless pasting from html or rtf.
Here is my style spec: Font: (Default) Lucida Console, 10 pt, Font color: Text 1, Line spacing: At least 12 pt, Space After: 12 pt, Style: Linked, Quick Style, Based on: console

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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