How to show code snippets in MS Word document as it shows in StackOverflow (scrollbars and gray background)
Asked Answered
H

4

11

I am writing a document which intends to show code changes made in C# project, I am looking for a good format to show code snippet.

I like is the way StackOverflow site shows code snippet in its Questions and Answers (scrollbars and background color).

Can anybody guide me to create similar background/view to show code snippet in word document (mainly scrollbars).

I tried copying and pasting it from StackOverflow but the background does not appear.

I search and found this useful link but it does not change background color and don't have scroll bars How do you display code snippets in MS Word preserving format and syntax highlighting?

Heathcote answered 21/11, 2013 at 11:41 Comment(1)
R
15

Here is what I did, first the results:

enter image description here

Go to stackoverflow copy some code, paste it in the word doc, you will get this gray box and etc.

Mark you text and go to:

enter image description here

enter image description here

enter image description here

Then you just write your code in any IDE, and past it into the word doc, mark it and set the style to code. :)

Rahel answered 2/8, 2014 at 8:1 Comment(4)
Could you please explain how you were able to configure the options, such as enabling a background? You just showed the final screen, and I am confused about the process that you took to do this.Satsuma
@Satsuma what is not clear from the process? i wrote everything you need to do in order to get it... the final screen is the first image. all of the other are the process it self...Rahel
Sorry, I was not clear, what I meant is that the actual steps you take when creating a new style, you do not show how you actually set the background color inside of the style editor. I had to find it on my version of Word, so I was wondering if you could make it easier for anyone else using this question.Satsuma
@Satsuma as i said, it is all written, when you copy and past the code sample from stackoverflow into work you are getting the same background color as stackoverflow have..Rahel
C
6

I could not comment on most voted answer for @AeroVTP, my rep is too low. But when you create a style, you can modify it by right clicking and then Modify..

Img 1

Then on bottom left, click on Format -> Border. Then on tab Shading you can select whatever color you want as a background. Hope this clears things up :)

Img 2

Commissioner answered 19/11, 2015 at 19:7 Comment(0)
T
2

In Microsoft Word setup a text box (Insert > textbox) select the "format" tab, go to "fill" and choose the background color, set up a grey background, then use a monospaced font and here is your code-like text!

Here is a link to a Microsoft support page that can drive you better if you need: http://office.microsoft.com/en-gb/word-help/make-the-background-of-a-text-box-invisible-HA010337242.aspx?CTT=1

Fro scrollbars is a little more complicated, but here is someone who found a solution: http://answers.microsoft.com/en-us/office/forum/office_2007-word/i-need-a-textbox-with-a-scroll-bar-in-my-word-form/534ced3f-f202-46b1-a4b4-3ecdabaa6899

From there you can find a lot of usefull guides for text formatting and general MS Word use.

Tarshatarshish answered 21/11, 2013 at 11:55 Comment(1)
this seems not fisible for lot of code snippet in the page, I am looking for something handful..Heathcote
J
0

Just insert a 1x1 table, style it as you want and paste the code from notepad++ (NppExport->Copy all formats to clipboard). Easiest solution.

Even though, it would be best if we write to Bill that he has to put some code styler for us developers in need to document our code via Microsoft word :(

Julius answered 24/9, 2014 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.