WdColor 枚举 (Word)

 

 

指定要应用的 24 位颜色。
名称
值
说明
wdColorAqua
13421619
水绿色。
wdColorAutomatic
-16777216
自动配色。默认值;通常为黑色。
wdColorBlack
0
黑色。
wdColorBlue
16711680
蓝色。
wdColorBlueGray
10053222
蓝灰色。
wdColorBrightGreen
65280
鲜绿色。
wdColorBrown
13209
褐色。
wdColorDarkBlue
8388608
深蓝色。
wdColorDarkGreen
13056
深绿色。
wdColorDarkRed
128
深红色。
wdColorDarkTeal
6697728
深青色。
wdColorDarkYellow
32896
深黄色。
wdColorGold
52479
金色。
wdColorGray05
15987699
5% 灰色底纹。
wdColorGray10
15132390
10% 灰色底纹。
wdColorGray125
14737632
12.5% 灰色底纹。
wdColorGray15
14277081
15% 灰色底纹。
wdColorGray20
13421772
20% 灰色底纹。
wdColorGray25
12632256
25% 灰色底纹。
wdColorGray30
11776947
30% 灰色底纹。
wdColorGray35
10921638
35% 灰色底纹。
wdColorGray375
10526880
37.5% 灰色底纹。
wdColorGray40
10066329
40% 灰色底纹。
wdColorGray45
9211020
45% 灰色底纹。
wdColorGray50
8421504
50% 灰色底纹。
wdColorGray55
7566195
55% 灰色底纹。
wdColorGray60
6710886
60% 灰色底纹。
wdColorGray625
6316128
62.5% 灰色底纹。
wdColorGray65
5855577
65% 灰色底纹。
wdColorGray70
5000268
70% 灰色底纹。
wdColorGray75
4210752
75% 灰色底纹。
wdColorGray80
3355443
80% 灰色底纹。
wdColorGray85
2500134
85% 灰色底纹。
wdColorGray875
2105376
87.5% 灰色底纹。
wdColorGray90
1644825
90% 灰色底纹。
wdColorGray95
789516
95% 灰色底纹。
wdColorGreen
32768
绿色。
wdColorIndigo
10040115
靛蓝色。
wdColorLavender
16751052
淡紫色。
wdColorLightBlue
16737843
浅蓝色。
wdColorLightGreen
13434828
浅绿色。
wdColorLightOrange
39423
浅橙色。
wdColorLightTurquoise
16777164
浅青绿色。
wdColorLightYellow
10092543
浅黄色。
wdColorLime
52377
酸橙色。
wdColorOliveGreen
13107
橄榄色。
wdColorOrange
26367
橙色。
wdColorPaleBlue
16764057
淡蓝色。
wdColorPink
16711935
粉红色。
wdColorPlum
6697881
梅红色。
wdColorRed
255
红色。
wdColorRose
13408767
玫瑰色。
wdColorSeaGreen
6723891
海绿色。
wdColorSkyBlue
16763904
天蓝色。
wdColorTan
10079487
棕黄色。
wdColorTeal
8421376
青色。
wdColorTurquoise
16776960
青绿色。
wdColorViolet
8388736
紫色。
wdColorWhite
16777215
白色。
wdColorYellow
65535
黄色。

 

转载于:https://www.cnblogs.com/endv/p/7499308.html

首先,我们需要使用 Microsoft.Office.Interop.Word 库来操作 Word 文档。以下是实现的步骤: 1. 创建一个空白的 Word 文档作为模板 ```c# using Word = Microsoft.Office.Interop.Word; // 创建一个 Word Application 实例 Word.Application wordApp = new Word.Application(); wordApp.Visible = true; // 创建一个空白的 Word 文档 Word.Document templateDoc = wordApp.Documents.Add(); ``` 2. 插入两个不同的 Word 文件到模板中 ```c# // 插入第一个 Word 文件 Word.Selection sel = wordApp.Selection; sel.InsertFile("path/to/file1.docx"); // 在模板中插入分隔符 sel.TypeText(Environment.NewLine + "====分隔符====" + Environment.NewLine); // 插入第二个 Word 文件 sel.InsertFile("path/to/file2.docx"); ``` 3. 在模板中标记出内容不同的地方 ```c# // 获取模板中所有段落 Word.Paragraphs paragraphs = templateDoc.Paragraphs; // 遍历所有段落,查找内容不同的地方 foreach (Word.Paragraph para in paragraphs) { // 获取段落的文本 string text = para.Range.Text; // 判断是否包含分隔符 if (text.Contains("====分隔符====")) { // 分割文本,获取左右两边的内容 string[] parts = text.Split(new string[] { "====分隔符====" }, StringSplitOptions.None); string leftText = parts[0].Trim(); string rightText = parts[1].Trim(); // 比较左右两边的内容,标记不同之处 if (leftText != rightText) { // 标记左边的内容为红色 para.Range.Words[1].Font.Color = Word.WdColor.wdColorRed; para.Range.Words[1].Font.Bold = 1; // 标记右边的内容为蓝色 int index = text.IndexOf("====分隔符====") + "====分隔符====".Length; para.Range.Words[index].Font.Color = Word.WdColor.wdColorBlue; para.Range.Words[index].Font.Bold = 1; } } } ``` 4. 将标记后的模板保存为新的 Word 文件 ```c# // 保存标记后的模板为新的 Word 文件 string outputPath = "path/to/output.docx"; templateDoc.SaveAs2(outputPath); // 关闭 Word Application 和模板文档 templateDoc.Close(); wordApp.Quit(); ``` 完整代码如下: ```c# using Word = Microsoft.Office.Interop.Word; public static void CompareWordFiles(string file1Path, string file2Path, string templatePath, string outputPath) { // 创建一个 Word Application 实例 Word.Application wordApp = new Word.Application(); wordApp.Visible = true; // 打开第一个 Word 文件 Word.Document file1Doc = wordApp.Documents.Open(file1Path); // 打开第二个 Word 文件 Word.Document file2Doc = wordApp.Documents.Open(file2Path); // 创建一个空白的 Word 文档作为模板 Word.Document templateDoc = wordApp.Documents.Add(); // 将第一个 Word 文件插入到模板中 Word.Selection sel = wordApp.Selection; sel.InsertFile(file1Path); // 在模板中插入分隔符 sel.TypeText(Environment.NewLine + "====分隔符====" + Environment.NewLine); // 将第二个 Word 文件插入到模板中 sel.InsertFile(file2Path); // 获取模板中所有段落 Word.Paragraphs paragraphs = templateDoc.Paragraphs; // 遍历所有段落,查找内容不同的地方 foreach (Word.Paragraph para in paragraphs) { // 获取段落的文本 string text = para.Range.Text; // 判断是否包含分隔符 if (text.Contains("====分隔符====")) { // 分割文本,获取左右两边的内容 string[] parts = text.Split(new string[] { "====分隔符====" }, StringSplitOptions.None); string leftText = parts[0].Trim(); string rightText = parts[1].Trim(); // 比较左右两边的内容,标记不同之处 if (leftText != rightText) { // 标记左边的内容为红色 para.Range.Words[1].Font.Color = Word.WdColor.wdColorRed; para.Range.Words[1].Font.Bold = 1; // 标记右边的内容为蓝色 int index = text.IndexOf("====分隔符====") + "====分隔符====".Length; para.Range.Words[index].Font.Color = Word.WdColor.wdColorBlue; para.Range.Words[index].Font.Bold = 1; } } } // 保存标记后的模板为新的 Word 文件 templateDoc.SaveAs2(outputPath); // 关闭所有文档和 Word Application file1Doc.Close(); file2Doc.Close(); templateDoc.Close(); wordApp.Quit(); } ``` 注意:需要在项目中引用 Microsoft.Office.Interop.Word 库。可以通过 NuGet 安装这个库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值