资源描述:
《C#编写的Word操作类,有换页,添加表格,文本功能.docx》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data;usingSystem.Drawing;usingWord=Microsoft.Office.Interop.Word;usingMicrosoft.Office.Interop.Word;usingSystem.Windows.Forms;/************************************
2、**************************************************************************************************文件名:**声明:**创建者:黄聪**创建日期:2009.10.8**修改者:黄聪**最新修改日期:2009.10.8************************************************************************************************
3、************************************/namespaceTool{/**********************************************************************************************************************************类名:WordPlayer**声明:**创建者:黄聪**创建日期:2009.7.15**修改者:黄聪**最新修改日期:2009.7.15***
4、*****************************************************************************************************************************/publicclassWordPlayer{#region-属性-privatestaticMicrosoft.Office.Interop.Word._ApplicationoWord=null;privatestaticMicrosoft.Offic
5、e.Interop.Word._Documentodoc=null;privatestaticMicrosoft.Office.Interop.Word._DocumentoDoc{get{if(odoc==null){odoc=oWord.Documents.Add(refNothing,refNothing,refNothing,refNothing);}returnodoc;}set{if(value!=null){odoc=value;}}}privatestaticobjectNothing
6、=System.Reflection.Missing.Value;publicenumOrientation{横板,竖板}publicenumAlignment{左对齐,居中,右对齐}#endregion#region-添加文档-#region-创建并打开一个空的word文档进行编辑-publicstaticvoidOpenNewWordFileToEdit(){oDoc=oWord.Documents.Add(refNothing,refNothing,refNothing,refNothing);
7、}#endregion#endregion#region-创建新Word-publicstaticboolCreateWord(boolisVisible){try{oWord=newMicrosoft.Office.Interop.Word.Application();oWord.Visible=isVisible;returntrue;}catch(Exception){returnfalse;}}publicstaticboolCreateWord(){returnCreateWord(fals
8、e);}#endregion#region-打开文档-publicstaticboolOpen(stringfilePath,boolisVisible){try{oWord.Visible=isVisible;objectpath=filePath;oDoc=oWord.Documents.Open(refpath,refNothing,refNothing,refNothing,refNothing,refNothing,refNothing,ref