问题描述
本人想使用webbrowser控件显示和编辑excel文件,新建form1窗体,添加webbrowser控件,窗体加载时打开excel文件,一切正常,但是这时从本地磁盘打开excel文件时,excel打不开了,请问有什么方法没有
解决方案
解决方案二:
报什么错误,截个图呗,你想我们建议你重装office么
解决方案三:
没有提示文件正在使用中????你的webbrowser加载的是excel文件还是excel文件的内容?
解决方案四:
首先感谢2位的回复,我是想在窗体中嵌入控件,然后打开excel,能进行编辑,写入操作。代码如下:很简单,就是在窗体中只要打开excel,再在本地打开其他excel文件就冲突了,第二个excel文件打不开publicpartialclassForm1:Form{privateObjectoDocument;publicAxSHDocVw.AxWebBrowseraxWebBrowser1=newAxWebBrowser();publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){StringstrFileName;//FindtheOfficedocument.openFileDialog1.FileName="";openFileDialog1.ShowDialog();strFileName=openFileDialog1.FileName;//Iftheuserdoesnotcancel,openthedocument.if(strFileName.Length!=0){Objectrefmissing=System.Reflection.Missing.Value;oDocument=null;//axWebBrowser1.Navigate(strFileName,refrefmissing,refrefmissing,refrefmissing,refrefmissing);this.webBrowser1.Navigate(strFileName);}}publicvoidForm1_Load(objectsender,System.EventArgse){button1.Text="Browse";openFileDialog1.Filter="OfficeDocuments(*.doc,*.xls,*.ppt)|*.doc;*.xls;*.ppt";openFileDialog1.FilterIndex=1;}publicvoidForm1_Closed(objectsender,System.EventArgse){oDocument=null;}publicvoidaxWebBrowser1_NavigateComplete2(objectsender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Evente){//Note:Youcanusethereferencetothedocumentobjectto//automatethedocumentserver.Objecto=e.pDisp;oDocument=o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);ObjectoApplication=o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);ObjectoName=o.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,oApplication,null);MessageBox.Show("Fileopenedby:"+oName.ToString());}}
解决方案五:
引用3楼baleibalei的回复:
首先感谢2位的回复,我是想在窗体中嵌入控件,然后打开excel,能进行编辑,写入操作。代码如下:很简单,就是在窗体中只要打开excel,再在本地打开其他excel文件就冲突了,第二个excel文件打不开publicpartialclassForm1:Form{privateObjectoDocument;publicAxSHDocVw.AxWebBrowseraxWebBrowser1=newAxWebBrowser();publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){StringstrFileName;//FindtheOfficedocument.openFileDialog1.FileName="";openFileDialog1.ShowDialog();strFileName=openFileDialog1.FileName;//Iftheuserdoesnotcancel,openthedocument.if(strFileName.Length!=0){Objectrefmissing=System.Reflection.Missing.Value;oDocument=null;//axWebBrowser1.Navigate(strFileName,refrefmissing,refrefmissing,refrefmissing,refrefmissing);this.webBrowser1.Navigate(strFileName);}}publicvoidForm1_Load(objectsender,System.EventArgse){button1.Text="Browse";openFileDialog1.Filter="OfficeDocuments(*.doc,*.xls,*.ppt)|*.doc;*.xls;*.ppt";openFileDialog1.FilterIndex=1;}publicvoidForm1_Closed(objectsender,System.EventArgse){oDocument=null;}publicvoidaxWebBrowser1_NavigateComplete2(objectsender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Evente){//Note:Youcanusethereferencetothedocumentobjectto//automatethedocumentserver.Objecto=e.pDisp;oDocument=o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);ObjectoApplication=o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);ObjectoName=o.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,oApplication,null);MessageBox.Show("Fileopenedby:"+oName.ToString());}}
这个控件是自定义的?
解决方案六:
解决方案七:
引用4楼Benjay77的回复:
Quote: 引用3楼baleibalei的回复:
首先感谢2位的回复,我是想在窗体中嵌入控件,然后打开excel,能进行编辑,写入操作。代码如下:很简单,就是在窗体中只要打开excel,再在本地打开其他excel文件就冲突了,第二个excel文件打不开publicpartialclassForm1:Form{privateObjectoDocument;publicAxSHDocVw.AxWebBrowseraxWebBrowser1=newAxWebBrowser();publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){StringstrFileName;//FindtheOfficedocument.openFileDialog1.FileName="";openFileDialog1.ShowDialog();strFileName=openFileDialog1.FileName;//Iftheuserdoesnotcancel,openthedocument.if(strFileName.Length!=0){Objectrefmissing=System.Reflection.Missing.Value;oDocument=null;//axWebBrowser1.Navigate(strFileName,refrefmissing,refrefmissing,refrefmissing,refrefmissing);this.webBrowser1.Navigate(strFileName);}}publicvoidForm1_Load(objectsender,System.EventArgse){button1.Text="Browse";openFileDialog1.Filter="OfficeDocuments(*.doc,*.xls,*.ppt)|*.doc;*.xls;*.ppt";openFileDialog1.FilterIndex=1;}publicvoidForm1_Closed(objectsender,System.EventArgse){oDocument=null;}publicvoidaxWebBrowser1_NavigateComplete2(objectsender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Evente){//Note:Youcanusethereferencetothedocumentobjectto//automatethedocumentserver.Objecto=e.pDisp;oDocument=o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);ObjectoApplication=o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);ObjectoName=o.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,oApplication,null);MessageBox.Show("Fileopenedby:"+oName.ToString());}}这个控件是自定义的?
webbrowser控件,工具箱里的
解决方案八:
引用6楼baleibalei的回复:
Quote: 引用4楼Benjay77的回复:
Quote: 引用3楼baleibalei的回复:
首先感谢2位的回复,我是想在窗体中嵌入控件,然后打开excel,能进行编辑,写入操作。代码如下:很简单,就是在窗体中只要打开excel,再在本地打开其他excel文件就冲突了,第二个excel文件打不开publicpartialclassForm1:Form{privateObjectoDocument;publicAxSHDocVw.AxWebBrowseraxWebBrowser1=newAxWebBrowser();publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){StringstrFileName;//FindtheOfficedocument.openFileDialog1.FileName="";openFileDialog1.ShowDialog();strFileName=openFileDialog1.FileName;//Iftheuserdoesnotcancel,openthedocument.if(strFileName.Length!=0){Objectrefmissing=System.Reflection.Missing.Value;oDocument=null;//axWebBrowser1.Navigate(strFileName,refrefmissing,refrefmissing,refrefmissing,refrefmissing);this.webBrowser1.Navigate(strFileName);}}publicvoidForm1_Load(objectsender,System.EventArgse){button1.Text="Browse";openFileDialog1.Filter="OfficeDocuments(*.doc,*.xls,*.ppt)|*.doc;*.xls;*.ppt";openFileDialog1.FilterIndex=1;}publicvoidForm1_Closed(objectsender,System.EventArgse){oDocument=null;}publicvoidaxWebBrowser1_NavigateComplete2(objectsender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Evente){//Note:Youcanusethereferencetothedocumentobjectto//automatethedocumentserver.Objecto=e.pDisp;oDocument=o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);ObjectoApplication=o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);ObjectoName=o.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,oApplication,null);MessageBox.Show("Fileopenedby:"+oName.ToString());}}这个控件是自定义的?
webbrowser控件,工具箱里的
我想问打不开excel有什么提示么?
解决方案九:
引用7楼Benjay77的回复:
Quote: 引用6楼baleibalei的回复:
Quote: 引用4楼Benjay77的回复:
Quote: 引用3楼baleibalei的回复:
首先感谢2位的回复,我是想在窗体中嵌入控件,然后打开excel,能进行编辑,写入操作。代码如下:很简单,就是在窗体中只要打开excel,再在本地打开其他excel文件就冲突了,第二个excel文件打不开publicpartialclassForm1:Form{privateObjectoDocument;publicAxSHDocVw.AxWebBrowseraxWebBrowser1=newAxWebBrowser();publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){StringstrFileName;//FindtheOfficedocument.openFileDialog1.FileName="";openFileDialog1.ShowDialog();strFileName=openFileDialog1.FileName;//Iftheuserdoesnotcancel,openthedocument.if(strFileName.Length!=0){Objectrefmissing=System.Reflection.Missing.Value;oDocument=null;//axWebBrowser1.Navigate(strFileName,refrefmissing,refrefmissing,refrefmissing,refrefmissing);this.webBrowser1.Navigate(strFileName);}}publicvoidForm1_Load(objectsender,System.EventArgse){button1.Text="Browse";openFileDialog1.Filter="OfficeDocuments(*.doc,*.xls,*.ppt)|*.doc;*.xls;*.ppt";openFileDialog1.FilterIndex=1;}publicvoidForm1_Closed(objectsender,System.EventArgse){oDocument=null;}publicvoidaxWebBrowser1_NavigateComplete2(objectsender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Evente){//Note:Youcanusethereferencetothedocumentobjectto//automatethedocumentserver.Objecto=e.pDisp;oDocument=o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);ObjectoApplication=o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);ObjectoName=o.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,oApplication,null);MessageBox.Show("Fileopenedby:"+oName.ToString());}}这个控件是自定义的?
webbrowser控件,工具箱里的
我想问打不开excel有什么提示么?
没有提示,试一下不就知道了。