在64位环境中使用32位COM对象

Dor*_*ron 3 .net excel powershell 64-bit ms-office

我在Win7/64bit上使用PowerShell 3.我试图用这个命令使用Excel(32位)的.NET:[microsoft.office.interop.excel.xlfileformat]我得到这个错误:无法找到类型microsoft.office.interop.excel.xlfileformat:确保加载包含此类型的程序集.我使用Win7/32bit之前没有出现此错误.也许有人知道如何解决这个问题?

Kei*_*ill 7

您需要加载Excel互操作程序集,如下所示:

Add-Type -AssemblyName Microsoft.Office.Interop.Excel
Run Code Online (Sandbox Code Playgroud)

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