C# 嵌入Excel、winform 嵌入Ecxel 、.net 嵌入 Excel、winform 打开 Excel、webBrowser打开Excel...

 

最近开发 Winform 应用程序,涉及到 嵌入Excel 文件。技术验证也快结束,需要整理一下帮助文档了。。

C# 嵌入Excel、winform 嵌入Ecxel 、.net 嵌入 Excel、winform 打开 Excel、webBrowser打开Excel..._第1张图片

用webBrowser控件 打开Excel 。

        ///


       ///
       ///

       public static Microsoft.Office.Interop.Excel.Range range = null;
       ///
       ///
       ///

       public static Microsoft.Office.Interop.Excel.Workbook wbb = null;

         ///


        /// 打开Excel文件
        ///

        /// Excel文件路径
        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;

}

转载于:https://www.cnblogs.com/ok519/archive/2009/09/21/1570903.html

你可能感兴趣的:(C# 嵌入Excel、winform 嵌入Ecxel 、.net 嵌入 Excel、winform 打开 Excel、webBrowser打开Excel...)