如何在Word中排版出漂亮的编程语言代码样式?(较好用的部分方法汇总)

您所在的位置:网站首页 代码放在word里 如何在Word中排版出漂亮的编程语言代码样式?(较好用的部分方法汇总)

如何在Word中排版出漂亮的编程语言代码样式?(较好用的部分方法汇总)

2024-07-16 01:37:26| 来源: 网络整理| 查看: 265

 

[1] 能输出各种编程语言并保持代码格式和语法高亮显示的网站:

PlanetB | Syntax Highlight Code in Word Documents  http://www.planetb.ca/syntax-highlight-word

Welcome! — Pygments  http://pygments.org/

[2] How do you display code snippets in MS Word preserving format and syntax highlighting?

https://stackoverflow.com/questions/387453/how-do-you-display-code-snippets-in-ms-word-preserving-format-and-syntax-highlig#

[3] 如何在Word中排出漂亮的代码 - CSDN博客  http://blog.csdn.net/code4101/article/details/41802715

本人使用VS 2013作为C语言的编程环境,直接将代码从VS中“保留源格式”复制到Word中,因此在原作者写的宏的基础上加了两条宏命令拿来使用的,即:

Options.DefaultHighlightColorIndex = wdNoHighlight 'NeXT_Vision新增的:清除“以不同颜色突出显示文本”,从而解决从VS中“保留源格式”复制带来的文本高亮问题 Selection.Range.HighlightColorIndex = wdNoHighlight 'NeXT_Vision新增的:清除“以不同颜色突出显示文本”,从而解决从VS中“保留源格式”复制带来的文本高亮问题 Sub Word中代码排版之设置代码表格() ' author: code4101 链接http://blog.csdn.net/code4101/article/details/41802715 ' Word中代码排版之设置代码表格 宏 '第一个宏需要选定一个一行两列的表格 ' ' 背景色为morning的配色方案,RGB为(229,229,229) With Selection.Tables(1) With .Shading .Texture = wdTextureNone .ForegroundPatternColor = wdColorAutomatic .BackgroundPatternColor = 15066597 '15066597这个数其实就是229*(2^16 + 2^8 + 1) End With Options.DefaultHighlightColorIndex = wdNoHighlight 'NeXT_Vision新增的:清除“以不同颜色突出显示文本”,从而解决从VS中“保留源格式”复制带来的文本高亮问题 Selection.Range.HighlightColorIndex = wdNoHighlight 'NeXT_Vision新增的:清除“以不同颜色突出显示文本”,从而解决从VS中“保留源格式”复制带来的文本高亮问题 .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(0) .RightIndent = CentimetersToPoints(0) .SpaceBefore = 0 .SpaceBeforeAuto = False .SpaceAfter = 0 .SpaceAfterAuto = False .LineSpacingRule = wdLineSpaceExactly '行距为“固定值” .LineSpacing = 12 '行距为“固定值”的“12磅” .KeepWithNext = False .KeepTogether = False .PageBreakBefore = False .NoLineNumber = False .Hyphenation = True '用连字符号连接 .FirstLineIndent = CentimetersToPoints(0) .OutlineLevel = wdOutlineLevelBodyText .CharacterUnitLeftIndent = 0 .CharacterUnitRightIndent = 0 .CharacterUnitFirstLineIndent = 0 .LineUnitBefore = 0 .LineUnitAfter = 0 .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 Word中代码排版之输入连续数字() ' author: code4101 链接http://blog.csdn.net/code4101/article/details/41802715 ' Word中代码排版之设置代码表格 宏 '第二个宏是在表格第一列自动加上行号 ' 行数 = InputBox("请输入代码终止行数", "输入行数", "50") For i = 1 To 行数 - 1 Selection.TypeText Text:=i Selection.TypeParagraph Next Selection.TypeText Text:=行数 End Sub

 

Office VBA 参考Office VBA Reference | MSDN  https://msdn.microsoft.com/vba/office-vba-reference

[4] Word里如何排版出漂亮的编程语言代码样式_百度经验  

https://jingyan.baidu.com/article/9c69d48f99eb1b13c8024e7d.html

[5] word2013种如何插入代码着色的代码块? - 知乎  https://www.zhihu.com/question/31544667

[6] 



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭