Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying code into word document and keeping formatting [closed]

Tags:

python

ms-word

I need to get my code (Python 2.7 written in the Python IDE) into a word document for my dissertation but I am struggling to find a way of copying it in and keeping the formatting, I've tried paste special and had no luck. The only way I've found so far is screenshoting but with just over 1000 lines of code this is proving very laborious.

like image 447
user2996828 Avatar asked Mar 27 '14 08:03

user2996828


People also ask

How do I copy and paste code with formatting?

Select the portion of code you'd like to copy, then go the Edit menu and select Copy Special -> Copy as RTF. Your code, complete with syntax highlighting colors, is now stored on the clipboard. Simply press Ctrl + V in your other application to paste the code with syntax highlighting. It's that simple!

How do I paste code into a Word document?

Go to Insert tab, Text section, click Object button (it's on the right) Choose OpenDocument Text which will open a new embedded word document. Copy and paste your code from Visual Studio / Eclipse inside this embedded word page. Save and close.


2 Answers

After trying every method I still had problems then came across this!, basically copy and paste your code and select what language it is (e.g. python, java, ...), and it will kick out the formatted and coloured version ready to be pasted into word :-)

Code to Word and keep formatting

like image 148
user2996828 Avatar answered Sep 22 '22 01:09

user2996828


To fix this, instead of directly copying and pasting, use Insert -> Object -> OpenDocument Text. The second option is to create a style for your code.

like image 40
user3441996 Avatar answered Sep 22 '22 01:09

user3441996