在网上搜寻了一些代码,向指定书签中写入内容可以,但是把它读取出来就不行了,能够找到书签的名字(bk.Name),但是书签制定的能容找不到,总是显示null( bk.Range.Text为null),试了好久还是不行啊!
解决方案 »
- Devexpress LayoutControl Item 设置visibility 替代的item的问题
- 请问,如何取消ListBox的点击弹出列表
- C# 如何调用DataGridViewCellValidatingEventArgs事件,并传入参数
- 字符串和数组的转换问题
- 数据入库的问题,麻烦各位大大了!不胜感谢!
- 简单的正则表达式
- 如何通過一個公用的函數實現Delegate TextClickEvent =new System.EventHandler(this.button3_Click)
- 请教一个关于 Winform 本地化的问题。谢谢
- 如何关闭窗体?
- 接上一个帖子
- 子窗口无法显示控件问题
- 怎样用代码请求一个URL,并获取请求成功返回的XML,读取XML里面的信息???
public string GetDocumentBookData(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.Books.GetEnumerator(); while(enu.MoveNext())
{
Microsoft.Office.Interop.Word.Book bk = (Microsoft.Office.Interop.Word.Book)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;
}
这段代码有没有试过,我以前用过,可以的
oWord.Documents.Open(ref fileName, ref confirmConversions, ref readOnly, ref addToRecentFiles, ref passwordDocument, ref passwordTemplate, ref revert, ref writePasswordDocument, ref writePasswordTemplate, ref format, ref encoding, ref visible, ref openConflictDocument, ref openAndRepair, ref documentDirection, ref noEncodingDialog)
我采用上面的方法,在xp系统中能读取word模版,但是在windows 2003中,返回的却是空对象,不知道什么原因,请指教。
这是个函数 网上很多!
这是个现成的函数 去网上搜搜!
{
object b="a";
Word.Book bk=Doc.Books.Item(ref b); word.range wordrng = doc.books.get_item(ref j).range;
string s=bk.Range.Text ;
}
读取和写入书签内容