如何在com自动化中启动特定的excel版本? [英] How can I start a specific excel version in com automation?
问题描述
我通过COM自动化(在c#)使用Excel,但似乎该问题无法控制什么版本的Excel开始在框上 - 我们使用Excel 9和Excel 11和一个特定的电子表格需要excel 9他们不会工作。
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 ,如果在Excel.Application下的CurVer键下面,它指向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,你可能想强制它启动Excel.Application.9如果prog id存在于目标机器上。
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.
这里是一个小代码示例:
Here is a little code sample:
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屋!