I want to show code snippets with the original formatted styles in Microsoft Word document, is there anyway to do this?

The code is:

<iframe type="text/html" width="100%" src="" frameborder="0"></iframe> 

2 Answers

From StackOverflow:

  1. go to "insert" tab, click "object" button (it's on the right)
  2. choose "openDocument Text" which will open a new embedded word document
  3. copy and paste your code from Visual Studio / Eclipse inside this embedded word page
  4. save and close

The result looks very nice. Here are the advantages of this method:

  • the code keeps its original layout and colors
  • the code is separated from the rest of the document, as if it was a picture or a chart
  • spelling errors won't be highlighted in the code (this is cool!)

And it takes only few seconds.

Note of mine (after checking this solution), just to clear: After inserting the object Word will open a new instance, which is the code snippet. Just paste the code, save and close. If you will want to edit the code just double-click the snippet and Word will open the document.

You may also consider the other solutions which were presented by other users for this question.

This solution is good for any kind of snippet.

you can do it by pressing on Prnt Scr which will take print screen of your code.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy