SetParent无法使用Excel 2013 [英] SetParent not working with Excel 2013

查看:143
本文介绍了SetParent无法使用Excel 2013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已使用Interop程序集将Excel嵌入到WPF窗口中。要嵌入到主WPF窗口中,我们使用的是SetParent()函数,它不能与Excel2013一起使用。鼠标和键盘导航在工作簿区域中不起作用以及自定义插件
不起作用,因为excel实例返回为null

We have embedded Excel into a WPF window using Interop assemblies. To embed into main WPF window we are using SetParent() function which is not working with Excel2013. Mouse and keyboard navigation are not working in the workbook area as well as custom plugin does not work as excel instance comes back as null

      ;       _application = new Microsoft.Office.Interop.Excel.Application();           

            _application = new Microsoft.Office.Interop.Excel.Application();           

            _application.Visible = true;

            _application.Visible = true;

            excelHandle = new IntPtr(_application.Hwnd);

            

            SetParent(excelHandle,this.Handle);        //将当前主持人设置为Excel Hwnd的父级          
 



            int lngStyle = GetWindowLong(excelHandle,GWL_STYLE);

            lngStyle = lngStyle ^ WS_CAPTION;

            lngStyle = lngStyle ^ WS_SIZEBOX;



            SetWindowLong(excelHandle,GWL_STYLE,lngStyle); //应用新风格

            SetWindowPos(excelHandle,new IntPtr(0),0,0,this.Width,this.Height,SWP_FRAMECHANGED);

            excelHandle = new IntPtr(_application.Hwnd);
            
            SetParent(excelHandle, this.Handle);       // set the current Host as the Parent of the Excel Hwnd            

            int lngStyle = GetWindowLong(excelHandle, GWL_STYLE);
            lngStyle = lngStyle ^ WS_CAPTION;
            lngStyle = lngStyle ^ WS_SIZEBOX;

            SetWindowLong(excelHandle, GWL_STYLE, lngStyle); // apply the new style
            SetWindowPos(excelHandle, new IntPtr(0), 0, 0, this.Width, this.Height, SWP_FRAMECHANGED);

以前用过使用Office 2010可以正常工作。如果我们删除SetParent,那么所有的东西都能正常工作,但它不会嵌入到WPF窗口中。

It used to work all fine with Office 2010. If we remove SetParent then all the things work correctly but it does not get embedded into WPF window.

谢谢,

Shirish

推荐答案

Hi Shirish Wagh,

Hi Shirish Wagh,

感谢您在这里发帖。

为您的与WPF问题更相关的案例,我建议将其移至WPF论坛以获得更好的支持。

For your case which is more related to WPF problems, I suggest to move it to WPF forum for better support.

您的理解与合作将不胜感激。

Your understanding and cooperation will be grateful.

最诚挚的问候,

Sera Yu


这篇关于SetParent无法使用Excel 2013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆