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

StackOverflow https://stackoverflow.com/questions/20120016

  •  03-08-2022
  •  | 
  •  

Frage

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?

War es hilfreich?

Lösung

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. :)

Andere Tipps

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

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.

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 :(

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top