Word 代码高亮
整理文档比较费事,提供个脚本放在VBA里,使Word 代码高亮的一种方法是改变颜色
'script to high light code In document Private Function isKeyword(w) As Boolean Dim keys As New Collection With keys .Add "onStart": .Add "Log": .Add "volatile": .Add "friend"
.Add "abstract": .Add "long": .Add "while": .Add "if"
.Add "Activity": .Add "native": .Add "FALSE": .Add "implements"
.Add "asm": .Add "new": .Add "import"
.Add "auto": .Add "new?": .Add "enabled": .Add "inlIne"
.Add "bool": .Add "android": .Add "instanceof"
.Add "boolean": .Add "onBind": .Add "receiver": .Add "int"
.Add "boolean?": .Add "onCreate": .Add "exported": .Add "int?"
.Add "break": .Add "onDestroy": .Add "filter": .Add "Intent"
.Add "BroadcastReceiver": .Add "onRebind": .Add "action": .Add "interface"
.Add "byte": .Add "onUnbind": .Add "category": .Add "isDebug?"
.Add "case": .Add "package": .Add "application": .Add "synchronized"
.Add "char": .Add "private": .Add "manifest": .Add "template"
.Add "class": .Add "protected": .Add "xmlns": .Add "this"
.Add "class?": .Add "protected?": .Add "version": .Add "throw?"
.Add "const": .Add "public": .Add "encoding": .Add "transient"
.Add "ContentProvider": .Add "register": .Add "utf": .Add "typename"
.Add "continue": .Add "return": .Add "INTERNET": .Add "union"
.Add "default": .Add "sendOrderBroadcast": .Add "RECEIVE_USER_PRESENT": .Add "unsigned"
.Add "do": .Add "Service": .Add "WAKE_LOCK": .Add "virtual"
.Add "double": .Add "short": .Add "READ_PHONE_STATE": .Add "void"
.Add "else": .Add "signed": .Add "WRITE_EXTERNAL_STORAGE"
.Add "enum": .Add "static": .Add "READ_EXTERNAL_STORAGE"
.Add "explicit": .Add "static?": .Add "VIBRATE": .Add "CHANGE_WIFI_STATE"
.Add "extends": .Add "strictfp": .Add "WRITE_SETTINGS": .Add "CHANGE_NETWORK_STATE"
.Add "extern": .Add "String?": .Add "ACCESS_NETWORK_STATE": .Add "@"
.Add "final": .Add "struct": .Add "ACCESS_WIFI_STATE": .Add "super"
.Add "float": .Add "for": .Add "switch": .Add "typedef": .Add "sizeof"
.Add "try": .Add "namespace": .Add "catch": .Add "operator"
.Add "cast": .Add "NULL": .Add "null": .Add "delete": .Add "throw"
.Add "dynamic": .Add "reinterpret": .Add "true": .Add "TRUE"
.Add "pub": .Add "provider": .Add "authorities": .Add "Add": .Add "get": .Add "set"
.Add "uses": .Add "permission": .Add "allowBackup"
.Add "grant": .Add "URI": .Add "meta": .Add "data": .Add "false": .Add "string": .Add "integer"
End With isKeyword = isSpecial(w, keys) End Function Private Function isSpecial(ByVal w As String, ByRef col As Collection) As Boolean For Each i In col If w = i Then isSpecial = True Exit Function End If Next isspeical = False End Function Private Function isOperator(w) As Boolean Dim ops As New Collection With ops .Add "+": .Add "-": .Add "*": .Add "/": .Add "&": .Add "^": .Add ";" .Add "%": .Add "#": .Add "!": .Add ":": .Add ",": .Add "." .Add "||": .Add "&&": .Add "|": .Add "=": .Add "++": .Add "--" .Add "'": .Add """" End With isOperator = isSpecial(w, ops) End Function ' set the style of selection Private Function isType(ByVal w As String) As Boolean Dim types As New Collection With types .Add "void": .Add "struct": .Add "union": .Add "enum": .Add "char": .Add "short": .Add "int" .Add "long": .Add "double": .Add "float": .Add "signed": .Add "unsigned": .Add "const": .Add "static" .Add "extern": .Add "auto": .Add "register": .Add "volatile": .Add "bool": .Add "class": .Add " private" .Add "protected": .Add "public": .Add "friend": .Add "inlIne": .Add "template": .Add "virtual" .Add "asm": .Add "explicit": .Add "typename" End With isType = isSpecial(w, types) End Function Sub SyntaxHighlight() Dim wordCount As Integer Dim d As Integer ' set the style of selection Selection.Style = "java code" d = wordCount = Selection.Words.Count Selection.StartOf wdWord While d < wordCount d = d + Selection.MoveRight(wdWord, , wdExtend) w = Selection.Text If isKeyword(Trim(w)) = True Then Selection.Font.Color = wdColorBlue ElseIf isType(Trim(w)) = True Then Selection.Font.Color = wdColorDarkRed ' 深绿色。lIne comment 水绿色 wdColorAutomatic wdColorBlueGray Selection.Font.Bold = True ElseIf isOperator(Trim(w)) = True Then Selection.Font.Color = wdColorBrown ' 鲜绿色。 ElseIf Trim(w) = "//" Then 'lIne comment Selection.MoveEnd wdLine, commentWords = Selection.Words.Count d = d + commentWords Selection.Font.Color = wdColorGreen ' 灰色底纹。 Selection.MoveStart wdWord, commentWords ElseIf Trim(w) = "/*" Then 'block comment While Selection.Characters.Last <> "/" Selection.MoveLeft wdCharacter, , wdExtend Selection.MoveEndUntil ("*") Selection.MoveRight wdCharacter, , wdExtend Wend commentWords = Selection.Words.Count d = d + commentWords Selection.Font.Color = wdColorGreen Selection.MoveStart wdWord, commentWords End If 'move the start of selection to next word Selection.MoveStart wdWord Wend ' prepare For set lIne number Selection.MoveLeft wdWord, wordCount, wdExtend ' SetLIneNumber End Sub
Word 代码高亮的更多相关文章
- Word中使用代码高亮插件
Word中使用代码高亮插件 1.下载并安装:SyntaxHighlighter4Word.zip 解压,然后双击bin\word2010\Kong.SyntaxHighlighter.Word2010 ...
- 如何在博客中使用SublimeText风格的代码高亮样式
因为觉得博客园自带的代码高亮样式很单一,不符合作为前端的我的审美习惯,于是下定决心要想办法折腾出一个方法来应用上另外一套代码高亮样式. 虽然探索的过程是很痛苦的,但最后还是成功了,但也不枉付出的那些努 ...
- 20141127 测试使用Word2013书写博客(代码高亮+公式支持)。
PS :又经过几次测试,发现用于Word2010的高亮插件在Word2013上排版效果不是很好,慎用.不过公式编辑倒是挺方便的 测试使用Word2013书写博客. 大概一个月前,使用WindowL ...
- 如何使用SublimeText风格的代码高亮样式 添加Zed Coding(EMMET)插件
因为觉得博客园自带的代码高亮样式很单一,不符合作为前端的我的审美习惯,于是下定决心要想办法折腾出一个方法来应用上另外一套代码高亮样式. 虽然探索的过程是很痛苦的,但最后还是成功了,但也不枉付出的那些努 ...
- 使用word2016发有代码高亮的博客
复制使用notepad++,eclipse这类有高亮的编辑器编写的代码到word中是默认有高亮的. 测试有没有代码高亮(eclipse代码): package p_day1; public class ...
- 如何在Open Live Writer(OLW)中使用precode代码高亮Syntax Highlighter
早先Microsotf的Windows Live Writer(WLW)现在已经开源了,并且更名为Open Live Writer,但是现在Windows Live Writer还是可以现在,Open ...
- highlight.js 代码高亮插件
官网:https://highlightjs.org/ API:http://highlightjs.readthedocs.org/en/latest/api.html 1. 简单使用: <l ...
- 7个高性能JavaScript代码高亮插件
本文由码农网 – 小峰原创,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 对于喜欢写技术博客的同学来说,一定对代码高亮组件非常熟悉.一款优秀的JavaScript代码高亮插件,将会帮助你渲染 ...
- 如何在 Evernote 中支持代码高亮
Evernote 本身不支持代码高亮,在 Apple App-Store 上有一个建立在 Evernote 上的 EverCode,可以支持代码高亮,需要付费.虽然只有¥5,但是这个 App 似乎只能 ...
随机推荐
- Codeforces.547C.Mike and Foam(容斥/莫比乌斯反演)
题目链接 \(Description\) 给定n个数(\(1\leq a_i\leq 5*10^5\)),每次从这n个数中选一个,如果当前集合中没有就加入集合,有就从集合中删去.每次操作后输出集合中互 ...
- sql中如何统计一字段中字符串的个数
declare @s varchar(100)set @s='156434A27kAsdABCiosd-01&**('--找出现的次数select len(@s)-len(replace(@s ...
- 详解Object.constructor
对象的constructor属性引用了该对象的构造函数.对于 Object 对象,该指针指向原始的 Object() 函数.如下: var obj = {}; obj.constructor //ƒ ...
- Linux终端(Xshell等)的编码设置
先简单说说一下遇到的情况吧: 在用类似Xshell的工具连接远端Linux时,运行命令ls时,如果有中文,就会显示有乱码: 网上查资料时,也把相应的连接属性修改为utf-8了(见下图),但是还是不行: ...
- make mrproper and make clean
make mrproper命令会删除所有的编译生成文件.内核配置文件(.config文件)和各种备份文件,所以几乎只在第一次执行内核编译前才用这条命令. make clean命令则是用于删除大多数的编 ...
- iOS上使用自己定义ttf字体
项目中想使用第三方的字体,在stackoverflow上查询解决的方法,也折腾一会,加入成功,示比例如以下: 1.将xx.ttf字体库增加project里面 2.在project的xx-Info.pl ...
- java基础学习总结——哈希编码
一.哈希编码
- Class.forName(String name)方法,到底会触发那个类加载器进行类加载行为?
4.2 在代码中直接调用Class.forName(String name)方法,到底会触发那个类加载器进行类加载行为? Class.forName(String name)默认会使用调用类的类加载器 ...
- 想要快速上手 Spring Boot?看这些教程就足够了!| 码云周刊第 81 期
原文:https://blog.gitee.com/2018/08/19/weekly-81/ 想要快速上手 Spring Boot?看这些教程就足够了!| 码云周刊第 81 期 码云周刊 | 201 ...
- Windows X64汇编入门(1)
最近断断续续接触了些64位汇编的知识,这里小结一下,一是阶段学习的回顾,二是希望对64位汇编新手有所帮助.我也是刚接触这方面知识,文中肯定有错误之处,大家多指正.文章的标题包含了本文的四方面主要内容: ...