Chinaunix首页 | 论坛 | 博客
  • 博客访问: 512267
  • 博文数量: 60
  • 博客积分: 1445
  • 博客等级: 上尉
  • 技术积分: 507
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-14 19:15
文章分类

全部博文(60)

文章存档

2012年(1)

2011年(7)

2010年(52)

我的朋友

分类: C/C++

2010-07-12 14:06:29

读取文档中标签数据处理方法
1 获取文档中的标签列表.把文档对象的书签列表读到IEnumerator中.
2 通过枚举推进的方式读取每个书签.
3 关闭文档

  1. //获取标签数据  
  2.         public string GetDocumentBookmarkData(string FileName)  
  3.         {  
  4.    
  5.             Microsoft.Office.Interop.Word.Document wDoc = null;  
  6.             Microsoft.Office.Interop.Word.Application wApp = null;  
  7.             this.OpenWordDoc(FileName,ref wDoc, ref wApp);  
  8.             object oEndOfDoc = "\\endofdoc";  
  9.             object missing = System.Reflection.Missing.Value;   
  10.   
  11.             string str="";  
  12.   
  13.             System.Collections.IEnumerator enu=wApp.ActiveDocument.Bookmarks.GetEnumerator();  
  14.   
  15.             while(enu.MoveNext())  
  16.             {  
  17.                 Microsoft.Office.Interop.Word.Bookmark bk = (Microsoft.Office.Interop.Word.Bookmark)enu.Current;  
  18.   
  19.                 str += "{"+bk.Name.ToString() + ":"+bk.Range.Text+"}";  
  20.             }  
  21.   
  22.             object o = null;  
  23.   
  24.             wDoc.Close(ref missing, ref missing, ref missing);  
  25.             wApp.Quit(ref missing, ref missing, ref missing);  
  26.   
  27.             if (wDoc!=null)  
  28.             {  
  29.                 System.Runtime.InteropServices.Marshal.ReleaseComObject(wDoc);  
  30.                 wDoc = null;  
  31.             }  
  32.   
  33.             if (wApp != null)  
  34.             {  
  35.                 System.Runtime.InteropServices.Marshal.ReleaseComObject(wApp);  
  36.                 wApp = null;  
  37.             }  
  38.   
  39.             GC.Collect();  
  40.   
  41.             return str;  
  42.         }  


阅读(1656) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~