Pasting source code in word 2007
Asked Answered
C

6

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?

Cutting answered 11/11, 2008 at 4:19 Comment(0)
E
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.

Evite answered 11/11, 2008 at 4:33 Comment(0)
B
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)

Beckerman answered 11/11, 2008 at 6:48 Comment(0)
E
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.

Evite answered 11/11, 2008 at 4:33 Comment(0)
B
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. :)

Bab answered 11/11, 2008 at 5:8 Comment(0)
B
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.

Badger answered 16/6, 2011 at 8:49 Comment(0)
S
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.

Squarrose answered 15/1, 2009 at 8:59 Comment(0)
B
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

Breastbone answered 13/8, 2012 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.