WebBrowser 打开excel的问题
奋青110 2008-12-08 08:29:41 我用WebBrowser加载Excel时出错 "未知名称。 (异常来自 HRESULT:0x80020006 (DISP_E_UNKNOWNNAME))”
出错代码 axWebBrowser1_NavigateComplete2事件中的
Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);
有谁遇到过这样的问题
或那位有能运行的程序给借鉴一下
本人邮箱yefengsheng105@163.com
万分感谢!正面是全部代码
public Form1()
{
InitializeComponent();
this.axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
}
private void Form1_Load(object sender, System.EventArgs e)
{
button1.Text = "Browse";
openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt";
openFileDialog1.FilterIndex = 1;
}
public void Form1_Closed(object sender, System.EventArgs e)
{
oDocument = null;
}
public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
try
{
Object o = e.pDisp;
Object 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);
Microsoft.Office.Interop.Excel.Application eApp = (Microsoft.Office.Interop.Excel.Application)oApplication;//
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
String strFileName;
//Find the Office document.
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
//If the user does not cancel, open the document.
if (strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
}
}