如何在 com 自动化中启动特定的 excel 版本? [英] How can I start a specific excel version in com automation?

查看:27
本文介绍了如何在 com 自动化中启动特定的 excel 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 COM 自动化(在 c# 中)使用 Excel,但问题似乎无法控制盒子上启动的 excel 版本 - 我们同时使用 Excel 9 和 Excel 11,并且一组特定的电子表格需要 excel9 否则他们将无法工作.

I use Excel via COM automation (in c#), but it seems that the problem has no control over what version of excel is started on the box - we use both Excel 9 and Excel 11 and one specific set of spreadsheets requires excel 9 else they wont work.

我包含了 excel 9 com 引用,但在另一个人的机器上 excel 11 启动了.我怎样才能解决这个问题 ?

I included the excel 9 com references but on another persons machine excel 11 started. How can I fix this ?

推荐答案

我不确定用于 Excel 的 ProgId(CLSID Guids 上的友好名称),但快速浏览使我找到Excel.Application",因为键入您可能会激活.

I'm unsure of the ProgId's (friendly names on CLSID Guids) used for Excel, but a quick look leads me to 'Excel.Application', as the type you might activate.

看看HKEY_CLASSES_ROOT下,在我的机器上我看到Excel.Application"和Excel.Application.12",我怀疑你正在激活Excel.Application",如果你看下CurVer"键下Excel.Application"它指向Excel.Application.12",在你的复制机器上检查这个值.

Take a look under HKEY_CLASSES_ROOT, on my machine I see "Excel.Application" and "Excel.Application.12", i suspect that you are activating "Excel.Application", if you look under the "CurVer" key under "Excel.Application" it points back to "Excel.Application.12", inspect this value on your repro machines.

我的猜测是您正在启动 Excel.Application,如果您的目标计算机上存在 prog id,您可能希望强制它启动 Excel.Application.9.

My guess would be that you are starting Excel.Application, you may want to force it to start Excel.Application.9 if the prog id exists on your target machine.

这是一个小代码示例:

Type excel9Type = Type.GetTypeFromProgID("Excel.Application.9");
Type excelType = Type.GetTypeFromProgID("Excel.Application");

if (excelType == excel9Type)
{
    Console.WriteLine("Default Excel.Application is pointing to 'Verion 9' yay");
}
else
{
    Console.WriteLine("Excel is installed, but it's not 'Version 9'");
}

if (excel9Type == null)
{
    throw new InvalidOperationException("Excel.Application.9 is not a registered progid");
}

object excelApplication = Activator.CreateInstance(excel9Type);

// Cast excelApplication to whatever you are using as your application type. 

这篇关于如何在 com 自动化中启动特定的 excel 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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