描述
我正在將Excel文件加載到WinForm webbrowser控件對象中。加載後,我可能需要打開其他Excel文件。但是,當瀏覽器控件加載時,它會阻止在使用雙擊時加載另一個工作簿。但是,如果我開始 - >運行Excel應用程序,然後選擇文件 - >打開文檔,它會加載,我可以在網頁瀏覽器中的工作簿和剛纔打開的工作簿之間進行切換。我使用.NET參考Microsoft.Office.Internet.Excel 14.0.0.0。Webbrowser控件中的Excel控件從其他文件鎖定Excel
是否有反正在加載瀏覽器控件時雙擊打開文件?
代碼WebBrowser控件中加載Excel文件
protected Microsoft.Office.Interop.Excel.Application _excelApp = null;
protected Workbook _workbook = null;
protected Worksheet _worksheet = null;
//Load the Excel file in the WebBrowser control
this.webBrowser.Navigate("MyFile.xls", false);
//Get the ActiveXinstance from the WebBrowser Container
SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)this.webBrowser.ActiveXInstance;
//Make the web browser silent so dialog boxes are not displayed
wb.Silent = true;
//Assign the document to an object
object odocument = wb.Document;
//Convert the Document to an Excel application
_excelApp = (Microsoft.Office.Interop.Excel.Application)odocument.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, odocument, null);
//Do not display alerts
_excelApp.DisplayAlerts = false;
//Assign a workbook to the Excel application. Use .Count in case there are other workbooks open in the Excel application
_workbook = (Workbook)_excelApp.Workbooks[_excelApp.Workbooks.Count];
//Assign a worksheet to the workbook (Excel objects are 1-based)
_worksheet = (Worksheet)_workbook.Worksheets[1];
我試圖啓動另一個Excel進程WebBrowser控件的加載,但有同樣的問題後:
System.Diagnostics.Process.Start(@"C:\Program Files\Microsoft Office\OFFICE11\Excel.exe");
我也嘗試過創建另一個Excel對象,但.NET參考似乎將兩者合併爲一個過程: oXL=new Microsoft.Office.Interop.Excel.Application
我注意到了這個問題,VS2008被瀏覽了很多,但沒有得到解決:https://stackoverflow.com/questions/2867744/webbrowser-locks-first-excel-instance