在 64 位环境中使用 32 位 COM 对象 [英] Using a 32bit COM object in a 64bit environment

查看:41
本文介绍了在 64 位环境中使用 32 位 COM 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Win7/64bit 上使用 powershell 3.我正在尝试通过以下命令使用 .net of excel(32 位):[microsoft.office.interop.excel.xlfileformat]我收到了这个错误:无法找到类型 microsoft.office.interop.excel.xlfileformat:确保加载了包含此类型的程序集.我之前用Win7/32bit的时候没有这个错误.也许有人知道如何解决这个问题?

I'm using powershell 3 on Win7/64bit . I am trying to use .net of excel (32bit) with this command : [microsoft.office.interop.excel.xlfileformat] And I got this error: unable to find type microsoft.office.interop.excel.xlfileformat: make sure that the assembly containing this type is loaded. I didn't have this error before when I used Win7/32bit. Maybe someone know how to fix that?

推荐答案

您需要像这样加载 Excel 互操作程序集:

You need to load the Excel interop assembly like so:

Add-Type -AssemblyName Microsoft.Office.Interop.Excel

如果您需要使用 Excel 互操作程序集中定义的类型,则必须先将该程序集加载到 PowerShell 中,然后才能引用其中定义的类型.您使用的是枚举 (xlFileFormat),因此 PowerShell 需要该类型的定义.

If you need to use types defined in the Excel interop assembly, you have to load that assembly into PowerShell before you can reference types defined in it. You're using an enumeration (xlFileFormat) so PowerShell needs the definition of that type.

这篇关于在 64 位环境中使用 32 位 COM 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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