读取文档中标签数据处理方法
1 获取文档中的标签列表.把文档对象的书签列表读到IEnumerator中.
2 通过枚举推进的方式读取每个书签.
3 关闭文档
-
- public string GetDocumentBookmarkData(string FileName)
- {
-
- Microsoft.Office.Interop.Word.Document wDoc = null;
- Microsoft.Office.Interop.Word.Application wApp = null;
- this.OpenWordDoc(FileName,ref wDoc, ref wApp);
- object oEndOfDoc = "\\endofdoc";
- object missing = System.Reflection.Missing.Value;
-
- string str="";
-
- System.Collections.IEnumerator enu=wApp.ActiveDocument.Bookmarks.GetEnumerator();
-
- while(enu.MoveNext())
- {
- Microsoft.Office.Interop.Word.Bookmark bk = (Microsoft.Office.Interop.Word.Bookmark)enu.Current;
-
- str += "{"+bk.Name.ToString() + ":"+bk.Range.Text+"}";
- }
-
- object o = null;
-
- wDoc.Close(ref missing, ref missing, ref missing);
- wApp.Quit(ref missing, ref missing, ref missing);
-
- if (wDoc!=null)
- {
- System.Runtime.InteropServices.Marshal.ReleaseComObject(wDoc);
- wDoc = null;
- }
-
- if (wApp != null)
- {
- System.Runtime.InteropServices.Marshal.ReleaseComObject(wApp);
- wApp = null;
- }
-
- GC.Collect();
-
- return str;
- }
阅读(1686) | 评论(0) | 转发(0) |