文档详情

C操作Word文档超详细操作总结大全.docx

发布:2017-08-09约8.04千字共10页下载文档
文本预览下载声明
前提工作:Using Microsoft.Office.Interop.Word;Microsoft Office 11.0 Object Library;必要实例化的两个类:Microsoft.Office.Interop.Word.Application myword = new Microsoft.Office.Interop.Word.Application();//对word软件的操作Microsoft.Office.Interop.Word.Document mydoc = new Microsoft.Office.Interop.Word.Document();//对word软件中文本的操作Microsoft.Office.Interop.Word.Range myrange = myword.Application.Selection.Range;//对word软件中文本字体设置的操作Microsoft.Office.Interop.Word.InlineShape shape = myword.ActiveWindow.ActivePane.Selection.InlineShapes.AddPicture(“图片地址”, Nothing, Nothing, Nothing);//页眉插入图片Microsoft.Office.Interop.Word.PageNumbers Pns = myword.Selection.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers;//获取当前页码myword.Selection 和 myword.Application.Selection//两者使用相同,Application指向的是Word应用程序经常使用变量:Object Nothing = System.Reflection.Missing.Value;//选参数的默认参数Object unite = WdUnits.wdStory;//word场景范例:①myword.selection.EndKey(ref unite,ref NoThing);常用的方法和属性:①Word引用常用的方法:/*文档集指向Word的文档*/mydoc = myWord.Document.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);//文档集指向word文档mydoc.Activate();//激活mydoc指定对象/*Word文档操作*/Object path = “本机保存文件地址”;Object format003 = WdSaveFormat.wdFormatDocument;//指定保存的格式mydoc.SaveAs(ref path,ref format003,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,ref Nothing);//保存word文档mydoc.SaveAs2(ref path,ref formatPDF,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);//保存word文档SaveAs(..)函数和SaveAs2(..)函数的区别:SaveAs2(..)只适用在Word2010项目中。解释:该函数功能为word文件另存为到本机硬盘中,在有指定存储格式的时候不需要追加“后缀名”字符串额外知识体系:{WdSaveFormat类的格式常用属性表wdformatdocument微软Word格式。wdformatdostext微软文本格式。wdformatdostextlinebreaks微软DOS文本保存换行符。wdformatencodedtext编码文本格式。wdformatfilteredhtml过滤HTML格式。wdformathtml标准HTML格式。wdformatrtf富文本格式(RTF)。wdformattemplate微软Word模板格式。wdformattext微软视窗文本格式。wdformattextlinebreaks微软Windows文本格式保留换行符。
显示全部
相似文档