pdeva
pdeva

Reputation: 45541

Pasting source code in word 2007

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?

Upvotes: 5

Views: 11308

Answers (6)

James Bostock
James Bostock

Reputation: 156

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.

Upvotes: 1

user337598
user337598

Reputation:

(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

Upvotes: 0

Nathan Fellman
Nathan Fellman

Reputation: 127588

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.

Upvotes: 0

RuntimeException
RuntimeException

Reputation: 1643

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)

Upvotes: 4

Richard A
Richard A

Reputation: 2833

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

Upvotes: 1

Ned Batchelder
Ned Batchelder

Reputation: 375912

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.

Upvotes: 2

Related Questions