如何在Word中排版出漂亮的编程语⾔代码样式?(较好⽤的
部分⽅法汇总)
[1] 能输出各种编程语⾔并保持代码格式和语法⾼亮显⽰的⽹站:
[2] How do you display code snippets in MS Word preserving format and syntax highlighting?
本⼈使⽤VS 2013作为C语⾔的编程环境,直接将代码从VS中“保留源格式”复制到Word中,因此在原作者写的宏的基础上加了两条宏
命令拿来使⽤的,即:
Options.DefaultHighlightColorIndex = wdNoHighlight  'NeXT_Vision新增的:清除“以不同颜⾊突出显⽰⽂本”,从⽽解决从VS中“保留源格式”复制带来的⽂本⾼亮问题Selection.Range.HighlightColorIndex = wdNoHighlight  'NeXT_Vision新增的:清除“以不同颜⾊突出显⽰⽂本”,从⽽解决从VS中“保留源格式”复制带来的⽂本⾼亮问题
Sub Word中代码排版之设置代码表格()
' author: code4101 链接blog.csdn/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)
.
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  链接blog.csdn/code4101/article/details/41802715
' Word中代码排版之设置代码表格宏
'第⼆个宏是在表格第⼀列⾃动加上⾏号
'
⾏数 = InputBox("请输⼊代码终⽌⾏数", "输⼊⾏数", "50")
For i = 1 To ⾏数 - 1
Selection.TypeText Text:=i
Selection.TypeParagraph
Next
Selection.TypeText Text:=⾏数
End Sub
[4] Word⾥如何排版出漂亮的编程语⾔代码样式_百度经验
[6]

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。