如何检查是否安装了Excel的.NET互操作能力 [英] How to check if .net interoperability for excel is installed

查看:106
本文介绍了如何检查是否安装了Excel的.NET互操作能力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的.NET主互操作性大会的Excel在我的code。 但是,应用程序可以在机器不具有安装达网络PIA为Excel运行。 我想给一个错误信息,如果没有安装

I am using .net Primary Interoperability Assembly for Excel in my code. But, the application can be run on machine which doesn't have .net PIA for Excel installed. I want to give an error message if it is not installed

尽管我检查在GAC,看是否PIA安装且仅当它是我使用的Microsoft.Office.Interop.Excel相关code present。我正在一个错误。

Even though I am checking in GAC, to see if PIA is installed and only if it is present I am using Microsoft.Office.Interop.Excel related code. I am getting an error.

我的问题是 - 我得到的错误是 - 未处理的异常 - 找不到无法加载文件或程序的Microsoft.Office.Interop.Excel

My problem is - I am getting error which is - Unhandled Exception - can't find could not load file or assembly Microsoft.Office.Interop.Excel

任何解决方案?

在此先感谢!

推荐答案

我用这个积木加载中的hunspell 5月份NHunspell包装在x86 / x64的版本。也许这是一个很好的起点,为您自己的动态加载程序:

I've used this Building block to load the x86 / x64 versions of hunspell in may NHunspell wrapper. maybe it is a good starting point for your own dynamic loader:

            // Initialze the dynamic marshall Infrastructure to call the 32Bit (x86) or the 64Bit (x64) Dll respectively 
            SYSTEM_INFO info = new SYSTEM_INFO();
            GetSystemInfo( ref info );

            // Load the correct DLL according to the processor architecture
            switch( info.wProcessorArchitecture )
            {
                case PROCESSOR_ARCHITECTURE.Intel:
                    string pathx86 = AppDomain.CurrentDomain.BaseDirectory;
                    if (!pathx86.EndsWith("\\"))
                        pathx86 += "\\";
                    pathx86 +=  Resources.HunspellX86DllName;

                    dllHandle = LoadLibrary(pathx86);
                    if (dllHandle == IntPtr.Zero)
                        throw new DllNotFoundException(string.Format(Resources.HunspellX86DllNotFoundMessage, pathx86));
                    break;

                case PROCESSOR_ARCHITECTURE.Amd64:
                    string pathx64 = AppDomain.CurrentDomain.BaseDirectory;
                    if (!pathx64.EndsWith("\\"))
                        pathx64 += "\\";
                    pathx64 += Resources.HunspellX64DllName;

                    dllHandle = LoadLibrary(pathx64);
                    if (dllHandle == IntPtr.Zero)
                        throw new DllNotFoundException(string.Format(Resources.HunspellX64DllNotFoundMessage, pathx64));
                    break;

看看这个委托声明:

look at this delegate declarations:

internal delegate bool HunspellSpellDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word);

和如何将库函数绑定到它

And how to bind a library function to it

HunspellSpell = (HunspellSpellDelegate)GetDelegate("HunspellSpell", typeof(HunspellSpellDelegate));

我想这应该为你工作太多,但你必须声明完整的互操作code。您可以检查出Nhunspell code来获得这种技术的工作示例:

I think this should work for you too, but you have to declare the complete interop code. You can check out the Nhunspell code to get a working sample of this technique:

NHunspell网站

这篇关于如何检查是否安装了Excel的.NET互操作能力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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