楼主幸运了,我前一段时间也做过这个功能。也花了我不少时间才搞定。下面是代码
这段代码可写在按钮单击事件里面。我用的是axWebBrowser控件,工具箱如果一般初始没有这个控件,你右键工具箱-->选择项-->com组件里面选择Microsoft Web Browser
String strFileName;
//Find the Office document.
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
//If the user does not cancel, open the document.
//Document doc = new Document();
//doc.SaveAs();
if (strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
}
//还要加一个该控件的事件
private Object oDocument;
private void axWebBrowser1_NavigateComplete2(object sender, DWebBrowserEvents2_NavigateComplete2Event e)
{
Object o = e.pDisp;
oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);
Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);
Object oName = o.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, oApplication, null);
}