Copying code into word document and keeping formatting

Question:

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 By: user2996828

||

Answers:

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.

Answered By: user3441996

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

Answered By: user2996828
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.