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.
Asked
Active
Viewed 1.1e+01k times
28
-
Unfortunately, this question is not appropriate for this forum. :( – sshashank124 Mar 27 '14 at 08:22
-
[Maybe this helps](http://stackoverflow.com/questions/387453/how-do-you-display-code-snippets-in-ms-word-preserving-format-and-syntax-highlig) – msvalkon Mar 27 '14 at 08:23
-
1Thanks, it may not be appropriate for the majority of people on here but for students who have to explain everything they've done in a report its very helpful and i wouldn't know where else to ask? – user2996828 Mar 27 '14 at 11:08
-
See the question [How to physically print python code in color from IDLE?](https://stackoverflow.com/questions/16833285/how-to-physically-print-python-code-in-color-from-idle/37898012#37898012) for a simple method using a Python extension called *IDLE2HTML* that saves directly (original colours) from IDLE to a formatted file usable by word processors. – Edward Oct 09 '17 at 20:54
2 Answers
58
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 :-)

Exelian
- 5,749
- 1
- 30
- 49

user2996828
- 1,137
- 3
- 12
- 19
-
You may not have noticed the question [How to physically print python code in color from IDLE?](https://stackoverflow.com/questions/16833285/how-to-physically-print-python-code-in-color-from-idle/37898012#37898012) which has a simple method using a Python extension called *IDLE2HTML* that saves directly (original colours) from IDLE to a formatted file usable by word processors. – Edward Oct 09 '17 at 20:57
3
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.

user3441996
- 99
- 9