转自:http://www.cnblogs.com/ok519/archive/2009/09/21/1570903.html
最近开发 Winform 应用程序,涉及到 嵌入Excel 文件。技术验证也快结束,需要整理一下帮助文档了。。
用webBrowser控件 打开Excel 。
/// <summary> /// /// </summary> public static Microsoft.Office.Interop.Excel.Range range = null; /// <summary> /// /// </summary> public static Microsoft.Office.Interop.Excel.Workbook wbb = null;
/// <summary> /// 打开Excel文件 /// </summary> /// <param name="filePath">Excel文件路径</param> public void OpenExcel(string filePath) { strFilePathAndFileName = filePath;
//Object refmissing = System.Reflection.Missing.Value;
this.webBrowser1.Navigate(strFilePathAndFileName);
//object axWebBrowser = this.webBrowser1.ActiveXInstance; }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { Object refmissing = System.Reflection.Missing.Value;
object[] args = new object[4];
args[0] = SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS;
args[1] = SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER;
args[2] = refmissing;
args[3] = refmissing;
object axWebBrowser = this.webBrowser1.ActiveXInstance;
axWebBrowser.GetType().InvokeMember("ExecWB", BindingFlags.InvokeMethod, null, axWebBrowser, args);
object oApplication = axWebBrowser.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, axWebBrowser, null);
wbb = (Microsoft.Office.Interop.Excel.Workbook)oApplication;
}
|
请发表评论