且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2021-08-24 02:43:29

您需要像这样加载 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.