C# OFFICE操作

来源:互联网 发布:ubuntu网卡驱动下载 编辑:程序博客网 时间:2024/05/17 06:11

///在工程中添加Word 12.0对象库的引用  

 /// 更改某表的某个单元格的内容        
/// </summary>        
/// <param >table id</param>          
/// <param >行id</param>        
/// <param >列id</param>        
/// <param >更新字符串</param>        
public void UpdateTableContent(int tableID, int lineID, int columnID, string context)         {              Word.Table tbl = WordApp.ActiveWindow.ActivePane.Selection.Tables[tableID];             tbl.Cell(lineID, columnID).Range.Text = context;             this.Save();         }
/// <summary>         /// 将书签更新成字符串         /// </summary>         /// <param >书签名</param>         /// <param >更新字符串</param>        
public void UpdateBookmark(string bookmarkName, string newText)         {              object name=null;             Word.Range rng = WordApp.ActiveDocument.Bookmarks.get_Item(ref  name).Range;             rng.Text = newText;             object range = rng;             WordApp.ActiveDocument.Bookmarks.Add(bookmarkName, ref range);             this.Save();         }
/// 从模版创建word文件         /// </summary>         /// <param >word模版路径</param>         /// <param >word文件路径</param>        
public void CreateFileFromDot(string strdotpath,string strdocpath)         {            object filepath = strdotpath;            object owordfile = strdocpath;            if (File.Exists(strdocpath))//删除已存在的文件            {                File.Delete(strdocpath);             }            WordApp.Documents.Add(ref filepath, ref missing, ref missing, ref missing);            WordApp.ActiveDocument.SaveAs(ref owordfile,                ref missing, ref missing, ref missing, ref missing, ref missing,                ref missing, ref missing, ref missing, ref missing, ref missing,                ref missing, ref missing, ref missing, ref missing, ref missing);               this.Open(strdocpath);             strwordfilepath = Path.GetDirectoryName(strdotpath);             strwordfilename = Path.GetFileName(strdocpath);         }

原创粉丝点击