【转】给word中的代码着色
基本操作
1)用Notepad++直接编辑代码文件,注意文件后缀,比如.cpp是C++程序,.m是Matlab,linux文件是.sh,写对后缀表示的文件类型,才有对应的语法高亮效果。
2)选中需要的代码块(或者不选,默认对全文操作),使用“插件 -> NppExport”,具体见下图


3)直接粘贴到Word就行了。
更加智能与自动化
office套件提供了VBA,让用户可以写程序、宏来辅助完成办公操作。VBA使用最广泛的当属Excel了。Alt + F11可以进入VBA,然后点击“插入”-“模块”:

然后把下面的代码复制到“模块1”并保存。
Sub 设置代码表格()
' author: code4101
' 设置代码表格 宏
'
'
' 背景色为morning的配色方案,RGB为(229,229,229)
With Selection.Tables()
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor =
End With
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
.AutoFitBehavior (wdAutoFitContent) '自动调整大小
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With ' 段落无首行缩进,行间距为固定值12磅
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints()
.RightIndent = CentimetersToPoints()
.SpaceBefore =
.SpaceBeforeAuto = False
.SpaceAfter =
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing =
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints()
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent =
.CharacterUnitRightIndent =
.CharacterUnitFirstLineIndent =
.LineUnitBefore =
.LineUnitAfter =
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.AutoAdjustRightIndent = True
.DisableLineHeightGrid = False
.FarEastLineBreakControl = True
.WordWrap = True
.HangingPunctuation = True
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True
.AddSpaceBetweenFarEastAndDigit = True
.BaseLineAlignment = wdBaselineAlignAuto
End With
' 清除原有的段落底纹
Selection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorAutomatic
End Sub Sub 输入连续数字()
' author: code4101
行数 = InputBox("请输入代码终止行数", "输入行数", "")
For i = To 行数 -
Selection.TypeText Text:=i
Selection.TypeParagraph
Next
Selection.TypeText Text:=行数
End Sub
参考:https://blog.csdn.net/code4101/article/details/41802715
【转】给word中的代码着色的更多相关文章
- Word中的代码怎样语法高亮
在平常我们粘贴代码到Word中的时候,经常会遇到代码粘贴到Word中后没有语法高亮,看着很乱很不友好,Word自带的样式---语法使用着也不尽人意, 网上有很多做法可以使得在插入在Word中的代码能够 ...
- 怎样在Word中插入代码并保持代码原始样式不变
怎样在Word中插入代码并保持样式不变 我们有时候需要在word中添加一段我们写的代码,但是把代码粘贴到word文档中之后就发现所有的代码的样子都变了,我们可以采用下边的方法来实现保持代码原来的样式和 ...
- Word中使用代码高亮插件
Word中使用代码高亮插件 1.下载并安装:SyntaxHighlighter4Word.zip 解压,然后双击bin\word2010\Kong.SyntaxHighlighter.Word2010 ...
- (转)如何优雅的在 Microsoft word中插入代码
背景:最近项目需要自己编写文档,在文档中需要插入部分代码,记录下这个方法. 一.工具 方法1.打开这个网页PlanetB; 方法2.或者谷歌搜索syntax highlight code in wor ...
- 计算机_软件技巧_01_优雅地再word中插入代码
二.参考资料 1.如何优雅的在 Microsoft word中插入代码
- 如何在 Microsoft word中插入代码
一.工具 方法1.打开这个网页PlanetB; 方法2.或者谷歌搜索syntax highlight code in word documents,检索结果的第一个.如下图: PS. 方法1和2打开的 ...
- 如何在word中插入代码
本文使用的是word2007,在网上查阅资料,可以使用如下方法: 1. 插入一个1行1列的表格,然后将代码写在里面,完成之后选中表格: 2. 将样式改为"HTML代码". 其实只是 ...
- 在word中使用notepad++实现代码的语法高亮
转载自:http://blog.csdn.net/woohello/article/details/7621651 有时写文档时需要将代码粘贴到word中,但直接粘贴到word中的代码虽能保持换行与缩 ...
- 在word中使用notepad++实现代码的语法高亮 分类: C_OHTERS 2013-09-22 10:38 2273人阅读 评论(0) 收藏
转载自:http://blog.csdn.net/woohello/article/details/7621651 有时写文档时需要将代码粘贴到word中,但直接粘贴到word中的代码虽能保持换行与缩 ...
随机推荐
- win10系统中如何解决cmd中的路径和现在电脑的用户名不一致
假设原用户名老王,已删除,但是cmd后路径还是C:\Users\老王>,这与现在用户laowng不一致了需改为C:\Users\laowang>. .先新建一个管理员账户laowang,然 ...
- sqli-labs第一节 get-字符型注入
https://blog.csdn.net/sherlock17/article/details/64454449 1.SQL注入漏洞的几种判断方法 ①http://www.heetian.com ...
- chmod、acl权限
R:4W:2X:1 chmod g+r file 给所有者的组内用户加上读的权限chmod o+r file 给其他组用户加上读的权限chmod a+x file 给所有用户加上写执行的权限chmod ...
- JSONCkecker(C语言版本)
/* JSON_checker.h */ typedef struct JSON_checker_struct { int valid; int state; int depth; int top; ...
- Linux配置本地yum源
最近在配置zabbix时,遇到CentOS 无法连接网络问题,搜索到一种配置本地yum源的方法,特此记录 一.联网安装预处理 配置缓存,修改/etc/yum.conf [main] cachedir= ...
- content-box和border-box
理解box-sizing属性border-box,content-box,其实也是理解正常盒模型与异常盒模型. 如果不做特殊说明,我们日常所用的div都是正常盒子模型. 正常盒子模型 正常盒子模型,是 ...
- Springboot监控之一:SpringBoot四大神器之Actuator
介绍 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供 ...
- 在JS中调用CS里的方法(PageMethods)
在JS中调用CS里的方法(PageMethods) 2014年04月28日 11:18:18 被动 阅读数:2998 最近一直在看别人写好的一个项目的源代码,感觉好多东西都是之前没有接触过的.今天 ...
- day25 Python __setattr__
#__getattr__只有在使用点调用属性且属性不存在的时候才会触发 class Foo: x=1 def __init__(self,y): self.y=y def __getattr__(se ...
- pip 安装指定版本软件包
默认情况下,pip 将安装最新版本的软件包,但有时需要获取特定版本的安装包,比如 jinja2 从 2.9 开始加入了 async 关键字,这个会导致 py2exe 报错:Invalid Syntax ...