Word 中修改字体、字体大小、字体颜色的源代码

 string fileName = @"文件路径";
            Object Nothing = System.Reflection.Missing.Value;

//生成操作对象
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
            Microsoft.Office.Interop.Word.Document document;

Object FileName = fileName;

//打开文件
            document = wordApp.Documents.Open(ref FileName, ref Nothing, ref f, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                    ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);

int parNum = document.Paragraphs.Count;

 for (n = 1; n <= parNum; n++)
                {
                    document.Paragraphs[n].Range.Font.Size = 12.0f;//可以设置其他大小的字体
                    document.Paragraphs[n].Range.Font.Name = "宋体";//可以设置其他字体

                    document1.Paragraphs[n].Range.Font.Color = WdColor.wdColorBlue;//字体设置为蓝色

                    document1.Paragraphs[n].Range.Font.Color = WdColor.wdColorRed;//字体设置为红色

                }

 //关闭document文档对象
document.Close(ref Nothing, ref Nothing, ref Nothing);
 //关闭wordApp组件对象
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);

阅读更多
文章标签: object string 文档
个人分类: C# Word 处理技术
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭