您如何以MS Word保留格式和语法高亮显示代码片段? [英] How do you display code snippets in MS Word preserving format and syntax highlighting?

查看:96
本文介绍了您如何以MS Word保留格式和语法高亮显示代码片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在Microsoft Word文档中显示保留颜色和格式的代码的方法吗?优选地,该方法也将是不引人注目的并且易于更新.

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.

最后,我知道有很多更好的编辑器/格式都可以解决这个问题,但是我仍然坚持使用MS word.

Lastly, I know that there are much better editors/formats that have no problem handling this but I am stuck working with MS word.

推荐答案

对我来说,这是在word中添加代码的最佳方法:

Here is the best way, for me, to add code inside word:

  1. 转到Insert选项卡的Text部分,单击object按钮(在右侧)
  2. 选择OpenDocument Text,这将打开一个新的嵌入式word文档
  3. 从Visual Studio/Eclipse中复制代码并将其粘贴到此嵌入式单词页中
  4. 保存并关闭
  1. go to Insert tab, Text section, 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:

  • 代码保持其原始布局和颜色
  • 代码与文档的其余部分分开,好像是图片还是图表
  • 拼写错误不会在代码中突出显示(这很酷!)

只需要几秒钟.

这篇关于您如何以MS Word保留格式和语法高亮显示代码片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆