准备:初学者对找WORD控件有很大问题,要在对office 2003中添加/更改对Net的支持
然后加入using Microsoft.Office.Interop.Word;
这样就可以引用word功能了
现在是定位问题,要对某段字符进行改变
start = 37; end =40;
range=Word_doc.Range(ref start, ref end);
range.Font.Bold=16;
range.Font.Color=WdColor.wdColorLavender;
意思是将第37和40个字符之间的字符修改bold 和color
注意:换行键算一个字符,空格不算
下面全部给出源代码,大家可以在第130行修改试验
1
using System;
2
using System.Diagnostics;
3
using System.Runtime.InteropServices;
4
using System.Reflection;
5
using System.Collections;
6
using System.Threading;
7
using Microsoft.Office.Interop.Word;
8
9
namespace Microsoft.Samples.Interop.WordApp
10
2
3
4
5
6
7
8
9
10