方法一:借助转换网站(强烈推荐)
网站截图
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724135546.png)
高亮代码效果图:
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724134959.png)
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724135119.png)
方法二:用word自带样式 (所用模板文件下载)
------搭配方法一使用效果极佳,因为方法一 有时候不能显示背景色,两者组合可以更好的显示代码的高亮
建议文件存在 C:\Users\xxx\AppData\Roaming\Microsoft\Templates下面
xxx 表示电脑账户名,此文件夹是存放word的公共样式模板的地方
step1 step2
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724135956.png)
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724140055.png)
step3 点击 导入/导出
step4
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724140434.png)
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724140709.png)
step5 复制样式到现有word文件,然后 哪里需要代码格式在哪里点击即可
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724141515.png)
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724141450.png)
方法三:借助转换网站
适用代码 ‘C C++ C# CSS Delphi, Pascal XML Java Javascript PHP Python Ruby SQL VB HTML’
- http://www.planetb.ca/syntax-highlight-word
- http://www.luofenming.com/tools/code2word/index.html
- http://www.codeinword.com/(有个缺点,代码首行会自动缩进)
打印为pdf后效果图
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724133142.png)
方法四:借助word本身表格功能。
优点:简单、快速;
缺点:格式单调,没有高亮方式,且字体字号会容易受文档现有格式影响。
打印为pdf后效果图:
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724132012.png)
方法五:借助软件notepad++
参考:知乎问答 Chilton Nieh的回答
效果如图:
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724134346.png)
![](https://gitee.com/PolarisF/Picgo_image/raw/master/20200724134440.png)