Does anyone know a way to display code in Microsoft Word documents that preserves coloring and formatting? Preferably, the method would also be unobtrusive and easy to update. I have tried to include code as regular text which looks awful and gets in the way when editing regular text. I have also tried inserting objects, a WordPad document and Text Box, into the document then putting the code inside those objects. The code looks much better and is easier to avoid while editing the rest of the text. However, these objects can only span one page which makes editing a nightmare when several pages of code need to be added. Lastly, I know that there are much better editors/formats that have no problem handling this but I am stuck working with MS word. Here is the best way, for me, to add code inside word: • go to 'insert' tab, click 'object' button (it's on the right) • choose 'OpenDocument Text' which will open a new embedded word document • copy and paste your code from Visual Studio / Eclipse inside this embedded word page • 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. Download and install and do the following: • Paste your code in the window; • Select the programming language from the language menu; • Select the text to copy; • Right click and select Plugin commands -> Copy Text with Syntax Highlighting; • Paste it into MS Word and you are good to go! Update: Notepad++ has a plugin called 'NppExport' (comes pre-installed) that allows you to copy to RTF, HTML and ALL. See the section entitled “Distribute Visual Studio Templates and Policy Wizards in a Deployment Project” in the MSDN Documentation for more information. For information on how to deploy files in your infrastructure, visit the Microsoft TechNet website at ❑ Project Portal: You can add the.zip file. Binding between data source and template document is provided. And opened in Microsoft Word. See Mail Merge in Word. Download free sample Word add-in in C# (source code). Solid framework for deep customization of Microsoft Office. Use solution templates. The Problem You have to write a Word Document, which should contain snippets of code. The code should be displayed using syntax highlighting following established rules for your programming language of choice. Furthermore, at a later point in time, you would like to publish parts of your word. It permits dozens of languages, whereas the aforementioned IDEs are limited to a handful each (without other plug-ins). I use Copy all formats to clipboard and 'paste as HTML' in MS word. This worked beautifully. I already had Notepad++ for other code projects, but never thought of using it. Combined with a Word style that added a faint blue background, border, and disabled spell check, it looks pretty good, and is fairly fast for a number of files, as opposed to methods involving file exports and imports. Although I wish there was a way to add it as a field that would automatically check the original.java files for updates, and keep the latest source code in the Word file. – Feb 4 '11 at 18:31 84. After reading a lot of related answers, I came across my own solution, which for me is the most suitable one. Result looks like this: As you can see, it is the same syntax highlighting like on Stack Overflow which is quite awesome. Steps to reproduce: on Stack Overflow • Goto (preferably with Chrome) • Paste Code and add a language tag (e.g. Java) to get syntax hightlighting • Copy code from preview in Word • Insert > Table > 1x1 • Paste code • Table Design > Borders > No Border • Select code > Edit > Find > Replace Search Document ^p (Paragraph Mark) Replace With ^l (Manual Line Break) (This is required to remove the gaps between some lines) • Select code again > Review > Language > check 'Do not check spelling or grammar' • Finally add a caption using References > Insert Caption > New Label > name it 'Listing' or sth Sample code thanks to. When I've done this, I've made extensive use of styles. It helps a lot. What I do is create a paragraph style (perhaps called ' Code Example' or something like that) which uses a monospaced font, carefully chosen tabs, a very light grey background, a thin black border above and below (that helps visibility a lot) and with spelling turned off. I also make sure that inter-line and inter-paragraph spacing are set right. I then create additional character styles on top (e.g., ' Comment', ' String', ' Keyword', ' Function Name Decl', ' Variable Name Decl') which I layer on top; those set the color and whether the text is bold/italic. It's then pretty simple to go through and mark up a pasted example as being code and have it come out looking really good, and this is works well for short snippets. Long chunks of code probably should not normally be in something that's going to go on a dead tree.:-) An advantage of doing it this way is that it is easy to adapt to whatever code you're doing; you don't have to rely on some IDE to figure out whatever is going on for you. (The main problem? Printed pages typically aren't as wide as editor windows so wrapping will suck.). In case you're like me and are too lazy or in a hurry and don't want to download additional software, you could use. It's very straight forward and supports several highlight themes and many programming languages. In my case I was using, which doesn't allow copying with format due to CSS involved in styling (as reported ). Copy the text from the Preview box and then in Word go to Insert -> Textbox, paste the Preview from the website, highlight all the text, and then. This is what the code looks like finally. In my experience copy-paste from eclipse and Notepad++ works directly with word. For some reason I had a problem with a file that didn't preserve coloring. I made a new.java file, copy-paste code to that, then copy-paste to word and it worked. As the other guys said, create a new paragraph style. What I do is use mono-spaced font like courier new, small size close to 8px for fonts, single spaced with no space between paragraphs, make tab stops small (0.5cm,1cm.,5cm), put a simple line border around the text and disable grammar checks. That way i achieved the line braking of eclipse so I don't have to do anything more. Hope I helped;). The link you provided gives a 404 error, so it's not possible to see what the answer was - although I believe I recognize the question. I usually like to provide background information and my information source to back up a statement, but to boil it down to something more understandable: The feature was removed from Office 2007. It's not there any more. You can't do what you did in Word 2003. A Word document does not natively have HTML Code. You can save a Word document to 'web page' format, open that in a text editor (or in Word if you activate the option that will let you select the encoding) and view the HTML the converter generated. But in its native environment, a Word document is either in its binary file format or in the new OpenXML file format. It's never in HTML format. The tool that was integrated in earlier versions of Word (the VB Script editor) to show you HTML has been removed from Office 2007, so it's no longer possible to view any HTML. Cindy Meister, VSTO/Word MVP Cindy Meister, VSTO/Word MVP.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2018
Categories |